Generating PDF…

Preparing…
← Back

Introduction to Networks

Week 12 — Understanding Switches & VLANs

Reza Farashahi — NZSE

Roadmap

Switching basics

Switches, hubs, frames, collision domains, broadcast domains, and CSMA/CD.

How switches decide

MAC learning, unknown-unicast flooding, forwarding, and aging.

Managed switch features

VLANs, Layer 3 switches, port mirroring, PoE, and Lab 10.

Why switches matter

  • Most wired LAN devices connect through switches.
  • A switch gives every connected host a dedicated path into the LAN.
  • It forwards Ethernet frames using MAC addresses.
  • Managed switches add control: VLANs, monitoring, PoE, and more.
Switch PCPrinter ServerAP

Switch vs hub

Hub

  • Repeats bits out every port.
  • All devices share one collision domain.
  • No MAC address table.
  • Mostly obsolete today.

Switch

  • Learns where MAC addresses live.
  • Forwards frames only where needed.
  • Each port is its own collision domain.
  • Foundation of modern Ethernet LANs.

Switches work at Layer 2

  • Layer 2 is the Data Link layer.
  • The Layer 2 address is the MAC address.
  • A switch reads Ethernet frame headers.
  • It does not need to inspect IP addresses to switch local traffic.
Routers forward packets between networks. Switches forward frames inside a local network or VLAN.
Layer 4: Transport Layer 3: IP / Routing Layer 2: Ethernet / MAC Layer 1: Cables / Signals

The switch reads the frame

  • Source MAC: where the frame came from.
  • Destination MAC: where the frame should go.
  • Payload: usually carries an IP packet.
DestinationBBB SourceAAA PayloadIP packet / data Ethernet frame header tells the switch what to learn and where to forward.

Collision domains

  • A collision domain is a place where two devices could transmit at the same time and collide.
  • Old hubs made all connected devices share one collision domain.
  • A switch breaks the LAN into one collision domain per port.
  • Full-duplex links remove the practical collision problem.
One Large Collision Domain Hub 1 2 3 4 Collision Domain 1 Collision Domain 3 Collision Domain 2 Collision Domain 4 Switch 1 3 2 4

Full duplex eliminates collisions

  • Collisions don't occur on switches using full duplex mode:
    • There's a dedicated channel for concurrent sending and receiving data.
Collision Domain 1 Collision Domain 3 Collision Domain 2 Collision Domain 4 Switch 1 3 2 4 Switch

Broadcast domains

  • A network segment where all devices receive ethernet broadcast messages (one-to-all) from each other.
    • Example protocols: ARP, DHCP
  • Hubs and switches forward broadcasts; routers do not.
    • Broadcasts are inefficient and resource-intensive.
    • If routers forwarded broadcasts, WAN performance would collapse due to broadcast storms.
Collision Domain & Broadcast Domain Hub Router Broadcast Domain Switch Collision Domain Collision Domain

What is CSMA/CD?

💡 What it is (In Simple Terms)

CSMA/CD stands for Carrier Sense Multiple Access with Collision Detection. Think of it as courtesy rules in a shared conversation where everyone shares one microphone:

  • Carrier Sense (Listen first): Before talking, a computer listens to the cable to see if anyone else is sending data. If busy, it waits.
  • Multiple Access (Shared wire): Many devices share and transmit across the exact same physical medium.
  • Collision Detection (Stop & retry): If two devices speak at once, their signals collide! Both detect this immediately, stop transmitting, broadcast a jam signal, wait a random backoff time, and try again.

🎯 Why is it used?

  • Prevents signal corruption: On shared media (like hubs), simultaneous transmissions collide into unreadable electrical noise.
  • Enables automatic recovery: Guarantees that corrupted frames are detected and re-sent safely without crashing the network.
  • Fair sharing: Lets multiple devices share one cable fairly without requiring a central coordinator.
Why not on modern switches? Modern switches operate in full-duplex mode (separate wire pairs for sending and receiving), eliminating collisions entirely. CSMA/CD is only used if a switch port is forced into legacy half-duplex mode (e.g., when connected to a hub).

CSMA/CD Process

Assemble Frame to Send Monitor Network: Network Free? No Wait Until Network is Available Yes Send Data Wait for Random Backoff Time Data Collision? Yes Send Jam Signal No Data Transmission Complete

