範例
使用
ip創建H1和H2兩個Network namespace- H1擁有自己的Network namespace以及私有網路網路接口
h1-eth0 - H2擁有自己的Network namespace以及私有網路網路接口
h2-eth0
- H1擁有自己的Network namespace以及私有網路網路接口
使用
ovs-vsctl創建Software Switch S1- S1有兩個埠
s1-eth0和s1-eth1 - S1運行在
root namespace,並使用實體接口eth0,等待Controller的指令 - 使用
veth pair與對應的Host接口相連,這樣H1和H2就可以透過S1溝通 s1-eth0和s1-eth1間的通訊資料透過Software Switch轉發
- S1有兩個埠

ip netns add <NetNS 名稱>- 新增NetNSip netns list- 列出現有的NetNSip netns identify <PID>- 顯示PID所在的NetNSip netns identify $$- 顯示目前的NetNSip netns exec <NetNS 名稱> <command>- 在Network namespace執行commandip link add <veth 名稱> type veth peer name <veth 另一端的名稱>- 建立一個veth裝置ip link set <veth 名稱> nets <NetNS 名稱>- 將veth搬到NetNS
- 將H1 port移到H1 namespaces
sudo ip link set h1-eth0 netns h1
- 將H2 port接到H2 namespaces
sudo ip link set h2-eth0 netns h2
- 顯示H1 namespaces的連結
sudo ip netns exec h1 ip link show
- 顯示H2 namespaces的連結
sudo ip netns exec h2 ip link show


- 修改H1 port網路介面,給予H1 eth0一個
10.0.0.1的參數sudo ip netns exec h1 ifconfig h1-eth0 10.1
- 啟動H1 eth0網路介面
sudo ip netns exec h1 ifconfig lo up
- 修改H2 port網路介面,給予H2 eth0一個
10.0.0.2的參數sudo ip netns exec h2 ifconfig h2-eth0 10.2
- 啟動H2 eth0網路介面
sudo ip netns exec h2 ifconfig lo up
- 啟動Switch網路介面
sudo ifconfig s1-eth1 upsudo ifconfig s1-eth2 up







