Wiki DE Start in the browser

Wiki › Protocols

VLANs and trunks

One switch, several separate networks: access ports, trunks with 802.1Q tag, native VLAN and routing between VLANs.

Layer
2 (Sicherung)
Standard
IEEE 802.1Q, IEEE 802.3
See an example
2 demos

What for

Without VLANs a switch is a single network: every broadcast reaches everyone, every device sees every other. A VLAN (virtual LAN) divides the switch into separate networks, e.g. administration, training and guests. Nothing passes between the VLANs without a router; this separates departments and enforces rules.

Access port and trunk

Port typeforFrames
Accessend device, belongs to exactly one VLANwithout tag
Trunklink between switches or to the router, carries several VLANswith 802.1Q tag (VLAN number)

The 802.1Q tag is 4 bytes after the MAC addresses: EtherType 0x8100, priority and the 12-bit VLAN ID (1 to 4094). The native VLAN travels on the trunk without a tag; both ends must have the same native VLAN. With “allowed VLANs” a trunk only lets certain VLANs through.

VLANs with trunk and spanning tree in the simulationVLANs with trunk and spanning tree in the simulation
Slow motion VLANs with trunk and spanning tree in the simulation

The 802.1Q tag

On the trunk the switch inserts 4 bytes after the source MAC: TPID 0x8100 and the VLAN number in it. At the access port it removes the tag again. Because the frame changes, the switch recomputes the FCS.

802.1QTag in the frame · IEEE 802.1Q
0481216202428
TPID16 bits0x8100
PCP3 bits0
DEI1 bit0
VLAN ID12 bits10
Each row has 32 bits (4 bytes), bit 0 on the left, as the RFCs draw their headers. Dashed: variable or optional. Point at a field for an explanation.
FieldLengthExample valueMeaning
TPID16 bits (2 bytes)0x8100Tag protocol identifier 0x8100: a VLAN tag follows instead of the EtherType.
PCP3 bits0Priority code point: priority 0 to 7 for quality of service (e.g. voice higher).
DEI1 bit0Drop eligible indicator: this frame may be dropped first when congested.
VLAN ID12 bits10VLAN number 1 to 4094 (0 and 4095 are reserved).
Values: Real frame from the demo “Router on a stick” (no. 7, 82 bytes), exactly as the packet list in leyoNET shows it.
Ethernet II + 802.1QFrame · IEEE 802.3, IEEE 802.1Q
Preamble7 bytes
SFD1 bytes
Destination MAC6 bytes02:00:00:00:01:00
Source MAC6 bytes02:00:00:00:03:00
TPID2 bytes0x8100
TCI2 bytes0x000a
EtherType2 bytes0x0800
Payload42–1500 bytes60 Byte
FCS4 bytes0xc04af1d0
Gap (IFG)12 bytes
Left to right, in the order the bytes are sent. Grey dashed: never part of a capture (layer 1 or line framing). Point at a field for an explanation.
FieldLengthExample valueMeaning
Preamble (layer 1)7 bytes10101010 × 7Seven bytes 10101010: the receiver synchronises its clock. Part of the physical layer.
SFD (layer 1)1 bytes10101011Start frame delimiter 10101011: the frame starts now.
Destination MAC6 bytes02:00:00:00:01:00To whom? FF:FF:FF:FF:FF:FF is broadcast, a first byte with the lowest bit set is multicast.
Source MAC6 bytes02:00:00:00:03:00From whom? The MAC address of the sending interface; the switch learns it.
TPID2 bytes0x8100Tag protocol identifier 0x8100: a VLAN tag follows instead of the EtherType.
TCI2 bytes0x000aTag control information: priority (PCP), DEI and VLAN ID, 16 bits together.
EtherType2 bytes0x0800What is inside: 0x0800 IPv4, 0x86DD IPv6, 0x0806 ARP, 0x8100 VLAN tag, 0x8864 PPPoE. Values from 0x0600 are types, smaller ones a length (IEEE 802.3).
Payload42–1500 bytes60 ByteThe layer-3 packet. Because of the 4-byte tag, 42 bytes are enough for the minimum length of 64 bytes.
FCS4 bytes0xc04af1d0Frame check sequence: CRC-32 over the whole frame from the destination MAC. If it does not match, the receiver drops the frame.
Gap (IFG) (layer 1)12 bytesAt least 12 bytes of silence before the next frame (interframe gap). Part of the physical layer.
Values: Real frame from the demo “Router on a stick” (no. 7, 82 bytes), exactly as the packet list in leyoNET shows it.

