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. If the keyword
104 "auto" is specified an available nsid will be chosen. This id
105 will be used by the kernel in some netlink messages. If no id is
106 assigned when the kernel needs it, it will be automatically
107 assigned by the kernel. Once it is assigned, it's not possible
108 to change it.
109
110
111 ip netns identify [PID] - Report network namespaces names for process
112
113 This command walks through /var/run/netns and finds all the net‐
114 work namespace names for network namespace of the specified
115 process, if PID is not specified then the current process will
116 be used.
117
118
119 ip netns pids NAME - Report processes in the named network namespace
120
121 This command walks through proc and finds all of the process who
122 have the named network namespace as their primary network names‐
123 pace.
124
125
126 ip [-all] netns exec [ NAME ] cmd ... - Run cmd in the named network
127 namespace
128
129 This command allows applications that are network namespace
130 unaware to be run in something other than the default network
131 namespace with all of the configuration for the specified net‐
132 work namespace appearing in the customary global locations. A
133 network namespace and bind mounts are used to move files from
134 their network namespace specific location to their default loca‐
135 tions without affecting other processes.
136
137 If -all option was specified then cmd will be executed syn‐
138 chronously on the each named network namespace even if cmd fails
139 on some of them. Network namespace name is printed on each cmd
140 executing.
141
142
143 ip netns monitor - Report as network namespace names are added and
144 deleted
145
146 This command watches network namespace name addition and dele‐
147 tion events and prints a line for each event it sees.
148
149
150 ip netns list-id - list network namespace ids (nsid)
151
152 Network namespace ids are used to identify a peer network names‐
153 pace. This command displays nsid of the current network names‐
154 pace and provides the corresponding iproute2 netns name (from
155 /var/run/netns) if any.
156
157
159 ip netns list
160 Shows the list of current named network namespaces
161
162 ip netns add vpn
163 Creates a network namespace and names it vpn
164
165 ip netns exec vpn ip link set lo up
166 Bring up the loopback interface in the vpn network namespace.
167
168
170 ip(8)
171
172
174 Original Manpage by Eric W. Biederman
175
176
177
178iproute2 16 Jan 2013 IP-NETNS(8)