引用:
理解Docker容器网络之Linux Network Namespace
9.5. ETHERNET BRIDGE CONFIGURATION USING IPROUTE
sudo ip netns add c_ns1
sudo ip netns add c_ns2
sudo ip netns
sudo ls /var/run/netns
sudo ip netns exec c_ns1 ip a
sudo ip netns exec c_ns2 ip a
sudo ip netns exec c_ns1 ip route
sudo ip netns exec c_ns2 ip route
sudo ip link add c_br0 type bridge
sudo ip addr add 88.88.88.81/24 dev c_br0
sudo ip link set c_br0 up
sudo ip route
sudo ip link add c_br0_port1 type veth peer name c_ns1_nic1
sudo ip link add c_br0_port2 type veth peer name c_ns2_nic1
sudo ip link set c_br0_port1 type bridge_slave
sudo ip link set c_br0_port1 master c_br0
sudo ip link set c_br0_port1 up
sudo ip link set c_br0_port2 type bridge_slave
sudo ip link set c_br0_port2 master c_br0
sudo ip link set c_ns1_nic1 netns c_ns1
sudo ip link set c_ns2_nic1 netns c_ns2
sudo ip netns exec c_ns1 ip a
sudo ip netns exec c_ns2 ip a
sudo ip netns exec c_ns1 ip link set c_ns1_nic1 name ETH0
sudo ip netns exec c_ns1 ip a
sudo ip netns exec c_ns2 ip link set c_ns2_nic1 name ETH0
sudo ip netns exec c_ns2 ip a
sudo ip netns exec c_ns1 ip route
sudo ip netns exec c_ns2 ip route
sudo ip netns exec c_ns1 ip addr add 88.88.88.11/24 dev ETH0
sudo ip netns exec c_ns1 ip link set ETH0 up
sudo ip netns exec c_ns2 ip addr add 88.88.88.12/24 dev ETH0
sudo ip netns exec c_ns2 ip link set ETH0 up
sudo ip netns exec c_ns1 ip route
sudo ip netns exec c_ns2 ip route
sudo ip netns exec c_ns1 ip route add default via 88.88.88.81
sudo ip netns exec c_ns1 ip route
sudo ip netns delete c_ns1
sudo ip netns delete c_ns2
sudo ip link delete c_br0