tc · Linux command

Also known as: traffic control

On this page 7

tc is the Linux command for traffic control, the iproute2 utility that configures how the kernel queues, schedules, shapes and drops network packets on each interface. In Linux networking, it is the main administrative interface to the kernel packet scheduler, used to limit bandwidth, prioritize latency-sensitive traffic, emulate poor networks and attach programmable filters.

Where tools such as nftables decide whether a packet is allowed, tc decides when and in what order packets leave an interface. It belongs to the same iproute2 package as the ip command and follows a similar object-based syntax built around three concepts: queuing disciplines, classes and filters.

How tc controls the kernel packet scheduler

Every network interface in Linux has a queuing discipline, or qdisc, attached to its egress path. When the kernel sends a packet, it enqueues it into this qdisc, and the qdisc decides when to dequeue it toward the driver. tc replaces or tunes that qdisc and, for classful qdiscs, builds a tree of classes that divides bandwidth among traffic groups.

Objects are identified by handles in the major:minor form, such as 1: for a root qdisc and 1:10 for one of its classes. Filters attached to a qdisc or class inspect packets and assign them to a class, using matches on addresses, ports, firewall marks or eBPF programs.

The following table summarizes the building blocks that a tc configuration combines.

ObjectFunctionExample command
QdiscQueues and schedules packets on an interfacetc qdisc add dev eth0 root fq_codel
ClassSubdivides a classful qdisc with its own rate or prioritytc class add dev eth0 parent 1: classid 1:10 htb rate 50mbit
FilterClassifies packets into classestc filter add dev eth0 parent 1: protocol ip u32 match ip dport 22 0xffff flowid 1:10
ActionModifies, drops, mirrors or redirects matched packetsaction mirred egress redirect dev ifb0
HandleIdentifies an object in the tree1:, 1:10, ffff:
Core tc objects

An important limitation is that shaping applies mainly to egress traffic. The ingress side offers only a simple ingress or clsact hook for policing and filtering. To shape incoming traffic, administrators redirect it to an Intermediate Functional Block (IFB) device and apply a qdisc on that device’s egress path.

Common queuing disciplines

The choice of qdisc determines whether tc limits rate, enforces priority or reduces latency. Classless qdiscs treat all packets on an interface in one structure, while classful qdiscs host a hierarchy of classes with separate rules.

QdiscTypeTypical purpose
fq_codelClasslessDefault on many distributions, fights bufferbloat with fair queuing and CoDel
HTBClassfulHierarchical bandwidth guarantees and ceilings per class
TBFClasslessSimple rate limit with a token bucket
netemClasslessEmulates delay, jitter, loss, duplication and reordering
fqClasslessPer-flow pacing, often paired with BBR congestion control
CAKEClasslessAll-in-one shaper for home and edge links
prioClassfulStrict priority bands without rate limits
mqprio and taprioClassfulHardware queue mapping and time-aware scheduling
Frequently used qdiscs

HTB (Hierarchical Token Bucket) is the usual choice for multi-class bandwidth sharing. Each class receives a guaranteed rate and may borrow up to a ceil value when parent capacity is idle. Leaf classes generally carry their own qdisc, often fq_codel to keep queues short.

tc is often confused with firewall tools because both inspect packets, but its job is scheduling rather than access control. The table places it among neighboring utilities.

ToolMain roleRelation to tc
tcQueuing, shaping, policing, emulationConfigures the packet scheduler
ip commandAddresses, links, routesSame iproute2 package, similar syntax
nftables and iptablesFiltering and NATCan set firewall marks that tc filters match
ethtoolNIC driver and hardware settingsControls ring buffers and offloads that affect tc results
tcpdumpPacket captureUsed to verify the effect of tc rules
tc and neighboring networking tools

A common pattern combines tools: nftables marks packets by application or user, and a tc fw filter places marked packets into HTB classes. Modern setups increasingly attach eBPF programs through the clsact hook, which gives programmable classification at high speed and is used by container networking projects such as Cilium.

Typical tc tasks and commands

Most practical tc work falls into a handful of recurring tasks, from inspecting statistics to emulating a slow mobile link. The decision table below links each goal to a suitable approach.

GoalRecommended approachReason
Cap upload bandwidthTBF or HTB root with a single classSimple and predictable rate limit
Guarantee bandwidth per serviceHTB tree with filters by port or markRate and ceiling per class
Reduce latency under loadfq_codel or CAKE on the bottleneckKeeps queues short
Test an application on a bad networknetem with delay and lossReproducible impairment
Shape downloadsIFB device with HTB or CAKEIngress cannot be shaped directly
Choosing a tc approach

To inspect the current state, tc -s qdisc show dev eth0 prints counters for sent bytes, drops, overlimits and backlog, which reveal whether a shaper is actually limiting traffic. A netem test such as tc qdisc add dev eth0 root netem delay 100ms 20ms loss 1% adds an average of 100 ms delay with 20 ms jitter and 1 percent loss, and tc qdisc del dev eth0 root restores the default.

Pitfalls when using tc

tc rules are not persistent across reboots and are lost when an interface is recreated. They must be reapplied by a script, a systemd unit or a network manager integration such as systemd-networkd, which supports several qdiscs in its configuration files.

  • Shaping must happen at the real bottleneck; limiting a 1 Gbit interface does nothing if the upstream modem queue fills first, so set the rate slightly below the true link speed
  • Offloads such as GSO and TSO create large aggregated packets that distort token bucket accounting at low rates
  • Applying netem on a remote server’s only interface can lock out the SSH session that configured it
  • Unclassified traffic in HTB falls to the default class, and an omitted default can leave traffic unshaped

The short version

Think of a network connection as a single checkout lane in a busy shop. tc is the store manager who organizes the line. The manager decides who goes first and how many customers pass per minute.

With it, a Linux machine can keep a video call smooth during a large download. It can stop one service from taking all the bandwidth. It can even slow itself down on purpose to test software on a weak connection. The key idea is simple: tc controls the order and pace of outgoing traffic.

Where it makes a difference

A small company runs its backups, voice phones and office traffic through a Linux router on a 100 Mbit/s upload link. Every evening the nightly backup saturates the link and phone calls become choppy, because packets wait behind large backup transfers in a long queue.

The administrator installs an HTB tree with a root rate of 95 Mbit/s, just under the real link speed. A voice class receives a guaranteed 10 Mbit/s and top priority, office traffic gets 50 Mbit/s with a ceiling of 95, and backups get 20 Mbit/s that can borrow unused capacity. nftables marks packets by port, tc fw filters sort them, and each leaf runs fq_codel. Afterward, tc -s class show confirms the backup class absorbing all drops, and call quality stays clear during backups that still finish before morning.