Routing between VLANs

  • Router on a stick: a router is connected to the switch with a trunk and has one subinterface per VLAN (eth0.10) that serves as the gateway.
  • Layer 3 switch: the switch routes itself via VLAN interfaces (SVIs), see Layer 3 switch.

Command line

Switch(config)# vlan 10
Switch(config-vlan)# name ADMIN
Switch(config)# interface range port1-4
Switch(config-if)# switchport access vlan 10
Switch(config)# interface port24
Switch(config-if)# switchport mode trunk
Switch(config-if)# switchport trunk allowed vlan 10,20
Switch# show vlan brief

In leyoNET VLANs with a colour tint the ports on the canvas, the front panel and in the rack; an area with a VLAN documents the network.

How to do it in leyoNET

The same text as in the app’s help (F1 key).

VLANs

VLANs split one switch into separate networks. An access port belongs to exactly one VLAN, a trunk carries several (Trunks).

Under Tools → VLANs each VLAN gets a name and a colour. The colour automatically tints every port of that VLAN on the canvas and in the port table. Between VLANs you need a router (Router on a stick) or a layer 3 switch.

Creating VLANs: a switch only forwards VLANs it knows (tab Switching → VLANs on this switch or vlan 20, name Training). Assigning a new VLAN to an access port creates it, as on Cisco. A switch in the middle with trunks only still needs the VLANs, otherwise it drops the frames (console: «VLAN 20 is not created»). no vlan 20 deletes a VLAN, its ports become inactive. Files before version 1.2 have no list: there all VLANs in use count as created.

Trunks

A trunk links switches (or switch and router) and carries several VLANs on one cable. Each frame gets an 802.1Q tag with the VLAN number; the native VLAN runs untagged.

Allowed VLANs: by default a trunk carries all created VLANs. With switchport trunk allowed vlan 10,20 only these; … add 30, … remove 10, … except 1, … all, … none. switchport trunk native vlan 99 changes the untagged VLAN (set it the same on both sides). show interfaces trunk shows allowed and active VLANs per trunk. In the form, native VLAN and allowed VLANs are in the port table.

Router on a stick

A router with a single cable to the switch routes between VLANs: the switch port is a trunk and the router has one subinterface per VLAN (e.g. eth0.10) with its own IP as gateway.

See an example

  • VLAN and spanning tree

    Three switches in a ring, two VLANs over trunks.

    STP blocks one port (orange), then the office reaches its second computer over the trunk with an 802.1Q tag.

    Watch live Project file

  • Demo “Router on a stick” in leyoNETDemo “Router on a stick” in leyoNET
    Router on a stick

    Two VLANs, one router with subinterfaces on the trunk.

    The packet goes tagged to the router (eth0.10) and comes out in the other VLAN (eth0.20).

    Watch live Project file

“Watch live” opens the network in leyoNET, the simulation runs in a loop. In the app you find it under File → Demo networks, ready to present.

Practise

  • ★★★☆☆ Separate networks with VLANs · 4 goals · Worksheet (German)
  • ★★☆☆☆ Document VLANs · 2 goals · Worksheet (German)
  • ★★★☆☆ Router-on-a-stick · 4 goals · Worksheet (German)
  • ★★☆☆☆ UE03 Port-based VLAN: two departments on one switch · 6 goals · Worksheet (German)
  • ★★★☆☆ UE04 Trunk VLAN: VLANs across two floors · 6 goals · Worksheet (German)
  • ★★★☆☆ Extra 2: management VLAN and native VLAN · 4 goals · Worksheet (German)
  • ★★★★★ Final exercise: set up an office · 10 goals · Worksheet (German)

In leyoNET under Tools → Exercise catalogue. Every exercise checks itself.

What leyoNET simplifies

ProtocolLayerSimplification in the simulation
Ethernet II, 802.1Q2With FCS (CRC-32) and padding to 64 bytes; preamble, SFD and gap only as information on layer 1; no jumbo frames

Standards

  • IEEE 802.1Q – Bridges and Bridged Networks (current edition: IEEE 802.1Q-2022)
  • IEEE 802.3 – IEEE Standard for Ethernet (current edition: IEEE 802.3-2022)

Read on

Found a mistake or have an idea? Source of this page on GitHub.