How to Open and Manage Linux Firewall Ports on CentOS 6/7
This guide explains step‑by‑step how to check firewall status, enable firewalld, open specific ports, reload or restart the firewall, and modify iptables on CentOS 6 and 7, including useful commands and common pitfalls.
Using firewalld on CentOS 7
Check firewall status: firewall-cmd --state If not running, start it: systemctl start firewalld.service Add a permanent port rule (example MySQL 3306): firewall-cmd --zone=public --add-port=3306/tcp --permanent Restart firewalld to apply changes: systemctl restart firewalld.service Reload the configuration: firewall-cmd --reload List opened ports: firewall-cmd --list-ports Remove a port (e.g., 8080):
firewall-cmd --zone=public --remove-port=8080/tcp --permanentthen restart and reload.
Temporarily stop the firewall: systemctl stop firewalld.service Disable firewall permanently:
systemctl disable firewalld.serviceModifying iptables on CentOS 6
Edit /etc/sysconfig/iptables with a text editor (e.g., vi).
Restart iptables service:
/etc/init.d/iptables restartImportant notes
Opening a port only permits traffic; a service must be listening on that port for remote connections to succeed. Verify listening processes with netstat -lnpt | grep <em>PORT</em>. On CentOS 7, install net-tools if netstat is unavailable: yum install -y net-tools.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
