29

Had a port opened up to for public use using firewall-cmd, I wanted to limit this port to a specific IP which I found the answer for on this SITE.

I used the following to open it:

$ firewall-cmd --permanent --zone=public --add-port=10050/tcp
$ firewall-cmd --reload

Now using the information from the information I found I wanted to restrict access to this port to a specific IP address. Do I need to first remove this port from public access?

Or Can I just just add the new rule as follows and that will take care of the problem for me?

$ firewall-cmd --new-zone=special
$ firewall-cmd --permanent --zone=special --add-rich-rule='
  rule family="ipv4"
  source address=”123.1.1.1"
  port protocol="tcp" port="10050" accept'

I have tried the following:

$ firewall-cmd --zone=public --remove-port=10050/tcp
$ firewall-cmd --reload

But when I run the following:

$ firewall-cmd --list-ports 

10050/tcp is still displayed.

Please understand I'm not overly familiar with Sever side configurations.

Soultion: Do not forget the --runtime-to-permanent

$ firewall-cmd --zone=public --remove-port=10050/tcp
$ firewall-cmd --runtime-to-permanent
$ firewall-cmd --reload 
mcv
  • 1,015

5 Answers5

51

Solution: Do not forget the --runtime-to-permanent

$ firewall-cmd --zone=public --remove-port=10050/tcp
$ firewall-cmd --runtime-to-permanent 
$ firewall-cmd --reload 
mcv
  • 1,015
13
# firewall-cmd --zone=public --remove-port=12345/tcp --permanent
# firewall-cmd --reload

Replace 12345 with the port you want to remove.

Zing Lee
  • 231
3

Follow these steps, you will be fine:

$ firewall-cmd --zone=public --remove-port=10050/tcp
$ firewall-cmd --runtime-to-permanent 
$ firewall-cmd --reload 
$ systemctl restart firewalld
$ firewall-cmd --zone=public --list-ports
2

Please Running these step

  1. firewall-cmd --permanent --remove-service=telnet
  2. firewall-cmd --reload
  3. systemctl restart firewalld.service
  4. firewall-cmd --list-all
  5. iptables -nvL

your iptables firewalld willbe not showed service telnet

Regards

1

All those answers were wrong on my fedora server. My solution was:

firewall-cmd --remove-port=8081/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-all

Please note that the command firewall-cmd --permanent --remove-port=8081/tcp was throwing an error "firewall-cmd: error: unrecognized arguments: –-remove-port=8081/tcp".

Den
  • 11