Operations 4 min read

How to Open and Manage Linux Ports with firewalld and iptables

This guide walks through enabling the firewall, opening specific ports, and reloading rules on CentOS 7 using firewalld and on CentOS 6 using iptables, providing exact commands, optional parameters, and troubleshooting tips for successful network configuration.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How to Open and Manage Linux Ports with firewalld and iptables

Using firewalld on CentOS 7

Check the firewall status: firewall-cmd --state If the output is "not running", start the service first.

Start the firewalld service: systemctl start firewalld.service Verify that the service is now active.

Add a permanent port rule (example opens MySQL port 3306):

firewall-cmd --zone=public --add-port=3306/tcp --permanent

The command returns "success" when the rule is applied. The --zone=public flag limits the rule to the public zone, and --permanent makes it survive reboots.

Restart the firewall to apply changes immediately: systemctl restart firewalld.service No output indicates success.

Reload the firewall configuration (alternative to restart): firewall-cmd --reload A "success" message confirms the reload.

Additional useful commands:

List opened ports: firewall-cmd --list-ports Close a specific port (e.g., 8080):

firewall-cmd --zone=public --remove-port=8080/tcp --permanent
systemctl restart firewalld.service
firewall-cmd --reload

Temporarily stop the firewall: systemctl stop firewalld.service Permanently disable the firewall (must stop it first):

systemctl disable firewalld.service

Using iptables on CentOS 6

Edit the iptables configuration file: # vi /etc/sysconfig/iptables Add or modify rules as needed, then save the file.

Restart iptables to apply the new rules:

/etc/init.d/iptables restart

Important notes

Even after a port appears open in the firewall, remote telnet may still fail if no process is listening on that port. For example, opening port 3306 does not make MySQL reachable until the MySQL service is started and bound to the port.

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.

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