Como desarmar o namespace da rede do nic no Linux?

1

Eu sei que ip link set tap0 netns XX pode atribuir o namespace XX ao dispositivo tap0 no Linux. Mas o que devo fazer depois disso se eu quiser trazer tap0 de volta para o espaço de nomes público (o sem nome)?

    
por xywang 22.10.2015 / 08:17

1 resposta

1

Primeiro listamos as interfaces

[root@host ~]# ip link list
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
    link/ether 52:54:00:4e:ca:5c brd ff:ff:ff:ff:ff:ff
3: veth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
    link/ether e6:da:05:95:2f:4e brd ff:ff:ff:ff:ff:ff
4: veth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
    link/ether 4a:73:df:f1:87:26 brd ff:ff:ff:ff:ff:ff

Colocamos o dispositivo veth1 em netns testns

[root@host ~]# ip link set veth1 netns testns

podemos verificar se está em

[root@host ~]# ip link list
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
    link/ether 52:54:00:4e:ca:5c brd ff:ff:ff:ff:ff:ff
4: veth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
    link/ether 4a:73:df:f1:87:26 brd ff:ff:ff:ff:ff:ff

[root@host ~]# ip netns exec testns ip link list
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
3: veth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
    link/ether e6:da:05:95:2f:4e brd ff:ff:ff:ff:ff:ff

Em seguida, colocamos de volta nos netns padrão

[root@host ~]# ip netns exec testns ip link set veth1 netns 1

E confirmamos que está de volta em

[root@host ~]# ip netns exec testns ip link list
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
[root@host ~]# ip link list
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT qlen 1000
    link/ether 52:54:00:4e:ca:5c brd ff:ff:ff:ff:ff:ff
3: veth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
    link/ether e6:da:05:95:2f:4e brd ff:ff:ff:ff:ff:ff
4: veth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 1000
    link/ether 4a:73:df:f1:87:26 brd ff:ff:ff:ff:ff:ff

Você precisa substituir veth1 por tap0 no seu caso. Então, na verdade:

 [root@host ~]# ip netns exec testns ip link set tap0 netns 1
    
por 22.10.2015 / 10:15