Bagaimana cara mengeset namespace jaringan nic di Linux?

1

Saya tahu ip link set tap0 netns XXbisa mengaitkan namespace XXdengan perangkat tap0di Linux. Tapi apa yang harus saya lakukan setelah itu jika saya ingin membawa tap0kembali ke namespace publik (yang tidak disebutkan namanya)?

xywang
sumber

Jawaban:

1

Pertama-tama kita daftarkan antarmuka

[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

Kami menempatkan perangkat veth1 di netns testns

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

kami dapat memverifikasi itu masuk

[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

Kemudian kami mengembalikannya ke jaringan default

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

Dan kami memverifikasi kembali

[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

Anda harus mengganti veth1 dengan tap0 dalam kasus Anda. Jadi sebenarnya:

 [root@host ~]# ip netns exec testns ip link set tap0 netns 1
Pierre-Alain TORET
sumber