How to check open ports on RHEL8/CentOS8

Method 1: Using ‘firewal-cmd’

We can use the command firewall-cmd --permanent --list-all to check all the open ports and services in our system

Note We can separately check both open ports and services

firewall-cmd --permanent --list-port
firewall-cmd --permanent --list-services

For adding a port we use the command (Here we are adding port number 2020)

firewall-cmd --permanent --add-port=2020/tcp

After every port addition we must reload the firewall

firewall-cmd --reload

For adding service port we can use the command (Here we are adding the https service)

firewall-cmd --permanent --add-service=https

Reload the firewall

firewall-cmd --reload

Method 2: Using ‘nmap’

nmap is mainly used for checking the open ports in remote systems

Note Check whether nmap is installed in your system if not install it

yum install nmap -y

To check the open ports on remote systems (Here we use the remote system hostname as myweb.thestack.net)

nmap myweb.thestack.net

To check for a specific port :

nmap -p 80 myweb.thestack.net

Related Articles