iptables 继续使用旧的 nat 规则

iptables 继续使用旧的 nat 规则

我在网关上使用 iptables snat 将本地源 IP 地址更改为外部。问题是,在我更改规则后(或者即使我刷新 iptables nat 表),网关仍会继续使用旧规则,直到我重新启动网关。我使用 Ubuntu 14.04 Server 作为运行操作系统。因此,例如,在我输入

iptables -t nat -A POSTROUTING -s 10.0.0.129 -j SNAT --to-source 1.2.3.4

10.0.0.129 的外部地址是 1.2.3.4,在外部网关接口上我可以看到类似这样的内容

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
09:48:07.920936 IP 1.2.3.4 > 8.8.8.8: ICMP echo request, id 2425, seq 1, length 64
09:48:08.920066 IP 1.2.3.4 > 8.8.8.8: ICMP echo request, id 2425, seq 2, length 64
09:48:09.920422 IP 1.2.3.4 > 8.8.8.8: ICMP echo request, id 2425, seq 3, length 64

甚至之后

iptables -F 
iptables -t nat -F 
iptables -t nat -A POSTROUTING -s 10.0.0.129 -j SNAT --to-source 4.3.2.1

结果是一样的

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
09:54:20.674671 IP 1.2.3.4 > 8.8.8.8: ICMP echo request, id 2666, seq 1, length 64
09:54:21.674997 IP 1.2.3.4 > 8.8.8.8: ICMP echo request, id 2666, seq 2, length 64
09:54:22.676283 IP 1.2.3.4 > 8.8.8.8: ICMP echo request, id 2666, seq 3, length 64

只有在我重新启动系统后,新规则才会生效,这种情况偶尔会发生,但最近发现,如果不重新启动,我无法更改这些规则。

相关内容