VLANs

One switch, several broadcast domains, drawn in software

123456789101112VLAN 10 · Sales · 10.1.10.0/24VLAN 20 · Engineering · 10.1.20.0/24broadcast✗✗✗✗✗✗never reaches VLAN 20A VLAN is a broadcast domain drawn in software: one switch behaves as several, with no traffic between them.Each access port belongs to one VLAN. Ports 1 to 6 are Sales and 7 to 12 Engineering; a broadcast, an unknown unicastor a flood stays inside its VLAN. Each VLAN gets its own IP subnet. Groups follow function rather than floor, and abroadcast storm or a curious laptop in one VLAN cannot reach the other without passing a router and its rules.

A VLAN is a separate broadcast domain on shared switches. Each VLAN is its own IP subnet.

VLANs · Going deeper

Access ports, voice VLANs and VLAN ranges

Switch port Gi1/0/5IP phonePC behind itvoice: tagged VLAN 100data: untagged VLAN 10interface gi1/0/5 switchport mode access switchport access vlan 10 switchport voice vlan 100 spanning-tree portfastVLAN IDsRangeNote0 and 4095reservednever assigned1defaultevery port starts here; do not use for users2 to 1001normalstored in vlan.dat1002 to 1005reservedold Token Ring and FDDI1006 to 4094extendedstored in the running configurationAn access port carries one data VLAN, plus a tagged voice VLAN when a phone sits in front of a PC.The 12-bit VLAN ID allows 4,094 usable VLANs. The phone learns its voice VLAN through CDP or LLDP-MED and tags its owntraffic, so voice and data share one cable but land in different subnets with different priorities.

An access port carries one VLAN untagged; a voice VLAN adds tagged phone traffic on the same port. Usable IDs run from 1 to 4094.

802.1Q trunks

A 4-byte tag lets one link carry many VLANs

SW1SW2one trunk link carries VLANs 10 and 20Destination MAC6 bytesSource MAC6 bytes802.1Q tag4 bytesType2 bytesPayload46 to 1500FCS4 bytesTPID 0x8100PCPDVLAN ID (12 bits)priority 0 to 7 · VLAN 1 to 4094A trunk carries many VLANs over one link by inserting a 4-byte tag that names each frame’s VLAN.The sending switch inserts the tag after the source MAC and recomputes the FCS; the receiving switch reads the VLAN ID,removes the tag and forwards the frame only to ports in that VLAN. Hosts never see tags. The 3-bit priority (PCP, or CoS)is how a switch knows to queue voice ahead of a backup. A tagged frame can be 1522 bytes.

A trunk carries frames from many VLANs, each with an 802.1Q tag holding a 12-bit VLAN ID.

802.1Q trunks · Going deeper

Native VLAN, allowed VLANs and DTP

interface gi1/0/24 switchport mode trunk switchport trunk native vlan 999 switchport trunk allowed vlan 10,20,100 switchport nonegotiateSW1# show interfaces trunkPort      Mode  Encapsulation  Status    Native vlanGi1/0/24  on    802.1q         trunking  999Port      Vlans allowed and activeGi1/0/24  10,20,100Native VLANthe one VLAN a trunk sends untagged (VLAN 1 by default). Both ends must agree, or framesleak between VLANs and CDP warns of a mismatch.Allowed listtrim it to the VLANs that need to cross. A missing VLAN on the allowed list is a classic“one VLAN works, one does not” fault.DTP offDynamic Trunking Protocol can turn a port into a trunk on request; nonegotiate and anexplicit mode stop that.Set the native VLAN to an unused one and list exactly which VLANs may cross: two lines that prevent VLAN hopping.In a double-tagging attack, a host in the native VLAN sends a frame with two tags; the first switch strips the outer one asnative and the next switch obeys the inner one, landing the frame in a VLAN it should never reach.

The native VLAN crosses a trunk untagged and must match at both ends. Set it to an unused VLAN, prune the allowed list, and disable DTP.

Inter-VLAN routing

VLANs cannot talk until something routes between them

Router on a stickRouterone trunkGi0/0.10 and Gi0/0.20 subinterfacesLayer 3 switchroutes insideVlan10 SVIVlan20 SVIroutes at hardware speed, no hairpinA port per VLAN (old)one router port and cable per VLANHosts in different VLANs cannot talk until something routes between them.Each VLAN is its own subnet, so traffic between them needs a gateway. Router on a stick sends every VLAN up one trunk toa router and back down; it works, but that one link carries all the traffic twice. A layer 3 switch gives each VLAN aswitched virtual interface (SVI) as its gateway and routes between them internally. Campus networks use this.

Route between VLANs with a router on a stick (subinterfaces on a trunk) or a layer 3 switch with one SVI per VLAN.

Inter-VLAN routing · Going deeper

Configuring subinterfaces and SVIs

! router on a stickinterface gi0/0.10 encapsulation dot1Q 10 ip address 10.1.10.1 255.255.255.0interface gi0/0.20 encapsulation dot1Q 20 ip address 10.1.20.1 255.255.255.0! layer 3 switchip routinginterface vlan 10 ip address 10.1.10.1 255.255.255.0interface vlan 20 ip address 10.1.20.1 255.255.255.0interface gi1/0/48 no switchportAn SVI comes up only when the VLAN exists, at least one port in it is up and forwarding, and it is not shut down.Forget ip routing on the layer 3 switch and every SVI answers pings while nothing is routed between them.Each VLAN’s gateway is an address on a subinterface or an SVI. The hosts in that VLAN point their default gateway at it.On a router the subinterface number is only a label; encapsulation dot1Q sets the VLAN. no switchport turns a switch portinto a routed port with its own IP address, used for links up to the core.