CSMA/CD & CSMA/CA Explained — PowerCert Animated Videos

Managed vs unmanaged switches

UnmanagedManaged
Plug in devices and it works.Administrator can configure behavior.
Common in homes and very small offices.Common in business and enterprise networks.
No VLAN control or monitoring features.Supports VLANs, port monitoring, security, PoE controls, and more.
See real products and price differences:
  • TP-Link TL-SG108 — 8-port unmanaged Gigabit switch, ~$20–25. Plug in and go.
  • Netgear GS308 — another popular unmanaged option at a similar price.
  • Cisco CBS350 (managed) — business-grade managed switch with VLAN, monitoring, and PoE. ~$150–$350+.

What management unlocks

VLANs

Separate departments or roles on one physical switch.

Visibility

Inspect port status, MAC tables, statistics, and mirrored traffic.

Policy

Control ports, power, priority, and security settings.

How a switch learns MAC addresses

  1. A frame enters a switch port.
  2. The switch reads the source MAC address.
  3. It records: this MAC lives on this port.
  4. Then it checks the destination MAC.
  5. If known, forward to one port. If unknown, flood inside the VLAN.

How a switch learns MAC addresses — step-by-step tutorial

Interactive: MAC learning stepper

Switch Host AAAA / P1 Host BBBB / P2 Host CCCC / P3
Click Next to begin with an empty MAC table.

MAC address table

MACPort
--
--

The switch learns from the source MAC of incoming frames.

MAC tables age out

  • Switches do not keep learned entries forever.
  • Inactive MAC entries age out after a timeout.
  • This lets the table adapt when devices move to different ports.
  • If the destination becomes unknown again, the switch floods until it relearns.
MAC Table AAAPort 1 BBBPort 2 CCCaged out Tables stay current by forgetting stale entries.

Quiz: switching fundamentals

1. What address does a Layer 2 switch use?
2. What does a hub do?
3. What happens when destination MAC is unknown?
4. What splits broadcast domains on a switch?

VLANs and managed features

One physical switch can support multiple logical LANs.

VLANs: LANs within LANs

  • Essentially LANs within a LAN
    • Physical Switch → Multiple Virtual Switches
  • Break up a large “physical” LAN into several smaller “logical” LANs.
  • Accomplished with managed switches.
  • Assign specific switch interfaces (ports) to specific virtual LANs.
    • Human Resource VLAN (Interfaces 1, 2, 3)
    • Accounting VLAN (Interfaces 4, 5, 6)
  • Benefits of VLANs
    • Reduces Broadcast Domains
    • Segments Network by Role
    • Increases Security
    • Devices Cannot Communicate with Other VLANs
    • Group Devices by Need, Not Physical Location
VLAN diagram showing one physical switch split into multiple virtual LANs

Port-based VLANs

Each physical switch port is assigned directly to a VLAN ID. Connected devices don't need any special configuration—the switch isolates their traffic automatically.

Switch Ports Assigned VLAN Department Behavior
Fa0/1 – Fa0/2 VLAN 20 Sales Isolated to Sales VLAN
Fa0/3 – Fa0/4 VLAN 10 HR Isolated to HR VLAN
Access Port Concept: Untagged frames from a PC enter the switch port, and the switch assigns them to that port's configured VLAN ID internally.
Cisco Switch CLI (IOS)
Terminal
! ── 1. ENTER CONFIGURATION MODE ──
Switch# configure terminal                     ! Enter global configuration mode

! ── 2. CREATE VLANs & ASSIGN NAMES ──
Switch(config)# vlan 10                        ! Create VLAN 10 database entry
Switch(config-vlan)# name HR                   ! Name VLAN 10 as "HR"
Switch(config-vlan)# vlan 20                   ! Create VLAN 20 database entry
Switch(config-vlan)# name Sales                ! Name VLAN 20 as "Sales"
Switch(config-vlan)# exit                      ! Return to global config mode

! ── 3. ASSIGN PORTS Fa0/1 - 2 TO SALES (VLAN 20) ──
Switch(config)# interface range Fa0/1 - 2      ! Select switch ports Fa0/1 to Fa0/2
Switch(config-if-range)# switchport mode access! Set port mode to access (end devices)
Switch(config-if-range)# switchport access vlan 20 ! Assign ports to Sales (VLAN 20)
Switch(config-if-range)# exit                  ! Exit interface range config

! ── 4. ASSIGN PORTS Fa0/3 - 4 TO HR (VLAN 10) ──
Switch(config)# interface range Fa0/3 - 4      ! Select switch ports Fa0/3 to Fa0/4
Switch(config-if-range)# switchport mode access! Set port mode to access (end devices)
Switch(config-if-range)# switchport access vlan 10 ! Assign ports to HR (VLAN 10)
Switch(config-if-range)# end                   ! Return to privileged EXEC mode

! ── 5. VERIFY CONFIGURATION ──
Switch# show vlan brief                        ! View VLAN table & assigned ports

VLANs split broadcasts

  • Broadcasts in VLAN 10 stay in VLAN 10.
  • Broadcasts in VLAN 20 stay in VLAN 20.
  • This reduces unnecessary traffic.
  • It also supports security and operational separation.
VLAN 10: HR VLAN 20: Sales blocked

VLAN Trunking Explained

A Trunk port is a connection between two switches (or a switch and a router) that carries traffic for multiple VLANs over a single physical link.

  • Access vs. Trunk: Access ports carry traffic for one VLAN to a PC. Trunk ports carry traffic for all VLANs between switches.
  • 802.1Q Tagging: The switch stamps a 4-byte 802.1Q tag containing the VLAN ID onto each frame before sending it across the trunk.
  • Native VLAN: Frames sent without a tag belong to the Native VLAN (default is VLAN 1).
VLANs with multiple switches showing trunk ports, access ports and 802.1Q tagging
Cisco Switch CLI (IOS) — Trunk Setup & Check
Terminal
! ── 1. HOW TO CONFIGURE TRUNK (IN CODE) ──
Switch# configure terminal                     ! Enter global configuration mode
Switch(config)# interface GigabitEthernet 0/1      ! Select trunk uplink port
Switch(config-if)# switchport mode trunk         ! Set port to trunk mode (carries multiple VLANs)
! (Optional) Restrict allowed VLANs across trunk:
Switch(config-if)# switchport trunk allowed vlan 10,20 ! Allow only VLANs 10 and 20
Switch(config-if)# end                               ! Return to privileged EXEC mode

! ── 2. HOW TO CHECK / VERIFY TRUNK STATUS ──
! Method A: Summary of all active trunk ports
Switch# show interfaces trunk                   ! List active trunks, encapsulation & VLANs
Port        Mode         Encapsulation  Status       Native vlan
Gi0/1       on           802.1q         trunking     1
Port        Vlans allowed on trunk
Gi0/1       10,20

! Method B: Detailed switchport check for one interface
Switch# show interfaces Gig0/1 switchport      ! Check operational status of Gig0/1
Operational Mode: trunk                         ! Confirms port is operating as trunk
Trunking Encapsulation: dot1q                   ! Confirms 802.1Q tagging protocol

VLANs do not route by themselves

  • VLAN 10 and VLAN 20 are separate Layer 2 networks.
  • A Layer 2 switch will not move traffic between them.
  • Cross-VLAN pings will fail without a router or Layer 3 switch.
  • To communicate between VLANs, add routing.
VLAN 10HR VLAN 20Sales No L3 path Isolation is the goal. Add a router or L3 switch to enable routing.

Layer 3 switches

  • Provide Layer 2 Switching & Layer 3 Routing.
    • OSI Layer 2 (Data Link): Switching
      • MAC Addresses
    • OSI Layer 3 (Network): Routing
      • IP Addresses
  • Managed Switch Capability
  • Used in Conjunction with VLANs
  • Provides:
    • VLAN Switching
    • IP Routing between VLANs
  • One Device Instead of Router & Switch
Layer 3 switch diagram showing combined switching and routing

Controlling Inter-VLAN Traffic

VLAN segmentation keeps traffic isolated by default. When departments need to communicate, the router controls and filters the path.

✅ How to LET VLANs Communicate

Configure Router-on-a-Stick sub-interfaces. The router acts as the default gateway for each VLAN and forwards IP packets between them automatically.

⛔ How NOT to Let Them Communicate

Method 1 (Default): Do not create a gateway for that VLAN on the router (Layer 2 isolation remains total).
Method 2 (Filtered): Apply an Access Control List (ACL) to deny specific cross-VLAN traffic while still permitting internet access.

