是否有切换到现有命名空间的命令?

rep*_*lay 5 util-linux linux-kernel namespace

我使用了多个 UTS 命名空间,每个命名空间都有一些服务器不断运行。

我可以通过 获取命名空间 ID readlink /proc/<pid>/ns/uts,现在我想更改为给定的命名空间以在那里进行修改。

据我了解man 2 setns,通过使用setns()系统调用应该可以做到这一点。甚至有一个示例程序可以做我正在寻找的东西,但我希望已经有一些实用程序,大多数发行版都包含可以做同样的工作。

unshare命令似乎对我不起作用,因为它只创建新的命名空间来启动进程,但它不允许我指定现有的命名空间。

rep*_*lay 5

2013 年 1 月 11 日,该实用程序nsenter已添加到util-linux软件包中。这是提交及其评论:

commit f8aa8e9495dd89f39b7d0db5aab431cac02ea519
Author: Eric W. Biederman <ebiederm@xmission.com>
Date:   Fri Jan 11 14:46:38 2013 -0800

nsenter: new command (light wrapper around setns)

Inspired by unshare, nsenter is a simple wrapper around setns that
allows running a new process in the context of an existing process.

Full paths may be specified to the namespace arguments so that
namespace file descriptors may be used wherever they reside in the
filesystem.

Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Run Code Online (Sandbox Code Playgroud)

util-linux其中的第一个版本nsenter是2013 年 4 月发布的2.23

不幸的是,大多数发行版目前仍在使用旧版本,其中util-linux尚未包含此实用程序。