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 9

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


bripiruffedia

bripiruffedia

Wow!!! Thanks.

Neefvoingenew

Neefvoingenew

Thanks!

morenfo

morenfo

Simply desire to say your article is as astounding. The clarity in your post is just great and i can assume you’re an expert on this subject. Fine with your permission let me to grab your feed to keep updated with forthcoming post. Thanks a million and please continue the gratifying work.

Mariel

Mariel

It’s amazing to pay a visit this site and reading
the views of all friends on the topic of this article, while I am
also keen of getting familiarity.

Niamh

Niamh

Hi Dear, are you in fact visiting this website daily, if so afterward you will
without doubt get fastidious knowledge.

Melodee

Melodee

Thanks for another informative blog. The place else could I am getting that type of info written in such an ideal means?
I have a venture that I am simply now working on, and I’ve been at the glance out for such information.

butpsam

butpsam

I’m not that much of a internet reader to be honest but your sites really nice, keep it up!
I’ll go ahead and bookmark your website to come back in the future.
Cheers

pgamour

pgamour

This is really fascinating, You’re an overly professional blogger.
I have joined your feed and sit up for in the hunt for
extra of your great post. Also, I’ve shared your website in my social networks

pheir

pheir

I am in fact delighted to glance at this blog posts which contains tons of valuable information,
thanks for providing these information.