Open a port in the firewall on CentOS or RHEL

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.

 

 

  • serverplus.pro, port, firewall, centos7, rhel, Open a port in the firewall on CentOS or RHEL
  • 1 Users Found This Useful
Was this answer helpful?

Related Articles

 How to Install DirectAdmin on CentOs 6 or 7

In this article, we are going to install DirectAdmin on a CentOS server.   Step 1: the...

 How to install xfce on linux

Since 1996, XFCE Desktop gives users the ability to have a graphical user interface (GUI)...

 Install Htop 2.0 – Linux Process Monitoring

This article is the continuation of our Linux system monitoring series, today we’re talking about...

 Reset Forgotten User Password in Ubuntu 14.04

If you have forgotten or lost your root password and unable to login to your Ubuntu 14.04...

 Change SSH Port in Linux

SSH or Secure Shell daemon is a network protocol that is used to perform remotely secured log ins...