Sub topic 2
VLANs as Separate Broadcast Domains
This chapter assumes you know Ethernet frames and MAC addresses, how a Layer 2 switch learns, forwards, floods and filters frames, IPv4 subnetting, and basic switch command-line use. It explains what a VLAN is and how a switch treats traffic once VLANs exist. Access ports, trunks and the 802.1Q tag get their own chapters.
The problem a VLAN solves
A switch forwards a frame by looking up the destination MAC address in its MAC address table. Some frames have no table entry to use, and the switch floods these out every port except the one they arrived on:
- Broadcasts, which go to ff:ff:ff:ff:ff:ff. ARP requests and DHCP discovers are examples.
- Unknown unicast, meaning a destination MAC address the switch has not learned yet.
- Multicast, unless the switch limits it with a feature such as IGMP snooping.
The set of devices that receive a broadcast sent by any one of them is a broadcast domain. On a plain switch, every port is in the same broadcast domain. Adding more switches and cables does not change this, because switches extend the domain instead of dividing it.
A single large broadcast domain has three costs:
- Every host processes every broadcast, even when the broadcast is not meant for it.
- Unrelated groups, such as guest devices and finance servers, share one Layer 2 segment.
- Any loop or broadcast storm affects every attached device.
Routers do divide broadcast domains, because they do not forward Layer 2 broadcasts. Buying one router interface and one switch for every group is expensive and inflexible. VLANs give you the same separation inside a single switch.
What a VLAN is
A virtual LAN (VLAN) is a logical Layer 2 segment defined in switch configuration instead of by cabling. Each VLAN is identified by a number, the VLAN ID. Each switch port is assigned to a VLAN, and the switch then enforces one rule:
> A frame that enters a port in VLAN N may only be forwarded, or flooded, out ports that are also in VLAN N.
Because of that rule, each VLAN is its own broadcast domain. A broadcast from a host in VLAN 10 reaches only the other VLAN 10 ports. The same holds for unknown unicast and multicast flooding.
How the switch keeps VLANs apart
Inside the switch, every frame is associated with a VLAN ID. For a frame arriving on an access port, the switch takes the VLAN from the port configuration. The switch then keeps MAC address learning and forwarding separate per VLAN. Conceptually, the table is keyed by the pair (VLAN ID, MAC address) and not by the MAC address alone. Two consequences follow:
- A MAC address learned in VLAN 10 is not used to forward a frame in VLAN 20.
- The same MAC address can legitimately appear in two VLANs, on different ports. This happens, for example, with a server that has one interface in each VLAN.
The switch does not forward frames from one VLAN to another at Layer 2. If a host in VLAN 10 must reach a host in VLAN 20, the traffic has to pass through a Layer 3 device. A later chapter covers inter-VLAN routing.
VLANs and IP subnets
A VLAN is a Layer 2 concept and an IP subnet is a Layer 3 concept. The switch does not check that they agree. In practice, you map them one to one: one VLAN carries one IPv4 subnet, and the router or Layer 3 switch provides the default gateway for that subnet.
| VLAN | Name | Subnet | Gateway |
|---|---|---|---|
| 10 | USERS | 192.168.10.0/24 | 192.168.10.1 |
| 20 | SERVERS | 192.168.20.0/24 | 192.168.20.1 |
The mapping matters because a host decides whether a destination is local by comparing it with its own subnet. If it is local, the host ARPs for the destination directly, and that broadcast must stay within the host's VLAN to work. If you put a host with a 192.168.10.x address in VLAN 20, it will ARP for its gateway, no reply will arrive, and the host will look as if the network is down. The cable, link light and switch port will all look healthy.
Creating VLANs and assigning ports
On Cisco IOS, you first create the VLAN and name it. You then assign access ports to it. An access port belongs to exactly one VLAN and sends and receives ordinary untagged frames. The next chapters explain access ports in depth. This example only shows the commands that create the segmentation.
vlan 10
name USERS
vlan 20
name SERVERS
!
interface GigabitEthernet0/1
switchport mode access
switchport access vlan 10
!
interface GigabitEthernet0/2
switchport mode access
switchport access vlan 20With this configuration, a host on Gi0/1 and a host on Gi0/2 cannot exchange frames through the switch, even though they are plugged into the same device. If you give a second port the command switchport access vlan 10, it joins Gi0/1 in the same broadcast domain.
Worked example: tracing an ARP request
Suppose ports Gi0/1 to Gi0/4 are in VLAN 10 and ports Gi0/5 to Gi0/8 are in VLAN 20. Host A (192.168.10.11) is on Gi0/1 and wants to reach 192.168.10.12.
- Host A sends an ARP request to ff:ff:ff:ff:ff:ff on Gi0/1.
- The switch learns Host A's MAC address on Gi0/1 in VLAN 10.
- The frame is a broadcast, so the switch floods it out the other VLAN 10 ports, Gi0/2 to Gi0/4.
- The switch does not send the frame to Gi0/5 to Gi0/8. Those hosts never receive it and never spend CPU time on it.
- The owner of 192.168.10.12 replies with a unicast ARP reply. The switch learns that host's MAC address in VLAN 10 and forwards the reply out Gi0/1.
The same exchange in VLAN 20 would run independently, with its own MAC table entries.
Edge cases and common surprises
VLAN 1 and unused ports
On Cisco switches, every port starts in VLAN 1, the default VLAN, and you cannot delete that VLAN. A new switch therefore behaves like a single broadcast domain until you change port assignments. A common hardening step is to move unused ports into an unused VLAN and shut them down. A later chapter returns to this in the VLAN hopping discussion.
A port assigned to a VLAN that does not exist
Behavior depends on platform and software version. On many switches the port is placed in an inactive state until the VLAN exists, and it forwards nothing. Older software versions may create the VLAN automatically. Always create the VLAN explicitly and confirm it with show vlan brief. Hosts attached to such a port show a link light but have no connectivity.
Two switches, same VLAN number, no link
VLAN 10 on Switch 1 and VLAN 10 on Switch 2 are separate broadcast domains unless something carries that VLAN between them. The VLAN number is only a label. Frames only travel between switches over a link that carries them, and that is the job of a trunk, covered next.
What VLANs do not do
- They do not add bandwidth. Traffic from different VLANs still shares the same switch hardware and any shared uplinks.
- They do not by themselves provide security. They separate Layer 2 traffic, but a misconfigured trunk or port can bridge VLANs, and a router with no access control lists will pass traffic between them freely.
- They do not remove the need for loop prevention. Spanning Tree Protocol still runs, and Cisco's default mode (PVST+) runs one instance per VLAN.
Quick checks for a VLAN problem
When a host cannot reach a neighbor that should be in the same segment, check these in order:
- Does the port's VLAN match the intended VLAN? Use
show vlan brief. - Does the host's IP address fall in the subnet mapped to that VLAN?
- Does the VLAN exist on the switch, and is it active?
- If the neighbor is on another switch, does a trunk between them carry that VLAN?
Summary of the model
| Without VLANs | With VLANs |
|---|---|
| One broadcast domain per switch network | One broadcast domain per VLAN |
| Grouping depends on physical cabling | Grouping depends on port configuration |
| MAC table keyed by MAC address | MAC table keyed by VLAN and MAC address |
| Hosts reach each other directly at Layer 2 | Different VLANs reach each other only through a Layer 3 device |
Exercise
A switch has ports Gi0/1 to Gi0/3 in VLAN 10 and Gi0/4 to Gi0/6 in VLAN 20. A host on Gi0/2 sends a frame to a destination MAC address that the switch has never learned. Out of which ports does the switch send the frame, and why?
Show answer
Out Gi0/1 and Gi0/3 only. Unknown unicast is flooded, but only within the VLAN the frame arrived in, VLAN 10, and never back out the ingress port Gi0/2. Ports Gi0/4 to Gi0/6 are in VLAN 20 and do not receive it.
Exercise
A host with the address 192.168.10.50/24 is plugged into a port configured with switchport access vlan 20, where VLAN 20 is mapped to 192.168.20.0/24. The link light is on, but the host cannot reach its default gateway 192.168.10.1. Explain the cause and the fix.
Show answer
The host is in the wrong broadcast domain. Its ARP request for 192.168.10.1 is flooded only inside VLAN 20, where the gateway's VLAN 10 interface never sees it, so no reply comes back. The fix is to assign the port to VLAN 10 with switchport access vlan 10, not to renumber the host.