In this article, I will show you how to open port a port in the firewall . Let’s get started.
- Open a Port on CentOS/RHEL 7
Starting with CentOS/RHEL 7, however, a new userland interface called firewalld has been introduced to replace iptables service. firewall rule settings are managed by firewalld
service daemon. A command-line client called firewall-cmd
can talk to this daemon to update firewall rules permanently.
To open up a new port (e.g., TCP/80) permanently, use these commands:
sudo firewall-cmd --zone=public --add-port=80/tcp --permanent
sudo firewall-cmd --reload
Attention: Without "--permanent" flag, the firewall rule would not persist across reboots.
- Open a Port on CentOS/RHEL 6
On CentOS/RHEL 6 or earlier, the iptables
service is responsible for maintaining firewall rules.
Use iptables
command to open up a new TCP/UDP port in the firewall (e.g., TCP/80). To save the updated rule permanently, you need the second command.
sudo iptables -I INPUT -p tcp -m tcp --dport 80 -j ACCEPT
sudo service iptables save
That’s how to Open a port in the firewall on CentOS or RHEL. Thanks for reading this article.