encapsulation dot1Q ties a subinterface to a VLAN; ip routing and interface vlan make a layer 3 switch route.

Spanning tree

Ethernet has no time to live, so a loop runs until a port is blocked

a broadcast circles foreverand multiplies at every switchSW-ASW-BSW-CWith spanning treeone port blocks,the loop is cutEthernet has no time to live, so a loop runs until spanning tree blocks a port to break it.Redundant links between switches are good; the loop they create is not. A broadcast is flooded round the ring and copied atevery switch, and within seconds the storm fills every link and MAC table flaps between ports. Spanning tree (STP) finds theloops and blocks one port in each, keeping the spare link ready to unblock if the active path fails.

A switching loop causes a broadcast storm. Spanning tree blocks one port per loop and unblocks it if the active path fails.

Spanning tree · Going deeper · 1 of 2

Electing the root and choosing which port blocks

SW-A · root bridge32778 · 0000.0c11.1111SW-B32778 · 0000.0c22.2222SW-C32778 · 0000.0c33.3333DDRRcost 4cost 4D✗1 Gbps links, cost 4 eachblocked1 Lowest bridge ID wins root:priority + VLAN, then MAC2 Root ports: each switch’scheapest path to the root3 Designated: one per link,the end nearer the root4 Every other port blocks.B–C tie at cost 4: lowerbridge ID (B) is designatedSpanning tree elects a root, gives every switch its cheapest path to it, and blocks whatever is left over.All three have the default priority 32768 plus VLAN 10, so the lowest MAC, SW-A, becomes root. Set it instead:spanning-tree vlan 10 root primary on the core. Costs: 10 Mbps 100, 100 Mbps 19, 1 Gbps 4, 10 Gbps 2. Ties break onthe neighbour’s bridge ID, then its port ID. R = root port, D = designated port, ✗ = blocked.

The lowest bridge ID becomes root bridge. Each switch picks a root port, each link a designated port; the rest block.

Spanning tree · Going deeper · 2 of 2

Rapid PVST+: roles, states and guards

Port role (Rapid PVST+)What it doesStateRoot portthe switch’s best path toward the rootforwardingDesignated portthe best port on its link toward the rootforwardingAlternate porta backup path to the root, ready to take overdiscardingBackup porta spare to a shared segment (rare)discardingEdge port (PortFast)goes to a host; skips listening and learningforwarding at onceProtectionApplied onStopsBPDU guardPortFast host portsa switch plugged into a user port: err-disables itRoot guardports to switches that must never be roota rogue or misconfigured rootLoop guardroot and alternate portsa one-way link turning a blocked port to forwardingClassic STP took 30 to 50 seconds to recover; Rapid PVST+ moves an alternate port to forwarding in about a second.Rapid PVST+, Cisco’s default, runs a separate rapid spanning tree for every VLAN, so roots can differ per VLAN.

Rapid PVST+ runs one rapid tree per VLAN. PortFast and BPDU guard on host ports; root guard and loop guard protect the design.

EtherChannel

Bundle links so spanning tree sees one, but a flow still rides one member

Access switchDistributionPort-channel 1 · 4 × 1 Gbpsflow 1: backup jobflow 2: video callflow 3: webEach flow is pinned to one member by a hash of its addresses, so one flow never exceeds 1 Gbps.Bundle parallel links so spanning tree sees one, but remember each single flow still rides one member.Without a bundle, spanning tree would block three of the four links. As an EtherChannel they act as one 4 Gbpsinterface, and losing a member only lowers capacity. Flows are spread by hashing MAC or IP addresses and ports, so manyflows share well and one big transfer does not. Members must match in speed, duplex, mode and VLANs. Up to 8 active.

An EtherChannel joins up to 8 links into one logical interface; LACP negotiates it and hashing spreads flows across members.

EtherChannel · Going deeper

LACP and PAgP modes: which combinations form a channel

Side ASide BChannel forms?Protocolactiveactive✓ yesLACP (IEEE 802.1AX)activepassive✓ yesLACPpassivepassive✗ no: both waitLACPdesirableauto✓ yesPAgP (Cisco only)autoauto✗ no: both waitPAgPonon✓ yes, no checksnone (static)onactive✗ nomixedinterface range gi1/0/1 - 4 channel-group 1 mode activeSW1# show etherchannel summaryPo1(SU)   LACP   Gi1/0/1(P) Gi1/0/2(P)At least one side must start the conversation: active for LACP, desirable for PAgP.Static “on” skips negotiation and will happily bundle a miswired link; LACP checks every member. SU means a layer 2channel that is up; P marks a member in the bundle, and an (s) or (I) marks one that is suspended or standalone.

LACP active forms with active or passive; passive with passive never forms. PAgP desirable forms with auto. “On” is static.

Lesson complete

You finished “VLANs and spanning tree”

Nicely done.

Open in a new tab