Opening and Checking Ports in CentOS 7

Starting with CentOS 7, firewall-related work should use firewall-cmd instead of iptables-related commands.

Opening a Port

Open a port as follows.

firewall-cmd --zone=public --permanent --add-port={port number}/tcp

Apply the setting.

firewall-cmd --reload

Actual example:

[root@localhost ~]# firewall-cmd --zone=public --permanent --add-port=9090/tcp
success
[root@localhost ~]# firewall-cmd --reload
success

Checking Open Ports

Use the following command to check open ports.

firewall-cmd --zone=public --list-all
[root@localhost ~]# firewall-cmd --zone=public --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources:
  services: dhcpv6-client ssh
  ports: 9090/tcp

You can confirm that port 9090, opened above, is listed.