Switching is how a network moves data from an input to the right output. This lesson starts with the three classic switching techniques, then moves to the Ethernet switch you will configure in practice: VLANs to split one switch into many networks, Spanning Tree to stop loops, and LACP to bundle several cables into one faster, redundant link.
Three switching techniques
| Technique | How it works | Pros | Cons | Example |
|---|---|---|---|---|
| Circuit switching | A dedicated path is set up before data flows and held until the end | Fixed bandwidth, constant delay | Capacity wasted when silent; setup time | Classic telephone network |
| Message switching | Each whole message is stored at a node, then forwarded (store and forward) | No setup | Big delays, large buffers needed | Old telegraph and early email relays |
| Packet switching | Messages are split into packets that are forwarded independently | Efficient sharing, survives failures | Variable delay, packets can be lost or reordered | The internet |
Packet switching comes in two styles: datagram (each packet is routed on its own, like IP) and virtual circuit (a path is set up first and packets follow it with a short label, like MPLS or the old ATM and Frame Relay networks).
How an Ethernet switch forwards
For every incoming frame, the switch:
- Learns: records the source MAC and the port it came in on.
- Looks up the destination MAC in its table.
- Forwards to that one port if known; floods to all ports in the VLAN if unknown, broadcast or most multicast.
- Filters: if the destination is on the same port it came from, it drops the frame.
Entries age out after about 300 seconds of silence, so moved devices are relearned.
Switches either use store-and-forward (receive the whole frame, check the CRC, then send; the norm today) or cut-through (start sending once the destination address is read; lower latency, used in trading and HPC networks, but forwards corrupted frames).
Broadcast domains and why VLANs exist
Every device on the same layer 2 network receives every broadcast: ARP requests, DHCP discovers, and plenty of chatty discovery protocols. A flat network with 2,000 devices drowns in that noise, and any device can reach any other directly, which is bad for security.
A VLAN (virtual LAN) splits one physical switch into several isolated layer 2 networks. Devices in VLAN 10 never see frames from VLAN 20, even on the same switch. Typical splits: staff, guests, servers, phones, cameras, management.
802.1Q tags, access and trunk ports
When frames from several VLANs share one cable, a 4-byte 802.1Q tag is inserted after the source MAC. It holds a 12-bit VLAN ID (1 to 4094 usable) and a 3-bit priority (PCP) used by QoS.
| Port type | Carries | Tags | Connects to |
|---|---|---|---|
| Access | One VLAN | Untagged; the switch adds and removes the tag internally | PCs, printers, cameras |
| Trunk | Many VLANs | Tagged, except the native VLAN which travels untagged | Other switches, routers, hypervisors, APs |
A Cisco-style configuration looks like this:
interface Gi0/5
switchport mode access
switchport access vlan 20
!
interface Gi0/48
switchport mode trunk
switchport trunk allowed vlan 10,20,30
Linux can tag frames too, which is how a server joins several VLANs over one cable:
$ sudo ip link add link enp3s0 name enp3s0.20 type vlan id 20
$ sudo ip addr add 10.20.0.15/24 dev enp3s0.20
$ sudo ip link set enp3s0.20 up
$ ip -d link show enp3s0.20 | grep vlan
vlan protocol 802.1Q id 20 <REORDER_HDR>
To confirm tags on the wire, tcpdump -e prints them:
$ sudo tcpdump -i enp3s0 -e -nn -c 1 vlan 20
10:41:07.202113 3c:2c:4a:1b:9c:10 > ff:ff:ff:ff:ff:ff, ethertype 802.1Q (0x8100), length 46: vlan 20, p 0, ethertype ARP (0x0806), Request who-has 10.20.0.1 tell 10.20.0.15, length 28
Inter-VLAN routing
VLANs are separate networks, so traffic between them must be routed. Two common designs:
- Router on a stick: one router port configured as a trunk with a sub-interface per VLAN. Cheap, but all inter-VLAN traffic crosses one link.
- Layer 3 switch: the switch has a virtual interface (SVI) per VLAN acting as each VLAN’s gateway and routes in hardware. This is the norm in offices and data centers.
The router or L3 switch is also where you put firewall rules, for example “guests may reach the internet but not the servers VLAN”.
Spanning Tree Protocol (STP)
Redundant links between switches are good for uptime but deadly at layer 2: Ethernet frames have no TTL, so a broadcast caught in a loop circles forever and multiplies, a broadcast storm that can take down a whole site in seconds.
STP (802.1D) and its faster successors RSTP (802.1w) and MSTP (802.1s) prevent this. Switches elect a root bridge (lowest bridge ID), compute the shortest path to it, and block any port that would create a loop. If an active link fails, a blocked port takes over. RSTP converges in about a second instead of the 30 to 50 seconds of classic STP.
Two settings you should always know:
- PortFast / edge port: skip the listening phase on ports to end devices, so PCs get a link immediately.
- BPDU Guard: shut down an edge port if a switch appears on it, which stops someone’s desk switch from creating a loop.
Modern data centers avoid STP altogether with routed leaf-spine fabrics (every link is layer 3) or MLAG/EVPN.
Link aggregation and LACP
Link aggregation bundles several physical links into one logical link (a port channel, LAG or bond). Two 10 Gbit/s links become one 20 Gbit/s link that survives if either cable fails. LACP (802.3ad, now 802.1AX) is the protocol both ends use to agree on which links belong to the bundle and to detect failed members.
One flow, one link: a LAG balances by hashing addresses and ports, so a single TCP connection always uses one member link. Two 10G links give 20G total across many flows, but one big file copy still tops out at 10G.
On Linux, a bond is built like this:
$ sudo ip link add bond0 type bond mode 802.3ad lacp_rate fast xmit_hash_policy layer3+4
$ sudo ip link set enp65s0f0 down && sudo ip link set enp65s0f0 master bond0
$ sudo ip link set enp65s0f1 down && sudo ip link set enp65s0f1 master bond0
$ sudo ip link set bond0 up
$ grep -E 'Mode|MII Status|Aggregator ID' /proc/net/bonding/bond0
Bonding Mode: IEEE 802.3ad Dynamic link aggregation
MII Status: up
Aggregator ID: 1
MII Status: up
Aggregator ID: 1
MII Status: up
Aggregator ID: 1
Both members reporting the same Aggregator ID means LACP agreed with the switch. Different IDs mean the switch side is misconfigured.
Exercise
Two PCs are plugged into the same switch but one is in VLAN 10 and the other in VLAN 20. What do they need to talk to each other?
Show answer
Answer: C. VLANs are separate layer 2 networks, so traffic between them must be routed, either by a router-on-a-stick or by SVIs on a layer 3 switch.
Exercise
What problem does Spanning Tree Protocol solve?
Show answer
Answer: D. Ethernet frames have no TTL, so loops are fatal at layer 2. STP blocks redundant ports and unblocks them when an active path fails.
Exercise
A server has a 2 × 10 Gbit/s LACP bond. A single large scp copy runs at about 9.4 Gbit/s. Why not 20?
Show answer
Answer: A. Link aggregation balances flows, not packets, so each connection stays on one member. Many parallel flows can use the full 20 Gbit/s.
Key takeaways
- Circuit switching reserves a path; packet switching shares links; the internet uses datagram packet switching.
- Switches learn source MACs, forward known destinations and flood unknown ones.
- VLANs split broadcast domains; 802.1Q tags carry many VLANs over one trunk.
- Traffic between VLANs must be routed.
- STP blocks loops; LACP bundles links for capacity and redundancy, one flow per member.
FAQ
What is the native VLAN?
The one VLAN on a trunk whose frames travel untagged. Both ends must agree on it. Many teams set it to an unused VLAN so that untagged traffic cannot slip into a real network.
How many VLANs can I have?
The 12-bit VLAN ID allows 4,094 usable VLANs. Cloud providers needed far more tenant networks, which is why they use VXLAN, with a 24-bit ID and about 16 million segments, tunneled over IP.
Is a VLAN a security boundary?
It is a useful one, but not a firewall. Misconfigured trunks and native VLANs have allowed “VLAN hopping” attacks. Combine VLANs with filtering at the router or firewall.
What is the difference between a bond and a bridge on Linux?
A bond joins several NICs into one logical link to the same switch. A bridge is a software switch that connects several interfaces, such as VM or container ports, into one LAN.