Firewall - Guide To Open & Close Ports On CentOS 6/7 Print

  • 803

This small guide will show you how you can open and close ports on CentOS 6 and 7.

 

Let’s start with how we can open and close ports on your Linux Server with CentOS 6/7.

 

Requirements

  • Root Access for the server

 

Procedure

Open Port in CentOS 6

Step 1

Log in to the root of your server

 

Step 2

Run the following commands to open port 5555
/sbin/iptables -D INPUT -p tcp --destination-port 5555 -j DROP
/sbin/service iptables save
iptables -S

 

Close Port in CentOS 6

Step 1

Log in to the root of your server.

 

Step 2

Run the following commands to close port 5555
/sbin/iptables -A INPUT -p tcp --destination-port 5555 -j DROP
/sbin/service iptables save
iptables -S

 

Open Port in CentOS 7

Step 1

Log in to the root of your server.

 

Step 2

Run the following commands to open 5555
firewall-cmd --zone=public --permanent --add-port=5555/tcp
firewall-cmd --reload

 

Close Port in CentOS 7

Step 1

Log in to the root of your server.

 

Step 2

Run the following commands to close 5555
firewall-cmd --zone=public --permanent --remove-port=5555/tcp
firewall-cmd --reload

 

With this, we finish the guide for opening and closing ports on the CentOS server.

 

How to check if a particular port is open?

  • In the terminal type the following command to check open port. For Example, we tried checking Port 22 on our server.
    netstat -lntu | grep 22

  • If the port is open then this will show the details for the port along with the protocol used.
    If you see no output then that means the port is not open or running on your Linux Machine
  • If you want to check all the open ports then kindly run the following command
    netstat -lntu

This will list all open ports or currently running ports including TCP and UDP in your Linux Machine.


Was this answer helpful?

« Back