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