docker info 显示 bridge-nf-call-iptables 禁用的处理
在 树莓派Raspberry Pi OS(64位)安装Docker 完成后(实际上很多 Linux环境安装Docker 都会遇到),执行 docker info 检查会看到如下警告:
docker info 显示 bridge-nf-call-iptables 被禁止的警告WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
这个警告实际上是 预期特性 :
bridge-nf-call-iptables内核参数控制穿过网桥bridge的数据包是否由host主机系统上的 iptables 规则处理。通常不建议启用这个选项:启用
bridge-nf-call-iptables内核参数(1)可能会导致 容器流量 被针对host主机的iptables规则阻止(出现不可预测的行为,通常容器不希望流量收到主机级别防火墙干扰/保护)这也是为何 libvirt 网桥型网络 要求 禁止
bridge-nf-call-iptables内核参数(0),否则可能因为host主机配置了iptables防火墙(默认netfilter激活在bridge上会通过FORWARD规则过滤掉bridge上主机之间流量),导致bridge模式连接到br0的虚拟机之间网络不能互通
cat << EOF > /etc/sysctl.d/bridge.conf
net.bridge.bridge-nf-call-ip6tables=0
net.bridge.bridge-nf-call-iptables=0
net.bridge.bridge-nf-call-arptables=0
EOF
sysctl -p /etc/sysctl.d/bridge.conf
在 KVM / Libvirt虚拟机管理器 环境中,要求 禁止
bridge-nf-call-iptables内核参数(0),是因为希望在虚拟机内部管理网络过滤,防止host主机iptablesFORWARD影响虚拟机 libvirt 网桥型网络在 Docker 容器环境中,要求 启用
bridge-nf-call-iptables内核参数(1),是因为容器内部不能通过iptables控制内核过滤规则,需要借助host主机iptables来管理容器网络。
Docker环境启用 bridge-nf-call-iptables (内核参数 1 )
和 libvirt 网桥型网络 配置相反(方法可借鉴),执行以下命令为Docker的host主机启用 bridge-nf-call-iptables (内核参数 1 ):
bridge-nf-call-iptables (内核参数 1 )cat << EOF > /etc/sysctl.d/bridge.conf
net.bridge.bridge-nf-call-ip6tables=1
net.bridge.bridge-nf-call-iptables=1
EOF
sysctl -p /etc/sysctl.d/bridge.conf
br_netfilter 内核模块(提供 bridge-nf-call-iptables 入口)
我在 树莓派Raspberry Pi 5 上的 Raspbery Pi OS(Raspbian) 遇到如下报错:
bridge-nf-call-iptables 内核参数入口sysctl: cannot stat /proc/sys/net/bridge/bridge-nf-call-ip6tables: No such file or directory
sysctl: cannot stat /proc/sys/net/bridge/bridge-nf-call-iptables: No such file or directory
这个内核入口错误是因为内核没有加载 br_netfilter 模块导致的,所以修正如下:
br_netfilter 内核模块modprobe br_netfilter
echo "br_netfilter" >> /etc/modules-load.d/br_netfilter.conf