As I know, I can use the “clone” to create a process and a namespace, but the namespace created in this way has no name. For example, I create a network namespace with the parameter: CLONE_NEWNS, but in the command “ip netns list”, there is no namespace list because the namespace created has no name. But I can use the command “ip netns add xxx” to create a namespace with the name “xxx”.
I wonder how to create a namespace with name using system call “clone”.
Advertisement
Answer
Create a symlink from /var/run/netns/<name>
to /proc/<pid>/ns/net
, where <pid>
is the PID of the process that was created with CLONE_NEWNS
and <name>
is the name you want to use to refer to the network namespace.
Note that the ip link set netns
command will accept either a PID or a name, and the nsenter
command can access namespaces by PID as well, so you may not actually need to assign a name to the network namespace.