![在 Linux 上建立新的網路命名空間](https://rvso.com/image/1316154/%E5%9C%A8%20Linux%20%E4%B8%8A%E5%BB%BA%E7%AB%8B%E6%96%B0%E7%9A%84%E7%B6%B2%E8%B7%AF%E5%91%BD%E5%90%8D%E7%A9%BA%E9%96%93.png)
我想在 Linux 上建立一個新的網路命名空間。
http://www.spinics.net/lists/linux-containers/msg10895.html告訴我可以透過執行以下命令將 shell 附加到 ID X 的現有命名空間:
$ chnetns X /bin/sh
如果命名空間已經存在,則效果很好,但如果我嘗試使用不存在的命名空間,則會得到以下結果:
$ chnetns 100 /bin/sh
setsocketopt: Invalid argument
如何建立命名空間?我使用的是 Red Hat Linux V6.1。
答案1
答案是「ip netns add vnet1」。
ip netns list
ip netns add vnet1
也可以看看Linux虛擬網路簡介:blog.scottlowe.org:Linux 網路命名空間簡介,opencloudblog.com:Linux 網路命名空間閃亮且更美麗和opencloudblog.com:Linux 網路命名空間閃亮且更詳細,帶有漂亮的圖表
指向其他參考的鏈接,可幫助其他人開始使用虛擬網路命名空間。另請參閱關於網路命名空間的 LWN 文章,開放式堆疊網路範例,ip路由2,Linux VRF 補丁集Linux 的虛擬路由與轉發,以及OpenStack 網路概念。
NAME
ip-netns - process network namespace management
SYNOPSIS
ip [ OPTIONS ] netns { COMMAND | help }
ip netns { list }
ip netns { add | delete } NETNSNAME
ip netns identify PID
ip netns pids NETNSNAME
ip netns exec NETNSNAME command ...
ip netns monitor