OpenStack 网络里 iptables 主要是在 Neutron 的各个 Agent 管理的 namespace 中生效,它并不在物理机全局直接写规则(除了少量 SNAT/DNAT 转发),所以不同的场景里 iptables 的作用也不同。以下是几个典型场景:
路径:
VM → br-int → qrouter → qg-xxx → br-ex → 物理网卡 → 外部网关
iptables 作用点:
qrouter-namespace (L3 agent)
SNAT:把 VM 的私网 IP 转换成 qg-xxx 的外网 IP。
规则在 iptables -t nat -S
里,形如:
-A neutron-l3-agent-snat -s 172.24.30.0/24 -j SNAT --to-source 10.0.19.106
路径:
外部请求 → br-ex → qrouter → DNAT (浮动IP → 内网IP) → qbr → VM
iptables 作用点:
qrouter-namespace
DNAT:把浮动 IP 转换成 VM 内网 IP。
-A neutron-l3-agent-float-snat -d 10.0.19.150/32 -j DNAT --to-destination 172.24.30.10
qbr-xxx (Linux bridge)
VM 的安全组规则在这里:
路径:
VM1 → br-int → qbr → VM2
iptables 作用点:
qbr-xxx(安全组网桥)
路径:
VM1 → br-int → br-tun (VXLAN/GRE) → 物理网卡 → br-tun → br-int → qbr → VM2
iptables 作用点:
源宿主机
目标宿主机
比如你把外部网络直接配置成 provider network,VM 拥有真实的外网 IP。
iptables 作用点:
qbr-xxx
qrouter
VM → DHCP 请求 → qdhcp-namespace
iptables 作用点:
qdhcp-namespace
qbr-xxx