删除命名空间后,Ubuntu 没有连接到容器的网络接口。我的环境中没有任何命名空间:
$ ls -la /var/run/netns/
total 0
drwxr-xr-x 2 root root 40 Sep 18 13:11 .
drwxr-xr-x 23 root root 940 Sep 18 13:21 ..
尽管如此,仍然无法创建接口:
$ sudo vconfig add eth1 268
ERROR: trying to add VLAN #268 to IF -:eth1:- error: File exists
$ sudo ip link show eth1.268
Device "eth1.268" does not exist.
有什么想法可以找到丢失的接口吗?当然,这是我的错,我忘记将接口从命名空间分配给 netns 1(主机系统),但我不相信它已经消失了……
Strace 提供的信息不多:
# strace vconfig add eth1 268
execve("/sbin/vconfig", ["vconfig", "add", "eth1", "268"], [/* 16 vars */]) = 0
brk(0) = 0x1742000
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fe6bb754000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=53226, ...}) = 0
mmap(NULL, 53226, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fe6bb747000
close(3) = 0
access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory)
open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0P \2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1840928, ...}) = 0
mmap(NULL, 3949248, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7fe6bb16f000
mprotect(0x7fe6bb329000, 2097152, PROT_NONE) = 0
mmap(0x7fe6bb529000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1ba000) = 0x7fe6bb529000
mmap(0x7fe6bb52f000, 17088, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7fe6bb52f000
close(3) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fe6bb746000
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fe6bb744000
arch_prctl(ARCH_SET_FS, 0x7fe6bb744740) = 0
mprotect(0x7fe6bb529000, 16384, PROT_READ) = 0
mprotect(0x601000, 4096, PROT_READ) = 0
mprotect(0x7fe6bb756000, 4096, PROT_READ) = 0
munmap(0x7fe6bb747000, 53226) = 0
open("/proc/net/vlan/config", O_RDONLY) = 3
close(3) = 0
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3
ioctl(3, SIOCSIFVLAN, 0x7ffc432b83c0) = -1 EEXIST (File exists)
write(2, "ERROR: trying to add VLAN #268 t"..., 66ERROR: trying to add VLAN #268 to IF -:eth1:- error: File exists
) = 66
exit_group(3) = ?
+++ exited with 3 +++
答案1
删除命名空间后,如果命名空间中仍有进程在运行,就会发生这种情况。您需要停止/终止此进程,然后才能再次添加相同的接口。如果找不到该进程,您可以在 /proc 中使用 find 搜索接口名称,例如:
root@linx:~# vconfig add enp1s0 10
ERROR: trying to add VLAN #10 to IF -:enp1s0:- error: File exists
root@linx:~# find /proc/ -name enp1s0.10
/proc/18557/task/18557/net/vlan/enp1s0.10
/proc/18557/task/18557/net/dev_snmp6/enp1s0.10
/proc/18557/net/vlan/enp1s0.10
/proc/18557/net/dev_snmp6/enp1s0.10
root@linx:~# kill -9 18557
root@linx:~# vconfig add enp1s0 10
Added VLAN with VID == 10 to IF -:enp1s0:-