namespaces — overview of Linux namespaces
| Use Case | Command | Description |
|---|---|---|
| 🔍 List current process namespaces | ls -l /proc/$$/ns | Show symlinks to all namespace handles |
| 🆕 Create new namespace (e.g., network) | unshare -n | Run command in a new network namespace |
| 🔄 Join existing namespace | nsenter --target PID --net | Enter the network namespace of a process |
| 🔗 Bind mount namespace to keep alive | mount --bind /proc/PID/ns/net /some/path | Prevent namespace destruction when no process remains |
| 📊 Show namespace inode | readlink /proc/$$/ns/uts | Display namespace type and inode number |
| 🔒 Check namespace limits | cat /proc/sys/user/max_*_namespaces | View per-user namespace creation limits |
| 📋 List all namespaces on system | lsns | List all namespaces of a given type (see lsns(8)) |
A namespace wraps a global system resource in an abstraction that makes it appear to the processes within the namespace that they have their own isolated instance of the global resource. Changes to the global resource are visible to other processes that are members of the namespace, but are invisible to other processes. One use of namespaces is to implement containers.
This page provides pointers to information on the various namespace types, describes the associated /proc files, and summarizes the APIs for working with namespaces.
The following table shows the namespace types available on Linux. The second column shows the flag value used to specify the namespace type in various APIs. The third column identifies the manual page with details. The last column is a summary of the isolated resources.
| 🚀 Namespace | Flag | 📄 Page | Isolates |
|---|---|---|---|
| 📦 Cgroup | CLONE_NEWCGROUP | cgroup_namespaces(7) | Cgroup root directory |
| 🔗 IPC | CLONE_NEWIPC | ipc_namespaces(7) | System V IPC, POSIX message queues |
| 🌐 Network | CLONE_NEWNET | network_namespaces(7) | Network devices, stacks, ports, etc. |
| 📁 Mount | CLONE_NEWNS | mount_namespaces(7) | Mount points |
| 🆔 PID | CLONE_NEWPID | pid_namespaces(7) | Process IDs |
| ⏱️ Time | CLONE_NEWTIME | time_namespaces(7) | Boot and monotonic clocks |
| 👤 User | CLONE_NEWUSER | user_namespaces(7) | User and group IDs |
| 🖥️ UTS | CLONE_NEWUTS | uts_namespaces(7) | Hostname and NIS domain name |
As well as various /proc files described below, the namespaces API includes the following system calls:
flags argument specifies one or more CLONE_NEW* flags, new namespaces are created for each flag, and the child process is made a member of those namespaces. (Also implements features unrelated to namespaces.)/proc/[pid]/ns files.flags argument specifies one or more CLONE_NEW* flags, new namespaces are created for each flag, and the calling process is made a member of those namespaces. (Also implements features unrelated to namespaces.)ioctl(2) operations can be used to discover information about namespaces. These are described in ioctl_ns(2).Creation of new namespaces using clone(2) and unshare(2) in most cases requires the CAP_SYS_ADMIN capability, since in the new namespace, the creator will have the power to change global resources that are visible to other processes. User namespaces are the exception: since Linux 3.8, no privilege is required to create a user namespace.
Each process has a /proc/[pid]/ns/ subdirectory containing one entry for each namespace that supports being manipulated by setns(2):
$ ls -l /proc/$$/ns | awk '{print $1, $9, $10, $11}'
total 0
lrwxrwxrwx. cgroup -> cgroup:[4026531835]
lrwxrwxrwx. ipc -> ipc:[4026531839]
lrwxrwxrwx. mnt -> mnt:[4026531840]
lrwxrwxrwx. net -> net:[4026531969]
lrwxrwxrwx. pid -> pid:[4026531836]
lrwxrwxrwx. pid_for_children -> pid:[4026531834]
lrwxrwxrwx. time -> time:[4026531834]
lrwxrwxrwx. time_for_children -> time:[4026531834]
lrwxrwxrwx. user -> user:[4026531837]
lrwxrwxrwx. uts -> uts:[4026531838]
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.
Opening one of the files in this directory (or a file that is bind mounted to one of these files) returns a file handle for the corresponding namespace of the process specified by pid. As long as this file descriptor remains open, the namespace will remain alive, even if all processes in the namespace terminate. The file descriptor can be passed to setns(2).
In Linux 3.7 and earlier, these files were visible as hard links. Since Linux 3.8, they appear as symbolic links. If two processes are in the same namespace, then the device IDs and inode numbers of their /proc/[pid]/ns/xxx symbolic links will be the same; an application can check this using the stat.st_dev and stat.st_ino fields returned by stat(2). The content of this symbolic link is a string containing the namespace type and inode number as in the following example:
$ readlink /proc/$$/ns/uts
uts:[4026531838]
The symbolic links in this subdirectory are as follows:
/proc/[pid]/ns/cgroup (since Linux 4.6) — Handle for the cgroup namespace of the process./proc/[pid]/ns/ipc (since Linux 3.0) — Handle for the IPC namespace of the process./proc/[pid]/ns/mnt (since Linux 3.8) — Handle for the mount namespace of the process./proc/[pid]/ns/net (since Linux 3.0) — Handle for the network namespace of the process./proc/[pid]/ns/pid (since Linux 3.8) — Handle for the PID namespace of the process. This handle is permanent for the lifetime of the process (i.e., a process's PID namespace membership never changes)./proc/[pid]/ns/pid_for_children (since Linux 4.12) — Handle for the PID namespace of child processes created by this process. This can change as a consequence of calls to unshare(2) and setns(2) (see pid_namespaces(7)), so the file may differ from /proc/[pid]/ns/pid. The symbolic link gains a value only after the first child process is created in the namespace. (Beforehand, readlink(2) of the symbolic link will return an empty buffer.)/proc/[pid]/ns/time (since Linux 5.6) — Handle for the time namespace of the process./proc/[pid]/ns/time_for_children (since Linux 5.6) — Handle for the time namespace of child processes created by this process. This can change as a consequence of calls to unshare(2) and setns(2) (see time_namespaces(7)), so the file may differ from /proc/[pid]/ns/time./proc/[pid]/ns/user (since Linux 3.8) — Handle for the user namespace of the process./proc/[pid]/ns/uts (since Linux 3.0) — Handle for the UTS namespace of the process.Permission to dereference or read (readlink(2)) these symbolic links is governed by a ptrace access mode PTRACE_MODE_READ_FSCREDS check; see ptrace(2).
The files in the /proc/sys/user directory (present since Linux 4.9) expose limits on the number of namespaces of various types that can be created. The files are as follows:
max_cgroup_namespaces — Per-user limit on the number of cgroup namespaces that may be created in the user namespace.max_ipc_namespaces — Per-user limit on the number of IPC namespaces.max_mnt_namespaces — Per-user limit on the number of mount namespaces.max_net_namespaces — Per-user limit on the number of network namespaces.max_pid_namespaces — Per-user limit on the number of PID namespaces.max_time_namespaces (since Linux 5.7) — Per-user limit on the number of time namespaces.max_user_namespaces — Per-user limit on the number of user namespaces.max_uts_namespaces — Per-user limit on the number of UTS namespaces.Note the following details about these files:
ENOSPC./proc/sys/kernel/threads-max). In all descendant user namespaces, the default value in each file is MAXINT.Absent any other factors, a namespace is automatically torn down when the last process in the namespace terminates or leaves the namespace. However, there are a number of other factors that may pin a namespace into existence even though it has no member processes. These factors include the following:
/proc/[pid]/ns/* file./proc/[pid]/ns/pid_for_children symbolic link./proc/[pid]/ns/time_for_children symbolic link.mqueue filesystem (see mq_overview(7)) refers to this namespace.See clone(2) and user_namespaces(7).
nsenter(1), readlink(1), unshare(1), clone(2), ioctl_ns(2), setns(2), unshare(2), proc(5), capabilities(7), cgroup_namespaces(7), cgroups(7), credentials(7), ipc_namespaces(7), network_namespaces(7), pid_namespaces(7), time_namespaces(7), user_namespaces(7), uts_namespaces(7), lsns(8), pam_namespace(8), switch_root(8)
This page is part of release 5.10 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/.
Generated by phpman v4.9.26-1-g511901d · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-08-04 07:19 @216.73.216.183
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format