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.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How to Open and Manage Linux Firewall Ports on CentOS 6/7

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 --permanent

then restart and reload.

Temporarily stop the firewall: systemctl stop firewalld.service Disable firewall permanently:

systemctl disable firewalld.service

Modifying iptables on CentOS 6

Edit /etc/sysconfig/iptables with a text editor (e.g., vi).

Restart iptables service:

/etc/init.d/iptables restart

Important 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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Linuxnetwork securityiptablesCentOSfirewalldport management
Liangxu Linux
Written by

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.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.