How to List Open Ports Using FirewallD in Linux

In this article, I show how to list open ports using FirewallD in Linux. In CentOS 7 the FirewallD is the default firewall program, as the same to other Red Hat, Fedora, and other popular Linux distributions. It is very simple to use command line interface (CLI) that’s a great alternative to iptabels. Now you going to see how to use the commands and should be same for any Linux distribution with FirewallD.
If you want to know more about FirewallD here you have an article.
Check the FirewallD status
First, check whether firewalld service is running with the below command.
1 |
sudo systemctl status firewalld |
Start the FirewallD Services
Here your firewalld services not in active run the following command to start the services.
1 |
sudo systemctl start firewalld |
Stop the FirewallD Services
To stop the firewalld services use the below command.
1 |
sudo systemctl stop firewalld |
List the FirewallD Services
If you like to list overall FirewallD configuration use the following command to list.
1 |
sudo firewall-cmd --list-all |
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
[root@s191-113-144-32 ~]# sudo firewall-cmd --list-all public target: default icmp-block-inversion: no interfaces: sources: services: ssh dhcpv6-client ports: 80/tcp 9018/udp protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules: [root@s191-113-144-32 ~]# |
If the services ssh dhcpv6-client services are enabled, that means the relevant port to these services is also open.
Check the opened ports
Using ssh you can find out what are the open ports are enabled with the following command.
1 |
grep ssh /etc/services |
In the below list, you can see the opened ports, the ssh service opens the TCP port 22 and UDP port 22.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[root@s191-113-144-32 ~]$ grep ssh /etc/services ssh 22/tcp # The Secure Shell (SSH) Protocol ssh 22/udp # The Secure Shell (SSH) Protocol x11-ssh-offset 6010/tcp # SSH X11 forwarding offset ssh 22/sctp # SSH sshell 614/tcp # SSLshell sshell 614/udp # SSLshell netconf-ssh 830/tcp # NETCONF over SSH netconf-ssh 830/udp # NETCONF over SSH sdo-ssh 3897/tcp # Simple Distributed Objects over SSH sdo-ssh 3897/udp # Simple Distributed Objects over SSH snmpssh 5161/tcp # SNMP over SSH Transport Model snmpssh-trap 5162/tcp # SNMP Notification over SSH Transport Model tl1-ssh 6252/tcp # TL1 over SSH tl1-ssh 6252/udp # TL1 over SSH ssh-mgmt 17235/tcp # SSH Tectia Manager ssh-mgmt 17235/udp # SSH Tectia Manager [root@s191-113-144-32 ~]$ |
List the Open Services
In the previous command sudo firewall-cmd –list-all
list out all the FirewallD configurations, Here if you like to list only what services are allowed to have open ports use the below command.
1 |
sudo firewall-cmd --list-services |
List the Open Ports
If you like to list out the open ports in your server using the following command.
1 |
sudo firewall-cmd --list-ports |
awsCentOSCentOS 7FedoraFirewallFirewallDRedhat
Mraj
Creative Designer & Developer specialist by the spirit and a loving blogger by thoughts. If you have any questions let me drop an email with the article name to the following email id: [email protected]