VLAN (Virtual Local Area Network)
What it is for
By default every port on a switch is in one broadcast domain: a broadcast from any host reaches the hosts on all other ports.
A VLAN (802.1Q) inserts a 4-byte tag into the frame, dividing one physical switch into several logical switches that cannot reach each other at layer 2. Each VLAN is a separate broadcast domain.
Where the tag is added and removed
· Access port: the frame is untagged; the host is unaware of VLANs;
· Entering the switch: a tag is added according to the VLAN of the ingress port;
· On a trunk: the frame travels tagged, and the far-end switch uses the tag to tell which VLAN it belongs to;
· Leaving an access port: the tag is removed before the frame goes to the host.
So a capture on the host side shows no tag; only a capture on the trunk does.
Common misconceptions
Traffic between VLANs must pass through a layer-3 device (a router or L3 switch). Different VLANs are different broadcast domains and usually different subnets.
The number of VLANs is limited. The VID is only 12 bits, so 1-4094 are usable. That was not enough for carrier networks, which is why QinQ exists.
Native-VLAN frames on a trunk are untagged. If the two ends use different native VLANs, an untagged frame is placed into the far end's native VLAN, so the traffic ends up in the wrong VLAN.