Enable Firewalld

To enable firewalld, run the following command as root:

systemctl enable firewalld

Start Firewalld

To start firewalld, run the following command as root:

systemctl start firewalld

Check the Status of Firewalld

To check the status of firewalld, run the following command as root:

systemctl status firewalld

Open a Port on CentOS/RHEL 7

Starting with CentOS and RHEL 7, 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

Without “–permanent” flag, the firewall rule would not persist across reboots.

Check the updated rules with:

$ firewall-cmd –list-all

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

Another way to open up a port on CentOS/RHEL 6 is to use a terminal-user interface (TUI) firewall client, named system-config-firewall-tui.

$ sudo system-config-firewall-tui

Choose “Customize” button in the middle and press ENTER.

If you are trying to update the firewall for any well-known service (e.g., web server), you can easily enable the firewall for the service here, and close the tool. If you are trying to open up any arbitrary TCP/UDP port, choose “Forward” button and go to a next window.

https://farm4.staticflickr.com/3941/15604533696_12857827ea_z.jpg

Add a new rule by choosing “Add” button.

https://farm4.staticflickr.com/3941/15008065383_4b92cbd843_z.jpg

Specify a port (e.g., 80) or port range (e.g., 3000-3030), and protocol (e.g., tcp or udp).

https://farm4.staticflickr.com/3946/15007474154_bef75d8c72_z.jpg

Finally, save the updated configuration, and close the tool. At this point, the firewall will be saved permanently.

https://farm4.staticflickr.com/3942/15628237765_0299a638ab_z.jpg

 

By Rayhan

My name is Rayhan and I'm an IT professional with over 10 years of experience in the field. I'm passionate about all things tech, and I love helping people solve their IT problems. In my free time, I enjoy tinkering with new gadgets and software, and I'm always on the lookout for the latest tech trends. I believe that technology has the power to make our lives easier and more enjoyable, and I'm excited to be a part of this ever-evolving field. Thank you for taking the time to visit my page.

Leave a Reply

Your email address will not be published. Required fields are marked *