我的网站会在 iptables 重启期间停止吗?

Xin*_*Xin 5 linux firewall iptables linux-networking centos6

在 CentOS 6 系统中通过以下命令重启 iptables 期间网站会停止吗?

$ service iptables restart
Run Code Online (Sandbox Code Playgroud)

Mad*_*ter 14

默认情况下,没有。该/etc/init.d/iptables脚本在重新启动时执行以下操作:

restart() {
    [ "x$IPTABLES_SAVE_ON_RESTART" = "xyes" ] && save
    stop
    start
}
Run Code Online (Sandbox Code Playgroud)

尽管存在保存现有规则的问题,未修改的效果stop是禁用所有规则:

[root@bill ~]# service iptables stop
iptables: Setting chains to policy ACCEPT: mangle nat filte[  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
[root@bill ~]# iptables -L -n -v
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
Run Code Online (Sandbox Code Playgroud)

并假设 (a) 您将规则保存在 上stop,并且您现有的规则是您想要的,或者 (b) 您没有将规则保存在 上stop,并且您提议的规则集在/etc/sysconfig/iptables语法和功能上都是正确的,当start重新制定规则,服务应继续不间断。

状态表不受停止防火墙规则的影响,因此stopstart. 不过,NAT 规则确实会(暂时)被 a 擦除stop,因此如果您使用的是 NAT,那么这可能会受到重新启动的影响。