局域网① | PC 2 | 局域网② |
PC1 is dhcp server and gw | enp2s0 : 192.168.55.148 | PC3 is dhcp server and gw |
192.168.55.254 | enp3s0 : 172.16.10.83 |
172.16.10.254 |
现在想实现从 PC 1 去 ping PC3 , 配置如下
Step 1
PC 1: route add -net 172.16.10.0/24 gw 192.168.55.254 #去往172的包发往 Gateway 192.168.55.254
Step 2
PC 2: echo 1 >/proc/sys/net/ipv4/ip_forward #开启Linux的路由转发
Step 3
PC 2; iptables -t nat -A POSTROUTING -s 172.16.10.0/24 -d 192.168.55.0/24 -o enp2s0
#静态的内部路由, 从源地址172 发往 192的包发往 enp2s0
Step 4
PC 2: iptables -t nat -A POSTROUTING -s 192.168.55.0/24 -d 172.16.10.0/24 -o enp3s0
#静态的内部路由, 从源地址192 发往 172的包发往 enp3s0