欢迎来到之路教程(on itroad-com)

回答

Libvirtd 进程会在启动 libvirtd 时将 iptables 规则添加到 iptables 中。
iptables 将在启动 libvirtd 时运行,即使之前禁用了 iptables。
这些规则不会影响物理网络的防火墙配置。
如果不使用 xen 环境,则根本不需要这些规则。
在非 xen 环境中,通过运行以下命令关闭服务 libvirtd 是安全的:

# chkconfig --level 345 libvirtd off
# service libvirtd stop

启动libvirtd时如何防止iptables启动

使用带有 Xen 内核的 Red Hat Enterprise Linux 5 时,libvirtd 守护进程将默认设置为启动。
“libvirtd”是一个守护进程,它会运行 /usr/sbin/libvirtd 命令并根据服务器上的物理网络状态和 /etc/libvirt/qemu/network 下的配置来创建一些 iptables 规则,例如:

# service iptables status
Table: nat
Chain PREROUTING (policy ACCEPT)
num  target     prot opt source               destination         
Chain POSTROUTING (policy ACCEPT)
num  target     prot opt source               destination         
1    MASQUERADE  all  --  192.168.122.0/24    !192.168.122.0/24    
Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination         
Table: filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination         
1    ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0           udp dpt:53 
2    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:53 
3    ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0           udp dpt:67 
4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:67 
Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination         
1    ACCEPT     all  --  0.0.0.0/0            192.168.122.0/24    state RELATED,ESTABLISHED 
2    ACCEPT     all  --  192.168.122.0/24     0.0.0.0/0           
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
4    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-port-unreachable 
5    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-port-unreachable 
Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination
  1. 检查启动和运行期间是否启用了 libvirtd 服务。
# chkconfig --list libvirtd
libvirtd        0:off   1:off   2:off   3:on    4:on    5:on    6:off
# /etc/init.d/libvirtd status
libvirtd (pid  3895) is running...
  1. 停止 libvirtd 并关闭 chkconfig 以防止它加载 iptables。
# chkconfig --level 345 libvirtd off
# service libvirtd stop
  1. 重启主机并验证。

注意:除非我们在 Oracle Linux 上使用 xen 内核来托管 VM,否则关闭 libvirtd 是安全的。

注意:已经注意到 docker 服务也启动了 iptables 服务。

问题

即使使用 'chkconfig -level 345 iptables off' 关闭了 iptables,
每次重启系统后,'service iptables status' 仍会显示一些 iptables 规则。

iptables 每次在系统重启后加载
日期:2020-09-17 00:14:00 来源:oir作者:oir