How to check all the Linux ports that are opened in Centos / RedHat

     In this article we will see how to check all the Linux ports that are opened in Centos / RedHat. If you want to open or close a port for a Linux firewall you have to edit the rules in the iptables configuration. By default iptables firewall stores its configuration at etc/sysconfig/iptables file. You need to edit this file and add rules to open port.

  This task should be a known task by any sysadmins, and is the base for understanding the security rules around your system.

Here are the steps to open the port 12345 using the default visual editor vim:

Open port 12345 Open flle /etc/sysconfig/iptables:
# vim /etc/sysconfig/iptables
Append rule as follows:
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 12345 -j ACCEPT
Save and close the file. Restart iptables:
# /etc/init.d/iptables restart

Verify that port is open

Run following command:
# netstat -tulpn | less
Make sure iptables is allowing port connections:
# iptables -L -n