Operations 4 min read

How to Open and Manage Linux Ports with firewalld and iptables

This guide walks you through enabling firewall services, adding permanent ports, and reloading rules on CentOS 7 using firewalld, as well as editing iptables files and restarting the firewall on CentOS 6, complete with command examples and common pitfalls.

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

Using firewalld on CentOS 7

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

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

Add a specific port permanently (example: MySQL port 3306):

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

The command returns success when the rule is applied.

firewalld add port success
firewalld add port success

Reload firewalld to apply changes immediately: firewall-cmd --reload A success message confirms the reload.

Other useful commands: <code># List opened ports firewall-cmd --list-ports # Remove a port (example: 8080) firewall-cmd --zone=public --remove-port=8080/tcp --permanent systemctl restart firewalld.service firewall-cmd --reload # Check which process uses a port (example: 5672) netstat -lnpt | grep 5672 # On CentOS 7, install net-tools first: # yum install -y net-tools # Temporarily stop firewalld systemctl stop firewalld.service # Permanently disable firewalld (stop first, then disable) systemctl disable firewalld.service</code>

Using iptables on CentOS 6

Edit the iptables configuration file to add or modify rules:

# vi /etc/sysconfig/iptables
iptables configuration file
iptables configuration file

Restart the iptables service to apply the new rules:

/etc/init.d/iptables restart
iptables restart
iptables restart

Important notes

Even after a port is opened in the firewall, remote telnet may still fail if no process is listening on that port. For example, opening port 3306 without a running MySQL instance will not allow connections; start the service first, then the port becomes reachable.

telnet test explanation
telnet test explanation
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.