Security Principle: Isolate by default at Layer 2; route and permit intentionally at Layer 3.
Cisco Router CLI (IOS) — Inter-VLAN Routing
Router#
! ── 1. HOW TO LET TWO VLANs COMMUNICATE (ROUTER-ON-A-STICK) ──
Router# configure terminal                     ! Enter global configuration mode
Router(config)# interface GigabitEthernet 0/0      ! Select physical trunk port to switch
Router(config-if)# no shutdown                   ! Enable / power on the physical port

! Sub-interface gateway for VLAN 10 (HR)
Router(config)# interface Gig0/0.10              ! Create virtual sub-interface for VLAN 10
Router(config-subif)# encapsulation dot1Q 10     ! Tag & recognize 802.1Q VLAN 10 frames
Router(config-subif)# ip address 192.168.10.1 255.255.255.0 ! Default gateway IP for HR subnet

! Sub-interface gateway for VLAN 20 (Sales)
Router(config)# interface Gig0/0.20              ! Create virtual sub-interface for VLAN 20
Router(config-subif)# encapsulation dot1Q 20     ! Tag & recognize 802.1Q VLAN 20 frames
Router(config-subif)# ip address 192.168.20.1 255.255.255.0 ! Default gateway IP for Sales subnet
! → Both VLANs can now communicate through the router!

! ── 2. HOW NOT TO LET THEM COMMUNICATE (BLOCK WITH ACL) ──
! Rule 1: Deny Sales (192.168.20.0/24) packets destined to HR (192.168.10.0/24)
Router(config)# access-list 100 deny ip 192.168.20.0 0.0.0.255 192.168.10.0 0.0.0.255

! Rule 2: Permit all other IP traffic (Internet, DNS, printers, etc.)
Router(config)# access-list 100 permit ip any any

! Apply ACL inbound on the Sales sub-interface
Router(config)# interface Gig0/0.20              ! Enter Sales sub-interface configuration
Router(config-subif)# ip access-group 100 in     ! Inspect & filter packets entering from Sales
! → Sales is blocked from HR, but can still access the Internet!

Port mirroring

  • Also called SPAN on Cisco switches.
  • Copies traffic from one or more source ports.
  • Sends the copy to a monitoring port.
  • Useful for Wireshark, IDS, troubleshooting, and learning.
Server Client Switch Analyzer Original traffic still flows. A copy is mirrored for analysis.

Power over Ethernet

  • PoE sends power and data over the same Ethernet cable.
  • Common for IP phones, wireless access points, and cameras.
  • A PoE switch can power devices without a nearby wall outlet.
  • The switch has a total power budget.
PoE Switch IP Phone Camera datapower

PoE power budget

DevicePower needCountTotal
IP phones7 W856 W
Access points18 W472 W
Cameras12 W672 W
Needed200 W
If a switch has a 150 W PoE budget, this example is over budget.

Quiz: choose the switch feature

ScenarioBest feature
Separate HR and Sales on one physical switch.
Copy traffic to a Wireshark laptop for troubleshooting.
Power cameras without separate electrical outlets.
Route between VLANs inside the campus LAN.

Switch design checklist

Ask first

  • Who needs to communicate?
  • Who should be isolated?
  • Which devices need power?
  • What traffic should be monitored?

Then choose

  • Unmanaged or managed switch.
  • VLAN plan and port assignments.
  • Layer 3 routing policy.
  • PoE budget and monitoring ports.

Common mistakes

In the lab

  • Assigning the wrong switch port.
  • Forgetting to create the VLAN first.
  • Testing the wrong target IP.
  • Expecting cross-VLAN pings to work.

In concepts

  • Confusing collision and broadcast domains.
  • Thinking VLANs route automatically.
  • Thinking a switch uses IP addresses for Layer 2 forwarding.
  • Forgetting that unknown unicast is flooded.

Key takeaways

Switching

  • Switches forward frames using MAC addresses.
  • They learn from source MAC addresses.
  • Unknown destinations are flooded inside the VLAN.
  • Each switch port is its own collision domain.

Managed features

  • VLANs split broadcast domains.
  • Layer 3 switches route between VLANs.
  • Port mirroring copies traffic for analysis.
  • PoE carries power and data over Ethernet.
Open Lab 10 and build VLAN 10 for HR and VLAN 20 for Sales.