# 将mac1放入到net1 namespace中 [root@localhost vagrant]# ip link set mac1 netns net1 [root@localhost vagrant]# ip netns exec net1 ip link 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 24: mac1@if3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT link/ether 3e:b8:e9:1d:3b:c8 brd ff:ff:ff:ff:ff:ff link-netnsid 0
# 在net1中将mac1接口命名为eth0 [root@localhost vagrant]# ip netns exec net1 ip link set mac1 name eth0 [root@localhost vagrant]# ip netns exec net1 ip link 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 24: eth0@if3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT link/ether 3e:b8:e9:1d:3b:c8 brd ff:ff:ff:ff:ff:ff link-netnsid 0
# 在net1中分配eth0网卡的ip地址为192.168.8.120 [root@localhost vagrant]# ip netns exec net1 ip addr add 192.168.8.120/24 dev eth0 [root@localhost vagrant]# ip netns exec net1 ip link set eth0 up [root@localhost vagrant]# ip netns exec net1 ip link 1: lo: <LOOPBACK> mtu 65536 qdisc noop state DOWN mode DEFAULT link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 24: eth0@if3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN mode DEFAULT link/ether 3e:b8:e9:1d:3b:c8 brd ff:ff:ff:ff:ff:ff link-netnsid 0
[root@localhost vagrant]# docker network ls NETWORK ID NAME DRIVER SCOPE b6a128f1730e bridge bridge local a65957cd6c3f docker_gwbridge bridge local 540bb390028a host host local b3e83aa45886 isolated_nw bridge local ec6c4e77321d local_alias bridge local 5c637798d559 mcv macvlan local 3d247d0414d0 none null local