VLAN And Switch

Setup

Consider this setup:

Pasted image 20250125184539.png

  • Switch 1 only has VLAN1 setup
  • Switch 2 only has
    • VLAN2 for first half the port
    • VLAN1 for second half the port
  • Switch 3 only has VLAN2 setup

We now start connecting the 3 switches:

Pasted image 20250125184826.png

we repeat the same for other switches

Pasted image 20250125185249.png

Setup guests

Pasted image 20250125185508.png

For each guest, lets setup the ip to be its name. For example. Ubuntu-1 will be 192.168.1.1

ip a add 192.168.1.1/24 dev eth0 # Ubuntu 1
ip a add 192.168.1.2/24 dev eth0 # Ubuntu 2
...

In the end you should have something similar to this:

root@Ubuntu-4:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
10: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UNKNOWN group default qlen 1000
    link/ether 02:42:02:3b:f5:00 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.4/24 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:2ff:fe3b:f500/64 scope link 
       valid_lft forever preferred_lft forever

Now,

  • Ubuntu-1 and Ubuntu-2 can ping eachother (via 192.168.1.1 and 192.168.1.2).
  • Ubuntu-3 and Ubuntu-4 can ping eachother (via 192.168.1.3 and 192.168.1.4)

However, Ubuntu-1 cannot ping Ubuntu-3 vice versa. In otherword, only same VLAN can ping eachother

Configure Trunking

Say we have Switch 6 which also contains VLAN 1 and VLAN 2. We want to connect Switch 6 to Switch 2

Pasted image 20250125203604.png

In here, since Switch6 and Switch 2 have 2 VLANs, without trunking we need to do

  • Switch 6: VLAN 1 Connects to Switch 2: VLAN 1
  • Switch 6: VLAN 2 Connects to Switch 2: VLAN 2

After this, the 2 VLANS in both switch can then talk to eachother. However, this will cost us 2 ports on both switch. In fact, if we have n vlans, that means both switch will cost n ports.

Using trunking

On switch 6 we set port 3 to be vLAN Trunking by setting the type to be dot1q

Pasted image 20250125210448.png

In here by default, trunking dont belong to any VLAN. So the VLAN setting here is the native VLAN.

Native VLAN 4 means if a protocol or any traffic goes through without any VLAN tagging, it will default to be from VLAN 4.

Choosing number 4 here doesn't mean anything it's just for example purposes.

Similarly, for Switch 2, we set Port 7 to be native vlan 3. Pasted image 20250125210707.png
**
Now we connect Switch 6 port 3 to Switch 2 Port 7

As a result, all machines from these 2 switches can now talk to each other.