VLAN And Switch
Setup
Consider this setup:
- 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:
we repeat the same for other switches
Setup guests
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
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
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.
**
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.