Skip to content

Intermediate · Switching and VLANs · topic 21 of 57 · 30 min

VLANs: what they are and why we use them

Explanation

A VLAN (virtual LAN) is a group of switch ports that act like their own separate switch. Broadcasts stay inside the VLAN, so one physical switch can safely carry staff, guest and camera traffic apart from each other. You create a VLAN with vlan 10, put a port in it with switchport access vlan 10, and check the result with show vlan brief.

The problem: one big broadcast domain

A broadcast is a frame sent to every device on the local network. Its destination MAC address is ffff.ffff.ffff. ARP ("who has this IP address?") and DHCP ("is there a DHCP server?") both use broadcasts. A switch forwards a broadcast out of every port except the one it came in on.

A broadcast domain is the set of devices that receive each other's broadcasts. Out of the box, every port of a switch is in the same broadcast domain. In a small office that is fine. In a hospital with 600 devices, it means every PC, printer, camera and guest phone hears every broadcast, and any device can try to talk to any other device directly.

The answer: VLANs

A VLAN (virtual local area network) is a group of switch ports that behave as if they were on their own separate switch. A broadcast from a port in VLAN 10 goes only to the other ports in VLAN 10. Devices in VLAN 20 never see it. To get from one VLAN to another, traffic must go through a router or a layer 3 switch, where you can control it with rules.

Think of it like this: Think of a big hospital building. Everyone walks through the same corridors (the same switch), but the doors are colour-coded. Staff have green cards that open only green doors, visitors have blue cards that open only blue doors. People share the building, yet each group can only reach its own rooms. To move between colours you must pass the security desk, which is the router.

Why VLANs are worth it

  • Smaller broadcast domains: fewer devices hear each broadcast, so less wasted bandwidth and CPU.
  • Security: guest Wi-Fi users cannot reach the billing servers, because traffic between VLANs must pass a router or firewall that checks it.
  • Easier changes: moving a person to another department is a one-line config change, not a new cable.
  • Better treatment for special traffic: voice and camera traffic can get its own VLAN and its own quality of service rules.

A common hospital plan: VLAN 10 STAFF, VLAN 20 GUEST-WIFI, VLAN 30 CCTV, VLAN 40 MEDICAL-DEVICES, VLAN 50 VOICE. Each VLAN normally gets its own IP subnet, for example 10.10.10.0/24 for staff and 10.10.20.0/24 for guests. One VLAN, one subnet: remember this rule.

VLAN numbers

A VLAN ID is a 12-bit number, so it can be 0 to 4095. The values 0 and 4095 are reserved, which leaves 1 to 4094 for use.

RangeMeaning
1The default VLAN. Every port starts here. It cannot be deleted or renamed.
2 to 1001Normal range. Use these for everyday VLANs.
1002 to 1005Reserved for old Token Ring and FDDI networks. They exist on the switch but cannot be deleted or used.
1006 to 4094Extended range. Supported on modern switches; on older switches with VTP version 1 or 2 you must use VTP transparent mode to create them.

Creating VLANs and access ports

output
SW1(config)# vlan 10
SW1(config-vlan)# name STAFF
SW1(config-vlan)# vlan 20
SW1(config-vlan)# name GUEST
SW1(config-vlan)# exit
SW1(config)# interface range fastEthernet 0/1 - 2
SW1(config-if-range)# switchport mode access
SW1(config-if-range)# switchport access vlan 10
SW1(config-if-range)# exit
SW1(config)# interface fastEthernet 0/3
SW1(config-if)# switchport mode access
SW1(config-if)# switchport access vlan 20
Cisco IOS: create two named VLANs, then make ports Fa0/1 and Fa0/2 access ports in VLAN 10 and Fa0/3 an access port in VLAN 20.

An access port belongs to exactly one data VLAN. It sends and receives normal, untagged frames, so the PC plugged into it does not know that VLANs exist. switchport mode access fixes the port as an access port, so it will never turn into a trunk by negotiation (you will meet trunks in the next topic).

Checking your work: show vlan brief

output
SW1# show vlan brief

VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
1    default                          active    Fa0/4, Fa0/5, Fa0/6, Gi0/2
10   STAFF                            active    Fa0/1, Fa0/2
20   GUEST                            active    Fa0/3
1002 fddi-default                     act/unsup
1003 token-ring-default               act/unsup
1004 fddinet-default                  act/unsup
1005 trnet-default                    act/unsup
Cisco IOS: each VLAN with its name, status and access ports. Trunk ports are not listed here.

If Gi0/1 is missing from every line, that is normal when Gi0/1 is a trunk: show vlan brief lists only access ports. Use show interfaces trunk to see trunks.

Voice VLAN: a phone and a PC on one port

Offices often plug a PC into the back of an IP phone, and the phone into the wall port. The port then carries two kinds of traffic. With switchport voice vlan 50, the switch tells the phone (using CDP or LLDP-MED) to tag its voice frames with VLAN 50, while the PC traffic stays untagged in the access VLAN. The port is still an access port.

output
SW1(config)# interface fastEthernet 0/10
SW1(config-if)# switchport mode access
SW1(config-if)# switchport access vlan 10
SW1(config-if)# switchport voice vlan 50
Cisco IOS: PC data in VLAN 10, phone voice in VLAN 50, on the same port.

Common mistakes and how to fix them

