#添加网络名称空间 ip netns add r1 ip netns add r2

#添加一对虚拟网卡 ip link add name veth1.1 type veth peer name veth1.2

#把设备和网络名称空间关联起来 ip link set dev veth1.1 netns r1 #把其中一端挪到网络名字空间里, 一个设备只能属于一个名称空间

#改个网卡名字 ip netns exec r1 ip link set dev veth1.1 name eth0

#激活宿主机这一端 ifconfig veth1.2 10.1.0.1/24 up

#激活另一端 ip netns exec r1 ifconfig eth0 10.1.0.2/24 up

#成功ping通 [root@test ~]# ping 10.1.0.2 PING 10.1.0.2 (10.1.0.2) 56(84) bytes of data. 64 bytes from 10.1.0.2: icmp_seq=1 ttl=64 time=0.017 ms