Firewalld 是否需要重新启动系统才能使更改生效

Firewalld 是否需要重新启动系统才能使更改生效

vagrantUbuntu 18.04.02 机器上

root@ubuntu-bionic:~# ss -tulanp | grep -i 3306
root@ubuntu-bionic:~# docker run -d --rm -e "MYSQL_ROOT_PASSWORD=root" -p 3306:3306 -v mysql_volume:/var/lib/mysql --name test_mysql mysql:5.7
29401546117d55b5b8d122a225352a6534cf8a9bbb611a195adbbe3ff7341909
root@ubuntu-bionic:~# ss -tulanp | grep -i 3306
tcp   LISTEN  0       128                        *:3306                *:*       users:(("docker-proxy",pid=1986,fd=4)) 
root@ubuntu-bionic:~# firewall-cmd --list-all
public
  target: default
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: ssh dhcpv6-client
  ports: 3306/tcp
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 
root@ubuntu-bionic:~# hostname -I
10.0.2.15 192.168.33.10 172.17.0.1 

然后在我的主机上:

/home/pkaramol/VirtualBox VMs
$ nc -zv -w 2 192.168.33.10 3306
Connection to 192.168.33.10 3306 port [tcp/mysql] succeeded!

3306我现在将尝试删除我明确添加的端口:

回到我的vagrant机器:

root@ubuntu-bionic:~# firewall-cmd --remove-port=3306/tcp --zone=public --permanent
success
root@ubuntu-bionic:~# firewall-cmd --reload
success
root@ubuntu-bionic:~# firewall-cmd --list-all
public
  target: default
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: ssh dhcpv6-client
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

回到我的主机:

$ nc -zv -w 2 192.168.33.10 3306
Connection to 192.168.33.10 3306 port [tcp/mysql] succeeded!

为什么重新加载不能立即应用新状态?

重新启动机器后问题就消失了vagrant,在这种情况下我得到

$ nc -zv -w 2 192.168.33.10 3306
nc: connect to 192.168.33.10 port 3306 (tcp) failed: Connection refused

答案1

我还没有遇到过这样的问题。只是猜测,但是如果您尝试(这不是推荐的做法)firewall-cmd --complete-reload重新加载内核过滤器并且它将终止任何连接,会发生什么

相关内容