In this lesson, you will learn how to implement policy-based Quality of Service (QoS) in Linux to ensure real-time VoIP and video traffic avoids the "bottleneck trap" caused by bulk data transfers.
The QoS Challenge
On a standard Linux network interface, packets are usually handled on a first-come, first-served basis via the pfifo_fast queueing discipline. While efficient for general traffic, this is disastrous for VoIP or video conferencing. If a large file download (bulk data) is saturating the buffer, your voice packets get stuck behind massive TCP segments, leading to jitter, latency, and packet loss.
Traffic Prioritization with tc
To solve this, we move beyond simple queuing and implement Class-Based Queueing (CBQ) or Hierarchical Token Bucket (HTB). The goal is to classify packets by their requirements and assign them to specific traffic classes.
For real-time streams, we define a "Priority" class that is serviced before the "Best Effort" class. We use tc (Traffic Control) to mark and route traffic based on Differentiated Services Code Point (DSCP) bits:
# Create an HTB qdisc on eth0
tc qdisc add dev eth0 root handle 1: htb default 12
# Create a high-priority class for VoIP/Video (Guaranteed bandwidth)
tc class add dev eth0 parent 1: classid 1:1 htb rate 10mbit ceil 20mbit prio 1
# Create a bulk data class (Low priority)
tc class add dev eth0 parent 1: classid 1:2 htb rate 50mbit ceil 100mbit prio 3
# Filter VoIP traffic (marked with DSCP EF) into the high-priority class
tc filter add dev eth0 protocol ip parent 1: prio 1 u32 match ip tos 0xb8 0xfc flowid 1:1
How it Works
- Classification: The
tc filteridentifies VoIP traffic (often tagged with DSCP0xb8orEF- Expedited Forwarding). - Prioritization: By assigning
prio 1to the VoIP class andprio 3to bulk data, the kernel’s scheduler ensures that even when the link is congested, the1:1class is drained first. - Bandwidth Management:
ceilallows the VoIP stream to "borrow" unused bandwidth, but ensures that bulk data cannot starve the real-time streams.
Key Takeaway: By implementing hierarchical queuing disciplines, you transform the Linux kernel from a passive packet-pusher into an active traffic orchestrator that protects latency-sensitive VoIP and video flows from bulk data congestion.