gpt4 book ai didi

networking - Linux 命名空间 : Is it possible for a network namespace to exist without being associated with a process?

转载 作者:IT老高 更新时间:2023-10-28 21:19:19 25 4
gpt4 key购买 nike

ip netns/var/run/ns 中创建对(命名的)网络命名空间的引用,可以很容易地跟踪。同样,也可以通过 /proc/[pid]/ns/net 确定。 .但是,某些自定义程序可以创建一个 net ns 并将相应的 inode 保存在其他一些非常规的位置。这会使我们难以确定是否有我们可以列出的 net ns。

其次,unshare <cmd>进程退出时销毁网络 ns,这很好。但是,ip netns exec <netns> <cmd>即使在命令/进程退出后也会保留 ns 。所以我相信,任何自定义程序都可以做到这一点。

因此,问题是:自定义程序是否有可能创建一个未命名的网络 ns,并且它与任何进程不关联

此外,如果我们不知道到 inode 的路径,是否可以从用户空间列出这样的(隐藏的)网络 ns? (内核当然有net ns的链表)一段代码会很有帮助。

最佳答案

Is it possible that a custom program creates an unnamed net ns, and it is left unassociated with any process?

是的,这是可能的。根据 Linux 命名空间手册页( http://man7.org/linux/man-pages/man7/namespaces.7.html ):

Each process has a /proc/[pid]/ns/ subdirectory containing one entry for each namespace that supports being manipulated by setns(2):

Bind mounting (see mount(2)) one of the files in this directory to somewhere else in the filesystem keeps the corresponding namespace of the process specified by pid alive even if all processes currently in the namespace terminate.

关于另一个问题:

is it possible to list out such (hidden) net ns from user-space, given that we do not know the paths to the inodes?

如果您考虑上面第一个问题的引用,通过检查绑定(bind)路径,您应该能够找到那些隐藏的命名空间

关于networking - Linux 命名空间 : Is it possible for a network namespace to exist without being associated with a process?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34560877/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com