Jan 4, 2017

6. Demo: VLANs inside a Linux machine

Leave a Comment

Topology


Expected result
PC1 & PC2 are on the same VLAN, they can communicate each other
PC1 & PC3 are on different VLANs, thay CANNOT see each other

Configuration

sudo ip netns add pc1
sudo ip netns add pc2
sudo ip netns add pc3
sudo ip netns add pc4
sudo brctl addbr vSwitch
sudo ip link add eth1 type veth peer name eth5
sudo ip link add eth2 type veth peer name eth6
sudo ip link add eth3 type veth peer name eth7
sudo ip link add eth4 type veth peer name eth8
  
sudo ip link set eth1 netns pc1
sudo ip link set eth2 netns pc2
sudo ip link set eth3 netns pc3
sudo ip link set eth4 netns pc4
sudo brctl addif vSwitch eth5
sudo brctl addif vSwitch eth6
sudo brctl addif vSwitch eth7
sudo brctl addif vSwitch eth8
  
sudo ip netns exec pc1 ip link add link eth1 name vlan type vlan id 10
sudo ip netns exec pc2 ip link add link eth2 name vlan type vlan id 10
sudo ip netns exec pc3 ip link add link eth3 name vlan type vlan id 20
sudo ip netns exec pc4 ip link add link eth4 name vlan type vlan id 20
  
sudo ip netns exec pc1 ip addr add 10.0.0.1/24 dev vlan
sudo ip netns exec pc2 ip addr add 10.0.0.2/24 dev vlan
sudo ip netns exec pc3 ip addr add 10.0.0.3/24 dev vlan
sudo ip netns exec pc4 ip addr add 10.0.0.4/24 dev vlan
  
sudo ip netns exec pc1 ip link set eth1 up
sudo ip netns exec pc2 ip link set eth2 up
sudo ip netns exec pc3 ip link set eth3 up
sudo ip netns exec pc4 ip link set eth4 up
sudo ip link set vSwitch up
sudo ip link set eth5 up
sudo ip link set eth6 up
sudo ip link set eth7 up
sudo ip link set eth8 up
  
sudo ip netns exec pc1 ip link set vlan up
sudo ip netns exec pc2 ip link set vlan up
sudo ip netns exec pc3 ip link set vlan up
sudo ip netns exec pc4 ip link set vlan up
  
sudo ip netns exec pc1 ping 10.0.0.2
sudo ip netns exec pc1 ping 10.0.0.3
sudo ip netns exec pc1 ping 10.0.0.4
 
sudo ip netns exec pc4 ping 10.0.0.1
sudo ip netns exec pc4 ping 10.0.0.2
sudo ip netns exec pc4 ping 10.0.0.3

Result

vdkmai@Ubuntu32bit:~$ sudo ip netns exec pc1 ping 10.0.0.2
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
64 bytes from 10.0.0.2: icmp_req=1 ttl=64 time=0.040 ms
64 bytes from 10.0.0.2: icmp_req=2 ttl=64 time=0.066 ms
^C
--- 10.0.0.2 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.040/0.053/0.066/0.013 ms
vdkmai@Ubuntu32bit:~$ sudo ip netns exec pc1 ping 10.0.0.3
PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.
^C
--- 10.0.0.3 ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1009ms
vdkmai@Ubuntu32bit:~$ sudo ip netns exec pc1 ping 10.0.0.4
PING 10.0.0.4 (10.0.0.4) 56(84) bytes of data.
^C
--- 10.0.0.4 ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1008ms
vdkmai@Ubuntu32bit:~$ sudo ip netns exec pc4 ping 10.0.0.1
PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data.
^C
--- 10.0.0.1 ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1006ms
vdkmai@Ubuntu32bit:~$ sudo ip netns exec pc4 ping 10.0.0.2
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
^C
--- 10.0.0.2 ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1001ms
vdkmai@Ubuntu32bit:~$ sudo ip netns exec pc4 ping 10.0.0.3
PING 10.0.0.3 (10.0.0.3) 56(84) bytes of data.
64 bytes from 10.0.0.3: icmp_req=1 ttl=64 time=0.048 ms
64 bytes from 10.0.0.3: icmp_req=2 ttl=64 time=0.069 ms
^C
--- 10.0.0.3 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 999ms
rtt min/avg/max/mdev = 0.048/0.058/0.069/0.013 ms
Commands to reset configuration
sudo ip netns del pc1
sudo ip netns del pc2
sudo ip netns del pc3
sudo ip netns del pc4
sudo ip link set vSwitch down
sudo brctl delbr vSwitch
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment