[root@slions_pc1 ~]# ip link add veth0 type veth peer name veth1 [root@slions_pc1 ~]# ip link show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/ether 00:0c:29:97:8c:d0 brd ff:ff:ff:ff:ff:ff 3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default link/ether 02:42:8a:8f:d7:d5 brd ff:ff:ff:ff:ff:ff 8: veth1@veth0: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether ae:f9:75:fa:93:4d brd ff:ff:ff:ff:ff:ff 9: veth0@veth1: <BROADCAST,MULTICAST,M-DOWN> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether d2:24:de:9b:b5:d9 brd ff:ff:ff:ff:ff:ff
可以看到,此时本地多了8和9两块没有被激活的网卡,并且从网卡名上可以看出对应关系
移动veth网卡到netns
把其中一个网卡移动到命名空间slions_ns1中
1
[root@slions_pc1 ~]# ip link set veth1 netns slions_ns1
在slions_ns1中验证网卡信息
1 2 3 4 5
[root@slions_pc1 ~]# ip netns exec slions_ns1 ip a 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 8: veth1@if9: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether ae:f9:75:fa:93:4d brd ff:ff:ff:ff:ff:ff link-netnsid 0
[root@slions_pc1 ~]# ip link show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/ether 00:0c:29:97:8c:d0 brd ff:ff:ff:ff:ff:ff 3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default link/ether 02:42:8a:8f:d7:d5 brd ff:ff:ff:ff:ff:ff 9: veth0@if8: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether d2:24:de:9b:b5:d9 brd ff:ff:ff:ff:ff:ff link-netnsid 0
我们还可以给slions_ns1中的veth1改名
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
[root@slions_pc1 ~]# ip netns exec slions_ns1 ip link set dev veth1 name eth0 [root@slions_pc1 ~]# ip netns exec slions_ns1 ifconfig -a eth0: flags=4098<BROADCAST,MULTICAST> mtu 1500 ether ae:f9:75:fa:93:4d txqueuelen 1000 (Ethernet) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0