Enable / Disable TCP Ports

To enable / disable port accessibility on a machine, we can use the firewall-cmd utility.

Note: You need Administrator / sudo access to play around with this utility.

Switch to Root Account.

1
$ sudo su

To Install firewalld

If you already have firewall daemon available on your machine, you can skip this.

Execute the below command to install firewall daemon

1
yum install -y firewalld

To check status of firewall daemon

1
firewall-cmd --state

You should see running as the result for the above command.

Enable TCP Ports

To enable any tcp port say 9090 for example, the command you need to execute is :

1
2
firewall-cmd --zone=public --permanent --add-port=9090/tcp
firewall-cmd --reload

Enable TCP Ports

To disable any tcp port say 8090 for example, the command you need to execute is :

1
2
firewall-cmd --zone=public --permanent --remove-port=8090/tcp
firewall-cmd --reload

List open ports

To list publicly accessible ports on the machine, use the below command.

1
2
$ firewall-cmd --zone=public --list-ports
9090/tcp