Section: Linux Programmer's Manual (7)
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.
Linux provides the following namespaces:
<TABLE> <TR VALIGN="top| <TD CLASS="c1|Namespace</TD> <TD CLASS="c1|Constant</TD> <TD>Isolates
</TD> </TR> <TR VALIGN="top| <TD>IPC</TD> <TD CLASS="c1|CLONE_NEWIPC</TD> <TD>System V IPC, POSIX message queues
</TD> </TR> <TR VALIGN="top| <TD>Network</TD> <TD CLASS="c1|CLONE_NEWNET</TD> <TD>Network devices, stacks, ports, etc.
</TD> </TR> <TR VALIGN="top| <TD>Mount</TD> <TD CLASS="c1|CLONE_NEWNS</TD> <TD>Mount points
</TD> </TR> <TR VALIGN="top| <TD>PID</TD> <TD CLASS="c1|CLONE_NEWPID</TD> <TD>Process IDs
</TD> </TR> <TR VALIGN="top| <TD>User</TD> <TD CLASS="c1|CLONE_NEWUSER</TD> <TD>User and group IDs
</TD> </TR> <TR VALIGN="top| <TD>UTS</TD> <TD CLASS="c1|CLONE_NEWUTS</TD> <TD>Hostname and NIS domain name
</TD> </TR> </TABLE>
As well as various /proc files described below, the namespaces API includes the following system calls:
Creation of new namespaces using clone?(2) and unshare?(2) in most cases requires the CAP_SYS_ADMIN capability. User namespaces are the exception: since Linux 3.8, no privilege is required to create a user namespace.
$ ls -l /proc/$$/ns total 0 lrwxrwxrwx. 1 mtk mtk 0 Jan 14 01:20 ipc -> ipc: lrwxrwxrwx. 1 mtk mtk 0 Jan 14 01:20 mnt -> mnt: lrwxrwxrwx. 1 mtk mtk 0 Jan 14 01:20 net -> net: lrwxrwxrwx. 1 mtk mtk 0 Jan 14 01:20 pid -> pid: lrwxrwxrwx. 1 mtk mtk 0 Jan 14 01:20 user -> user: lrwxrwxrwx. 1 mtk mtk 0 Jan 14 01:20 uts -> uts:
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 inode numbers of their /proc/[pid]/ns/xxx symbolic links will be the same; an application can check this using the stat.st_ino field 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:
The files in this subdirectory are as follows:
IPC namespaces isolate certain IPC resources, namely, System V IPC objects (see svipc?(7)) and (since Linux 2.6.30) POSIX message queues (see mq_overview?(7). The common characteristic of these IPC mechanisms is that IPC objects are identified by mechanisms other than filesystem pathnames.
Each IPC namespace has its own set of System V IPC identifiers and its own POSIX message queue filesystem. Objects created in an IPC namespace are visible to all other processes that are members of that namespace, but are not visible to processes in other IPC namespaces.
The following /proc interfaces are distinct in each IPC namespace:
When an IPC namespace is destroyed (i.e., when the last process that is a member of the namespace terminates), all IPC objects in the namespace are automatically destroyed.
Network namespaces provide isolation of the system resources associated with networking: network devices, IPv4 and IPv6 protocol stacks, IP routing tables, firewalls, the /proc/net directory, the /sys/class/net directory, port numbers (sockets), and so on. A physical network device can live in exactly one network namespace. A virtual network device ("veth") pair provides a pipe-like abstraction that can be used to create tunnels between network namespaces, and can be used to create a bridge to a physical network device in another namespace.
When a network namespace is freed (i.e., when the last process in the namespace terminates), its physical network devices are moved back to the initial network namespace (not to the parent of the process).
Mount namespaces isolate the set of filesystem mount points, meaning that processes in different mount namespaces can have different views of the filesystem hierarchy. The set of mounts in a mount namespace is modified using mount?(2) and umount?(2).
The /proc/[pid]/mounts file (present since Linux 2.4.19) lists all the filesystems currently mounted in the process's mount namespace. The format of this file is documented in fstab?(5). Since kernel version 2.6.15, this file is pollable: after opening the file for reading, a change in this file (i.e., a filesystem mount or unmount) causes select?(2) to mark the file descriptor as readable, and poll?(2) and epoll_wait?(2) mark the file as having an error condition.
The /proc/[pid]/mountstats file (present since Linux 2.6.17) exports information (statistics, configuration information) about the mount points in the process's mount namespace. This file is only readable by the owner of the process. Lines in this file have the form::
device /dev/sda7 mounted on /home with fstype ext3 [statistics] ( 1 ) ( 2 ) (3 ) (4)
The fields in each line are:
UTS namespaces provide isolation of two system identifiers: the hostname and the NIS domain name. These identifiers are set using sethostname?(2) and setdomainname?(2), and can be retrieved using uname?(2), gethostname?(2), and getdomainname?(2).
This page is part of release 3.74 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 http://www.kernel.org/doc/man-pages/.
Tutoriais de Tecnologia Web