Networking

lxc / lxd 中的網路命名空間在哪裡?

  • May 13, 2020

我試圖在/的上下文中理解名稱空間lxd``lxc

我有兩個容器,它們分別eth0橋接到主機br1br2主機上。這是通過虛擬乙太網介面完成的

root@srv:~# ip link
(...)

5: br1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
   link/ether fe:f0:ca:e8:c4:ae brd ff:ff:ff:ff:ff:ff
6: br2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default 
   link/ether fe:45:66:a8:37:a7 brd ff:ff:ff:ff:ff:ff
11: vethHRMPOM@if10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br1 state UP mode DEFAULT group default qlen 1000
   link/ether fe:f0:ca:e8:c4:ae brd ff:ff:ff:ff:ff:ff link-netnsid 1
27: vethNTG58H@if26: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br2 state UP mode DEFAULT group default qlen 1000
   link/ether fe:45:66:a8:37:a7 brd ff:ff:ff:ff:ff:ff link-netnsid 0

我想知道,比如說,另一邊在哪裡vethHRMPOM@if10

ip netns list是空的。

/var/run/netns不存在(這是 Ubuntu 15.10)

ip netns list-id節目

nsid 0 
nsid 1 

這似乎對應於ip list上面的最後一個元素。由於所有命令都按名稱(而不是 ID)引用命名空間,我如何獲得有關這些nsid 0的更多資訊?1

預設情況下,LXC 不會使用 iproute2 utils 註冊網路命名空間,但您可以手動註冊它們:

root@host:~# lxc-info -n testlxc
Name:           testlxc
State:          RUNNING
PID:            8888
<snip>
root@host:~# mkdir -p /var/run/netns/
root@host:~# ln -s /proc/8888/ns/net /var/run/netns/testlxc

netns註冊後,很容易回答問題:

root@host:~# ip netns list
testlxc (id: 0)
root@host:~# ip addr show | grep -A2 -B1 "link-netnsid 0"
15: veth9ICKL6@if14: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br1 state UP group default qlen 1000
   link/ether fe:b2:e0:99:81:53 brd ff:ff:ff:ff:ff:ff link-netnsid 0
   inet6 fe80::fcb2:e0ff:fe99:8153/64 scope link 
      valid_lft forever preferred_lft forever

引用自:https://serverfault.com/questions/765789