Skip to content

Instantly share code, notes, and snippets.

@Lupul
Last active August 29, 2015 14:01
Show Gist options
  • Save Lupul/4232003a8565d3832ab7 to your computer and use it in GitHub Desktop.
Save Lupul/4232003a8565d3832ab7 to your computer and use it in GitHub Desktop.
#!/bin/bash
BRIDGE=br-test
VLAN_IF=eth1.53
# remove ports from bridge
brctl delif $BRIDGE $VLAN_IF
brctl delif $BRIDGE br-tap1
brctl delif $BRIDGE br-tap2
ifconfig $BRIDGE down
brctl delbr $BRIDGE
ip netns exec ns1 ip link delete tap1 type veth
ip netns exec ns2 ip link delete tap2 type veth
ip netns delete ns1
ip netns delete ns2
echo "done cleaning up"
# exit 0
# add the namespaces
ip netns add ns1
ip netns add ns2
# create the switch
brctl addbr $BRIDGE
brctl stp $BRIDGE off
ip link set dev $BRIDGE up
brctl addif br-test $VLAN_IF
#
#### PORT 1
# create a port pair
ip link add tap1 type veth peer name br-tap1
# attach one side to linuxbridge
brctl addif br-test br-tap1
# attach the other side to namespace
ip link set tap1 netns ns1
# set the ports to up
# ip netns exec ns1 ip link set dev tap1 up
ip netns exec ns1 ifconfig tap1 192.168.53.250/24 up
ip link set dev br-tap1 up
#
#### PORT 2
# create a port pair
ip link add tap2 type veth peer name br-tap2
# attach one side to linuxbridge
brctl addif br-test br-tap2
# attach the other side to namespace
ip link set tap2 netns ns2
# set the ports to up
# ip netns exec ns2 ip link set dev tap2 up
ip netns exec ns2 ifconfig tap2 192.168.53.251/24 up
ip link set dev br-tap2 up
[OK] ip netns exec ns2 ping 192.168.53.250
[OK] ip netns exec ns1 ping 192.168.53.251
[OK] arping -I br-test 192.168.53.254 # oK with or without IpAddr configured on br-test
[X] ip netns exec ns1 ping 192.168.53.254
[X] ip netns exec ns2 ping 192.168.53.254
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment