How to add service or port by Firewall on centos 7

First install firewall on your system :

yum install firewalld -y

Now start & enable firewall :

systemctl start firewalld
systemctl enable firewalld
systemctl status firewalld

Now see how many zones in your system & who is your default zone :

firewall-cmd --get-zones
firewall-cmd --get-default-zone

Your default zone must be public if not then set default zone to public or your system may not work properly :

firewall-cmd --set-default-zone=public

Now see the permanent list of all services & ports on your public zone :

firewall-cmd --permanent --zone=public --list-all

If you need to add any service on your public zone then you can add like this :

firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --list-services

If you want to remove any service from your public zone you can do like this :

firewall-cmd --permanent --zone=public --remove-service=http

Now add a port to public zone & remove it if you need by this command :

firewall-cmd --permanent --zone=public --add-port=2222/tcp
firewall-cmd --zone=public --list-ports
firewall-cmd --permanent --zone=public --remove-port=25/tcp
You must say what is the protocol it is tcp or udp during adding a port.

Thank you for reading this article.

Was this helpful?

1 / 0

Leave a Reply 2

Your email address will not be published. Required fields are marked *


bripiruffedia

bripiruffedia

Wow!!! Thanks.

Neefvoingenew

Neefvoingenew

Thanks!