1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| yum install -y bridge-utils
brctl addbr br0
ip link set br0 up
ip netns add ns0 ip netns add ns1 ip netns add ns2
ip link add veth0-ns type veth peer name veth0-br ip link add veth1-ns type veth peer name veth1-br ip link add veth2-ns type veth peer name veth2-br
ip link set veth0-ns netns ns0 ip link set veth1-ns netns ns1 ip link set veth2-ns netns ns2
ip netns exec ns0 ip link set lo up ip netns exec ns0 ip link set veth0-ns up ip netns exec ns0 ip addr add 10.0.0.1/24 dev veth0-ns
ip netns exec ns1 ip link set lo up ip netns exec ns1 ip link set veth1-ns up ip netns exec ns1 ip addr add 10.0.0.2/24 dev veth1-ns
ip netns exec ns2 ip link set lo up ip netns exec ns2 ip link set veth2-ns up ip netns exec ns2 ip addr add 10.0.0.3/24 dev veth2-ns
ip netns exec ns0 ip a ip netns exec ns1 ip a ip netns exec ns2 ip a
ip netns exec ns0 route -n ip netns exec ns1 route -n ip netns exec ns2 route -n
ip link set veth0-br up ip link set veth1-br up ip link set veth2-br up brctl addif br0 veth0-br brctl addif br0 veth1-br brctl addif br0 veth2-br
brctl show
iptables -A FORWARD -i br0 -j ACCEPT
ip netns exec ns0 ping 10.0.0.1 ip netns exec ns0 ping 10.0.0.2 ip netns exec ns0 ping 10.0.0.3
|