tc

Traffic control utility for configuring Linux kernel packet scheduling, shaping, policing, and filtering. Core tool for bandwidth management and advanced QoS (Quality of Service).

Category: Networking QoS Traffic Shaping Kernel Advanced

What it does

tc (Traffic Control) configures packet queuing disciplines (qdisc), classes, filters, and policing rules in the Linux kernel. It allows precise bandwidth shaping, prioritization, and rate limiting on network interfaces.

How it works (mechanical)

The Linux kernel networking stack includes a traffic scheduler. tc configures:

  • Queueing disciplines (qdisc) — scheduling algorithms
  • Classes — bandwidth subdivisions
  • Filters — traffic classification rules
  • Policers — rate enforcement mechanisms

Rules attach to interfaces (e.g., eth0) and operate on outgoing (egress) or incoming (ingress) traffic.

10 Practical Examples

# 1) Show qdisc configuration
tc qdisc show
# 2) Show statistics for interface
tc -s qdisc show dev eth0
# 3) Add simple rate limit (Token Bucket Filter)
sudo tc qdisc add dev eth0 root tbf rate 1mbit burst 32kbit latency 400ms
# 4) Delete existing qdisc
sudo tc qdisc del dev eth0 root
# 5) Add HTB root qdisc
sudo tc qdisc add dev eth0 root handle 1: htb default 10
# 6) Create traffic class under HTB
sudo tc class add dev eth0 parent 1: classid 1:10 htb rate 2mbit ceil 5mbit
# 7) Add filter to match specific IP
sudo tc filter add dev eth0 protocol ip parent 1: prio 1 u32 match ip dst 192.168.1.50 flowid 1:10
# 8) Add ingress qdisc
sudo tc qdisc add dev eth0 handle ffff: ingress
# 9) Police inbound traffic
sudo tc filter add dev eth0 parent ffff: protocol ip prio 50 u32 match ip src 0.0.0.0/0 police rate 1mbit burst 10k drop
# 10) Flush all qdisc settings
sudo tc qdisc del dev eth0 root
sudo tc qdisc del dev eth0 ingress

Notes & Gotchas

  • Complex configurations can become difficult to debug.
  • Rules are not persistent unless scripted or saved.
  • Requires root privileges.
  • Misconfiguration can disrupt connectivity.
  • HTB is commonly used; TBF is simpler for basic shaping.

Historical Context

tc is part of the iproute2 suite and replaced older traffic shaping tools from the 2.2 kernel era. It remains the foundational Linux traffic shaping utility used in routers, firewalls, and enterprise networking.

Modern Equivalent / Related Tools

  • ip — general networking control
  • nftables / iptables — firewall and packet filtering
  • wondershaper — simplified bandwidth control wrapper
  • systemd-networkd — may configure traffic control rules