# 添加 ip link add br0 type bridge # 并且up ip link set dev br0 up
创建veth
创建 veth,并且一端加入ns,一端连接 bridge
首先和之前一样创建veth,假设已经创建了两对
1 2
veth0@veth1 veth2@veth3
绑定
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# 把设备 veth0 加入到 br0 ip link set dev veth0 master br0 ip link set dev veth1 netns net0 ip link set dev veth2 master br0 ip link set dev veth3 netns net1
ip netns exec net0 ip link set dev veth1 name eth0 ip netns exec net0 ip addr add 192.168.1.2/24 dev eth0
ip netns exec net1 ip link set dev veth3 name eth0 ip netns exec net1 ip addr add 192.168.1.3/24 dev eth0
ip link set dev veth0 up ip link set dev veth2 up
ip netns exec net0 ip link set dev eth0 up ip netns exec net1 ip link set dev eth0 up