参考URL:
https://blog.csdn.net/chengqiuming/article/details/80140768
一,启用Linux的路由转发功能。
二,新建veth pair
三,新建netnamespace
四,将不同的veth放入不同的Ns
五,手工增加路由表
六,测试
[root@localhost ~]# ip netns list [root@localhost ~]# ip link add tap1 type veth peer name tap1_peer [root@localhost ~]# ip link add tap2 type veth peer name tap2_peer [root@localhost ~]# ip netns add ns1 [root@localhost ~]# ip netns add ns2 [root@localhost ~]# ip link set tap1 netns ns1 [root@localhost ~]# ip link set tap2 netns ns2 [root@localhost ~]# ip addr add local 192.168.100.1/24 dev tap1_peer [root@localhost ~]# ip addr add local 192.168.200.1/24 dev tap2_peer [root@localhost ~]# ip netns exec ns1 ip addr add local 192.168.100.2/24 dev tap1 [root@localhost ~]# ip netns exec ns2 ip addr add local 192.168.200.2/24 dev tap2 [root@localhost ~]# ip link set tap1_peer up [root@localhost ~]# ip link set tap2_peer up [root@localhost ~]# ip netns exec ns1 ip link set tap1 up [root@localhost ~]# ip netns exec ns2 ip link set tap2 up [root@localhost ~]# ip netns exec ns1 route add -net 192.168.200.0 netmask 255.255.255.0 gw 192.168.100.1 [root@localhost ~]# ip netns exec ns2 route add -net 192.168.100.0 netmask 255.255.255.0 gw 192.168.200.1