Sub topic 2
VLANs as Separate Broadcast Domains
This chapter assumes you know Ethernet frames and MAC addresses, how a switch learns addresses and floods, forwards or filters frames, IPv4 subnets, and basic switch command-line use.
What a VLAN is
A virtual LAN (VLAN) is a logical Layer 2 segment defined inside one or more switches. Each switch port is assigned to a VLAN. The switch forwards frames only between ports in the same VLAN. A VLAN is therefore a separate broadcast domain. A broadcast sent by a host in one VLAN is never delivered to ports in another VLAN, even when the ports are on the same physical switch.
Without VLANs, every port on a switch shares one broadcast domain. Broadcasts such as ARP requests and DHCP discovers reach every host. Unknown-unicast frames are flooded to every port. As the network grows, this adds load and widens the area where a faulty or hostile host can cause trouble.
How the switch keeps VLANs apart
A switch with VLANs behaves as if it were several independent switches. Three behaviors matter:
- The MAC address table is kept per VLAN. The same MAC address can appear in two VLANs without conflict.
- Flooding is limited to ports in the frame's VLAN.
- A frame never crosses to another VLAN at Layer 2. Moving traffic between VLANs needs a Layer 3 device, covered in a later chapter.
VLANs and IP subnets
The usual design maps one VLAN to one IP subnet. Hosts in VLAN 10 might use 192.168.10.0/24 and hosts in VLAN 20 might use 192.168.20.0/24. This is a convention, not a rule enforced by the switch. The switch does not look at IP addresses. If you put two subnets in one VLAN, they share a broadcast domain but still need a router to talk to each other. If you put one subnet across two VLANs, hosts cannot reach each other, because their ARP broadcasts are not delivered across the VLAN boundary.
Creating a VLAN
Creating a VLAN registers its ID and an optional name in the switch's VLAN database. A port belongs to a VLAN only after you assign it.
vlan 10
name USERS
vlan 20
name SERVERSHosts connected to ports in VLAN 10 now share a broadcast domain that is separate from VLAN 20. Port assignment is covered in the access ports chapter.
Common errors
- Assigning a port to a VLAN that does not exist. Depending on the platform, the switch may create it automatically or the port may carry no traffic. Check the VLAN database first.
- Mismatched subnets. Two hosts in the same VLAN with addresses in different subnets will not communicate directly.
- Assuming VLANs are a security boundary on their own. VLANs separate broadcast domains. Their isolation depends on correct configuration, and later chapters cover how it can fail.
Exercise
Host A and host B are connected to ports in VLAN 10 on one switch. Host C is on a port in VLAN 20 on the same switch. Host A sends an ARP request broadcast. Which hosts receive it, and why?
Show answer
Only host B receives it. The switch floods a broadcast only to ports in the same VLAN as the incoming frame. Host C is in VLAN 20, a different broadcast domain, so it does not receive the frame.
Exercise
Why can the same MAC address safely appear in the MAC address tables of VLAN 10 and VLAN 20?
Show answer
The switch keeps a separate MAC address table for each VLAN, so an entry in one VLAN does not conflict with an entry in another.