Careful: Putting a port in a VLAN that does not exist: most current switches create it for you with a warning, but older ones leave the port inactive. Always create and name the VLAN first, and check with show vlan brief.
  • Expecting PCs in two VLANs to ping each other through the switch alone. They cannot: you need inter-VLAN routing (later in this module).
  • Leaving unused ports in VLAN 1 and enabled. Best practice is to move them to an unused "parking" VLAN and shut them down, so nobody can plug in and join a real VLAN.
  • Using the same subnet in two VLANs. Each VLAN needs its own subnet, or routing between them breaks.
  • Forgetting switchport mode access, which leaves the port able to negotiate a trunk with whatever is plugged in.
Tip: Give every VLAN a clear name (STAFF, GUEST, CCTV). Six months later, "VLAN 30 CCTV" in show vlan brief explains itself; "VLAN0030" does not.

Need help?

Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.

Try:

Watch the lesson

VLANs: what they are and why we use them · 1/7

VLANs

In this lesson you will learn what a VLAN is and why almost every company network uses them.

Prefer a video by a teacher? Find free videos on “cisco vlan configuration access port explained ccna” on YouTube ↗

In real life: A multi-speciality hospital in Hyderabad

The hospital has one core switch per floor. Doctors' PCs and the billing system sit in VLAN 10, patient guest Wi-Fi in VLAN 20, CCTV cameras in VLAN 30 and infusion pumps and monitors in VLAN 40. A virus on a visitor's phone in VLAN 20 cannot even send an ARP request to the billing server, because the broadcast never leaves VLAN 20, and the firewall between VLANs allows guests only to the internet.

output
vlan 10
 name STAFF
vlan 20
 name GUEST-WIFI
vlan 30
 name CCTV
vlan 40
 name MEDICAL-DEVICES
Cisco IOS: the VLAN plan as it appears in the switch configuration.

Practice (0/3 done)

Task 1 · Code · Python

Write vlan_range(vlan_id) that returns which range a VLAN number belongs to: "default" for 1, "normal" for 2 to 1001, "reserved" for 1002 to 1005, "extended" for 1006 to 4094, and "invalid" for anything else (including 0 and 4095).

Task 2 · Code · Python

A switch has access ports in different VLANs, given as a dict such as {"Fa0/1": 10, "Fa0/2": 10, "Fa0/3": 20}. Write broadcast_ports(port_vlans, source) that returns the list of ports that receive a broadcast sent by the device on port source: every other port in the same VLAN, in the same order as in the dict. If source is not in the dict, return an empty list.

Task 3 · Practice

Packet Tracer lab: put one 2960 switch and four PCs on the canvas. PC1 and PC2 (Fa0/1, Fa0/2) are in VLAN 10 STAFF with addresses 10.10.10.11 and 10.10.10.12 /24. PC3 and PC4 (Fa0/3, Fa0/4) are in VLAN 20 GUEST with 10.10.20.11 and 10.10.20.12 /24. Configure the switch, then test which pings work and explain why.

Quick quiz

Question 1

1.What does a VLAN separate?

Question 2

2.Which VLAN range is reserved for old Token Ring and FDDI?

Question 3

3.Which command makes Fa0/5 an access port in VLAN 30 (after switchport mode access)?

Question 4

4.show vlan brief does not list port Gi0/1 at all. What is the most likely reason?

Question 5

5.An IP phone and a PC share one switch port. Which command puts the phone traffic in VLAN 50?

Read more (free)

Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.

What does a VLAN separate?

Answer: Broadcast domains

Each VLAN is its own broadcast domain: a broadcast stays inside the VLAN.

Which VLAN range is reserved for old Token Ring and FDDI?

Answer: 1002 to 1005

VLANs 1002 to 1005 exist on the switch for legacy Token Ring and FDDI and cannot be deleted.

Which command makes Fa0/5 an access port in VLAN 30 (after switchport mode access)?

Answer: switchport access vlan 30

switchport access vlan 30 sets the data VLAN of an access port.

show vlan brief does not list port Gi0/1 at all. What is the most likely reason?

Answer: Gi0/1 is a trunk port

show vlan brief lists access ports only. Trunk ports appear in show interfaces trunk.

An IP phone and a PC share one switch port. Which command puts the phone traffic in VLAN 50?

Answer: switchport voice vlan 50

switchport voice vlan 50 tells the phone to tag voice frames with VLAN 50; the PC stays in the access VLAN.

How are frames in the native VLAN sent on an 802.1Q trunk?Related

Answer: Untagged

The native VLAN is the one VLAN whose frames cross the trunk without a tag.

From Trunks and 802.1Q tagging

A PC in VLAN 10 sends a packet to a PC in VLAN 20. Where does it send the frame first?Related

Answer: To its default gateway

The other PC is on a different subnet, so the PC sends the packet to its default gateway, which routes it.

From Inter-VLAN routing

A frame to ffff.ffff.ffff arrives on port 5 of a 24-port switch (all in one VLAN). Where does it go?Related

Answer: All ports except port 5

Broadcasts are flooded out of every port except the incoming one.

From How a switch learns and forwards

A 16-port switch has a PC on every port. How many collision domains are there?Related

Answer: 16

Each switch port is its own collision domain.

From Network devices

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

Next steps

  1. 4 more topics in “Switching and VLANs” before its exam: Trunks and 802.1Q tagging, Inter-VLAN routing, CDP and LLDP: discovering neighbours, Switch management and interface troubleshooting.
  2. Module 5 exam: Switching and VLANs · 13 questions · 20 min, without help. 5 topics of this module still to finish first.
  3. Then the next module, Spanning Tree and EtherChannel. 57 topics left in the course before the final exam.

← Previous: IPv6 address types, EUI-64, SLAAC and NDP