1IP-NETNS(8)                          Linux                         IP-NETNS(8)
2
3
4

NAME

6       ip-netns - process network namespace management
7

SYNOPSIS

9       ip [ OPTIONS ] netns  { COMMAND | help }
10
11       ip netns [ list ]
12
13       ip netns add NETNSNAME
14
15       ip netns attach NETNSNAME PID
16
17       ip [-all] netns del [ NETNSNAME ]
18
19       ip netns set NETNSNAME NETNSID
20
21       NETNSID := auto | POSITIVE-INT
22
23       ip netns identify [ PID ]
24
25       ip netns pids NETNSNAME
26
27       ip [-all] netns exec [ NETNSNAME ] command...
28
29       ip netns monitor
30
31       ip netns list-id [ target-nsid POSITIVE-INT ] [ nsid POSITIVE-INT ]
32
33

DESCRIPTION

35       A network namespace is logically another copy of the network stack,
36       with its own routes, firewall rules, and network devices.
37
38       By default a process inherits its network namespace from its parent.
39       Initially all the processes share the same default network namespace
40       from the init process.
41
42       By convention a named network namespace is an object at
43       /var/run/netns/NAME that can be opened. The file descriptor resulting
44       from opening /var/run/netns/NAME refers to the specified network names‐
45       pace. Holding that file descriptor open keeps the network namespace
46       alive. The file descriptor can be used with the setns(2) system call to
47       change the network namespace associated with a task.
48
49       For applications that are aware of network namespaces, the convention
50       is to look for global network configuration files first in
51       /etc/netns/NAME/ then in /etc/.  For example, if you want a different
52       version of /etc/resolv.conf for a network namespace used to isolate
53       your vpn you would name it /etc/netns/myvpn/resolv.conf.
54
55       ip netns exec automates handling of this configuration, file convention
56       for network namespace unaware applications, by creating a mount names‐
57       pace and bind mounting all of the per network namespace configure files
58       into their traditional location in /etc.
59
60
61       ip netns list - show all of the named network namespaces
62
63              This command displays all of the network namespaces in
64              /var/run/netns
65
66
67       ip netns add NAME - create a new named network namespace
68
69              If NAME is available in /var/run/netns/ this command creates a
70              new network namespace and assigns NAME.
71
72
73       ip netns attach NAME PID - create a new named network namespace
74
75              If NAME is available in /var/run/netns/ this command attaches
76              the network namespace of the process PID to NAME as if it were
77              created with ip netns.
78
79
80       ip [-all] netns delete [ NAME ] - delete the name of a network names‐
81       pace(s)
82
83              If NAME is present in /var/run/netns it is umounted and the
84              mount point is removed. If this is the last user of the network
85              namespace the network namespace will be freed and all physical
86              devices will be moved to the default one, otherwise the network
87              namespace persists until it has no more users. ip netns delete
88              may fail if the mount point is in use in another mount names‐
89              pace.
90
91              If -all option was specified then all the network namespace
92              names will be removed.
93
94              It is possible to lose the physical device when it was moved to
95              netns and then this netns was deleted with a running process:
96
97                 $ ip netns add net0
98                 $ ip link set dev eth0 netns net0
99                 $ ip netns exec net0 SOME_PROCESS_IN_BACKGROUND
100                 $ ip netns del net0
101
102              and eth0 will appear in the default netns only after
103              SOME_PROCESS_IN_BACKGROUND will exit or will be killed. To pre‐
104              vent this the processes running in net0 should be killed before
105              deleting the netns:
106
107                 $ ip netns pids net0 | xargs kill
108                 $ ip netns del net0
109
110
111       ip netns set NAME NETNSID - assign an id to a peer network namespace
112
113              This command assigns a id to a peer network namespace. This id
114              is valid only in the current network namespace.  If the keyword
115              "auto" is specified an available nsid will be chosen.  This id
116              will be used by the kernel in some netlink messages. If no id is
117              assigned when the kernel needs it, it will be automatically
118              assigned by the kernel.  Once it is assigned, it's not possible
119              to change it.
120
121
122       ip netns identify [PID] - Report network namespaces names for process
123
124              This command walks through /var/run/netns and finds all the net‐
125              work namespace names for network namespace of the specified
126              process, if PID is not specified then the current process will
127              be used.
128
129
130       ip netns pids NAME - Report processes in the named network namespace
131
132              This command walks through proc and finds all of the process who
133              have the named network namespace as their primary network names‐
134              pace.
135
136
137       ip [-all] netns exec [ NAME ] cmd ... - Run cmd in the named network
138       namespace
139
140              This command allows applications that are network namespace
141              unaware to be run in something other than the default network
142              namespace with all of the configuration for the specified net‐
143              work namespace appearing in the customary global locations. A
144              network namespace and bind mounts are used to move files from
145              their network namespace specific location to their default loca‐
146              tions without affecting other processes.
147
148              If -all option was specified then cmd will be executed syn‐
149              chronously on the each named network namespace even if cmd fails
150              on some of them. Network namespace name is printed on each cmd
151              executing.
152
153
154       ip netns monitor - Report as network namespace names are added and
155       deleted
156
157              This command watches network namespace name addition and dele‐
158              tion events and prints a line for each event it sees.
159
160
161       ip netns list-id [target-nsid POSITIVE-INT] [nsid POSITIVE-INT] - list
162       network namespace ids (nsid)
163
164              Network namespace ids are used to identify a peer network names‐
165              pace. This command displays nsids of the current network names‐
166              pace and provides the corresponding iproute2 netns name (from
167              /var/run/netns) if any.
168
169              The target-nsid option enables to display nsids of the specified
170              network namespace instead of the current network namespace. This
171              target-nsid is a nsid from the current network namespace.
172
173              The nsid option enables to display only this nsid. It is a nsid
174              from the current network namespace. In combination with the tar‐
175              get-nsid option, it enables to convert a specific nsid from the
176              current network namespace to a nsid of the target-nsid network
177              namespace.
178
179

EXAMPLES

181       ip netns list
182              Shows the list of current named network namespaces
183
184       ip netns add vpn
185              Creates a network namespace and names it vpn
186
187       ip netns exec vpn ip link set lo up
188              Bring up the loopback interface in the vpn network namespace.
189
190       ip netns add foo
191       ip netns add bar
192       ip netns set foo 12
193       ip netns set bar 13
194       ip -n foo netns set foo 22
195       ip -n foo netns set bar 23
196       ip -n bar netns set foo 32
197       ip -n bar netns set bar 33
198       ip netns list-id target-nsid 12
199              Shows the list of nsids from the network namespace foo.
200       ip netns list-id target-nsid 12 nsid 13
201              Get nsid of bar from the network namespace foo (result is 23).
202
203

SEE ALSO

205       ip(8)
206
207

AUTHOR

209       Original Manpage by Eric W. Biederman
210       Manpage revised by Nicolas Dichtel <nicolas.dichtel@6wind.com>
211
212
213
214iproute2                          16 Jan 2013                      IP-NETNS(8)
Impressum