我有一个网络 10.0.0.0/24,网关的 IP 为 10.0.0.1。网关上有两个接口。
eth0 Link encap:Ethernet HWaddr 08:00:27:a1:24:2d
inet addr:10.0.0.1 Bcast:10.0.0.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fea1:242d/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:221 errors:0 dropped:0 overruns:0 frame:0
TX packets:939 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:26698 (26.0 KiB) TX bytes:65901 (64.3 KiB)
eth1 Link encap:Ethernet HWaddr 08:00:27:18:75:46
inet addr:192.168.56.102 Bcast:192.168.56.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe18:7546/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:898138 errors:0 dropped:0 overruns:0 frame:0
TX packets:159141 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1044694113 (996.2 MiB) TX bytes:9919636 (9.4 MiB)
我想从 eth1 进行路由,从 eth1 接收流量到 eth0,内部网络接口,反之亦然。网关进行 IP 转发。我已在 sysctl.conf 中进行了设置:
net.ipv4.ip_forward = 1.
我尝试使用 iptables 但是没有效果:
iptables -A FORWARD -i eth0 -o eth1 -j ACCEPT
iptables -A FORWARD -o eth1 -i eth0 -j ACCEPT
答案1
不太确定您想要什么。我假设您的 eth1 是 192.168.56.0 网络的网关。请尝试:
iptables -t nat -I POSTROUTING -s 192.168.56.0/24 -j SNAT --to 10.0.0.1