How to open a port on Centos 7

Today I need to open a port on my Centos 7 box and I’m glad I know nothing but iptables which is give me ‘silent’ result 🙂 . After digging a few command from Redhat documentation I found its extremely easy.

As usual I make my note here for my future reference in case I need copy and paste method :-).

Centos 7 comes with firewalld by default. Its use firewall-cmd . For my need to open port 8082 tcp then I just need to type :

firewall-cmd –get-active-zones

public
interfaces: eth0

Yes, I only have ‘public’ zone.

To open port 8082 :

firewall-cmd –zone=public –add-port=8082/tcp –permanent

success

Save it.

firewall-cmd –reload

To check if this port (8082) is opened :

firewall-cmd –zone=public –list-all

public (default, active)
interfaces: eth0
sources:
services: dhcpv6-client http ssh
ports: 3306/tcp 53/udp 8082/tcp
masquerade: no
forward-ports:
icmp-blocks:
rich rules:

Yes, 8082 listed.

Very neat in my opinion 🙂

p.s:

systemctl status firewalld

firewall-cmd –state

for check if the service (firewalld) run