open and close ports on CentOS 6/7

How to open and close ports on CentOS 6/7

Learn how to open and close ports on CentOS 6/7. Looking for commands for opening and closing ports on your Linux machine? It is very simple and requires no expert knowledge. This short guide will show you how you can open and close ports on CentOS 6/7.

open and close ports on CentOS 6/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
-Log in to your server root
-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

-Log in to your server root.
-To close port 5555 run the following commands

/sbin/iptables -A INPUT -p tcp --destination-port 5555 -j DROP
/sbin/service iptables save
iptables -S

Open Port in CentOS 7

-Log in to your server root.
-Run the following commands to open 5555

firewall-cmd --zone=public --permanent --add-port=5555/tcp
firewall-cmd --reload

Close Port in CentOS 7
-Log in to your server root.
-Run the following commands to stop 5555

firewall-cmd --zone=public --permanent --remove-port=5555/tcp
firewall-cmd --reload

With this, we conclude the guide for opening and closing ports on the CentOS server.
How to check if a specific port is open?
Type the following command to check open ports in the terminal. For example, we tried checking port 22 on our server.

netstat -lntu | grep 22

 

 

-If the port is open it will show the details of the port including the protocol used.
-If you don’t see any output, it means the port is not open or running on your Linux machine
-You should check all open ports, please run the following command

netstat -lntu

open and close ports on CentOS 6/7

This will list all open ports or currently running ports including TCP and UDP on your Linux machine.
Learn how to install Sentora on CentOS 7. Buy VPS from Oudel Inc.

Scroll to Top