logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

ip-netns.8 (7254B)


  1. .TH IP\-NETNS 8 "16 Jan 2013" "iproute2" "Linux"
  2. .SH NAME
  3. ip-netns \- process network namespace management
  4. .SH SYNOPSIS
  5. .sp
  6. .ad l
  7. .in +8
  8. .ti -8
  9. .B ip
  10. .RI "[ " OPTIONS " ]"
  11. .B netns
  12. .RI " { " COMMAND " | "
  13. .BR help " }"
  14. .sp
  15. .ti -8
  16. .BR "ip netns" " [ " list " ]"
  17. .ti -8
  18. .B ip netns add
  19. .I NETNSNAME
  20. .ti -8
  21. .B ip netns attach
  22. .I NETNSNAME PID
  23. .ti -8
  24. .B ip [-all] netns del
  25. .RI "[ " NETNSNAME " ]"
  26. .ti -8
  27. .B ip netns set
  28. .I NETNSNAME NETNSID
  29. .ti -8
  30. .IR NETNSID " := " auto " | " POSITIVE-INT
  31. .ti -8
  32. .BR "ip netns identify"
  33. .RI "[ " PID " ]"
  34. .ti -8
  35. .BR "ip netns pids"
  36. .I NETNSNAME
  37. .ti -8
  38. .BR "ip [-all] netns exec "
  39. .RI "[ " NETNSNAME " ] " command ...
  40. .ti -8
  41. .BR "ip netns monitor"
  42. .ti -8
  43. .BR "ip netns list-id"
  44. .RI "[ target-nsid " POSITIVE-INT " ] [ nsid " POSITIVE-INT " ]"
  45. .SH DESCRIPTION
  46. A network namespace is logically another copy of the network stack,
  47. with its own routes, firewall rules, and network devices.
  48. By default a process inherits its network namespace from its parent. Initially all
  49. the processes share the same default network namespace from the init process.
  50. By convention a named network namespace is an object at
  51. .BR "/run/netns/" NAME
  52. that can be opened. The file descriptor resulting from opening
  53. .BR "/run/netns/" NAME
  54. refers to the specified network namespace. Holding that file
  55. descriptor open keeps the network namespace alive. The file
  56. descriptor can be used with the
  57. .B setns(2)
  58. system call to change the network namespace associated with a task.
  59. For applications that are aware of network namespaces, the convention
  60. is to look for global network configuration files first in
  61. .BR "/etc/netns/" NAME "/"
  62. then in
  63. .BR "/etc/".
  64. For example, if you want a different version of
  65. .BR /etc/resolv.conf
  66. for a network namespace used to isolate your vpn you would name it
  67. .BR /etc/netns/myvpn/resolv.conf.
  68. .B ip netns exec
  69. automates handling of this configuration, file convention for network
  70. namespace unaware applications, by creating a mount namespace and
  71. bind mounting all of the per network namespace configure files into
  72. their traditional location in /etc.
  73. .TP
  74. .B ip netns list - show all of the named network namespaces
  75. .sp
  76. This command displays all of the network namespaces in /run/netns
  77. .TP
  78. .B ip netns add NAME - create a new named network namespace
  79. .sp
  80. If NAME is available in /run/netns this command creates a new
  81. network namespace and assigns NAME.
  82. .TP
  83. .B ip netns attach NAME PID - create a new named network namespace
  84. .sp
  85. If NAME is available in /run/netns this command attaches the network
  86. namespace of the process PID to NAME as if it were created with ip netns.
  87. .TP
  88. .B ip [-all] netns delete [ NAME ] - delete the name of a network namespace(s)
  89. .sp
  90. If NAME is present in /run/netns it is umounted and the mount
  91. point is removed. If this is the last user of the network namespace the
  92. network namespace will be freed and all physical devices will be moved to the
  93. default one, otherwise the network namespace persists until it has no more
  94. users. ip netns delete may fail if the mount point is in use in another mount
  95. namespace.
  96. If
  97. .B -all
  98. option was specified then all the network namespace names will be removed.
  99. It is possible to lose the physical device when it was moved to netns and
  100. then this netns was deleted with a running process:
  101. .RS 10
  102. $ ip netns add net0
  103. .RE
  104. .RS 10
  105. $ ip link set dev eth0 netns net0
  106. .RE
  107. .RS 10
  108. $ ip netns exec net0 SOME_PROCESS_IN_BACKGROUND
  109. .RE
  110. .RS 10
  111. $ ip netns del net0
  112. .RE
  113. .RS
  114. and eth0 will appear in the default netns only after SOME_PROCESS_IN_BACKGROUND
  115. will exit or will be killed. To prevent this the processes running in net0
  116. should be killed before deleting the netns:
  117. .RE
  118. .RS 10
  119. $ ip netns pids net0 | xargs kill
  120. .RE
  121. .RS 10
  122. $ ip netns del net0
  123. .RE
  124. .TP
  125. .B ip netns set NAME NETNSID - assign an id to a peer network namespace
  126. .sp
  127. This command assigns a id to a peer network namespace. This id is valid
  128. only in the current network namespace.
  129. If the keyword "auto" is specified an available nsid will be chosen.
  130. This id will be used by the kernel in some netlink messages. If no id is
  131. assigned when the kernel needs it, it will be automatically assigned by
  132. the kernel.
  133. Once it is assigned, it's not possible to change it.
  134. .TP
  135. .B ip netns identify [PID] - Report network namespaces names for process
  136. .sp
  137. This command walks through /run/netns and finds all the network
  138. namespace names for network namespace of the specified process, if PID is
  139. not specified then the current process will be used.
  140. .TP
  141. .B ip netns pids NAME - Report processes in the named network namespace
  142. .sp
  143. This command walks through proc and finds all of the process who have
  144. the named network namespace as their primary network namespace.
  145. .TP
  146. .B ip [-all] netns exec [ NAME ] cmd ... - Run cmd in the named network namespace
  147. .sp
  148. This command allows applications that are network namespace unaware
  149. to be run in something other than the default network namespace with
  150. all of the configuration for the specified network namespace appearing
  151. in the customary global locations. A network namespace and bind mounts
  152. are used to move files from their network namespace specific location
  153. to their default locations without affecting other processes.
  154. If
  155. .B -all
  156. option was specified then
  157. .B cmd
  158. will be executed synchronously on the each named network namespace even if
  159. .B cmd
  160. fails on some of them. Network namespace name is printed on each
  161. .B cmd
  162. executing.
  163. .TP
  164. .B ip netns monitor - Report as network namespace names are added and deleted
  165. .sp
  166. This command watches network namespace name addition and deletion events
  167. and prints a line for each event it sees.
  168. .TP
  169. .B ip netns list-id [target-nsid POSITIVE-INT] [nsid POSITIVE-INT] - list network namespace ids (nsid)
  170. .sp
  171. Network namespace ids are used to identify a peer network namespace. This
  172. command displays nsids of the current network namespace and provides the
  173. corresponding iproute2 netns name (from /run/netns) if any.
  174. The
  175. .B target-nsid
  176. option enables to display nsids of the specified network namespace instead of the current network
  177. namespace. This
  178. .B target-nsid
  179. is a nsid from the current network namespace.
  180. The
  181. .B nsid
  182. option enables to display only this nsid. It is a nsid from the current network namespace. In
  183. combination with the
  184. .B target-nsid
  185. option, it enables to convert a specific nsid from the current network namespace to a nsid of the
  186. .B target-nsid
  187. network namespace.
  188. .SH EXAMPLES
  189. .PP
  190. ip netns list
  191. .RS
  192. Shows the list of current named network namespaces
  193. .RE
  194. .PP
  195. ip netns add vpn
  196. .RS
  197. Creates a network namespace and names it vpn
  198. .RE
  199. .PP
  200. ip netns exec vpn ip link set lo up
  201. .RS
  202. Bring up the loopback interface in the vpn network namespace.
  203. .RE
  204. .PP
  205. ip netns add foo
  206. .br
  207. ip netns add bar
  208. .br
  209. ip netns set foo 12
  210. .br
  211. ip netns set bar 13
  212. .br
  213. ip -n foo netns set foo 22
  214. .br
  215. ip -n foo netns set bar 23
  216. .br
  217. ip -n bar netns set foo 32
  218. .br
  219. ip -n bar netns set bar 33
  220. .br
  221. ip netns list-id target-nsid 12
  222. .RS
  223. Shows the list of nsids from the network namespace foo.
  224. .RE
  225. ip netns list-id target-nsid 12 nsid 13
  226. .RS
  227. Get nsid of bar from the network namespace foo (result is 23).
  228. .RE
  229. .SH SEE ALSO
  230. .br
  231. .BR ip (8)
  232. .SH AUTHOR
  233. Original Manpage by Eric W. Biederman
  234. .br
  235. Manpage revised by Nicolas Dichtel <nicolas.dichtel@6wind.com>