linuxlab.io
Tutorials▾
  • Linux & networking
    File system, processes, TCP/IP, BGP and OSPF
    →
  • Terraform & IaC
    HCL, state, plan/apply on a LocalStack sandbox
    →
  • Git & GitHub
    Object model, plumbing, branching, GitHub Actions
    →
All tutorials →
PricingAboutSign inCreate account
/
  • Introduction
  • Lessons
  • How it works
  • Simulator
  • Knowledge base
  • Interview prep
Index
Categories
All entries
Footer
linuxlab-TutorialsPricingAboutPrivacy & cookies
Copyright © 2026 LinuxLab. All rights reserved.
home/linux/kb/Commands/cmd-tc

kb/commands ── Commands ── advanced

tc: traffic control

`tc` manages packet queues on network interfaces: bandwidth limits, delay, loss, and classification. Part of iproute2.

view as markdownaka: traffic-control, qdisc

Core concepts

  • qdisc (queueing discipline): the queue rule on an interface. Every interface always has a qdisc. The default is pfifo_fast or fq_codel.
  • class: a hierarchy inside a qdisc (for splitting bandwidth between traffic types)
  • filter: what goes into which class (matched by port, IP, or mark)

Viewing queues

bash
tc qdisc show                        # qdisc on all interfaces
tc qdisc show dev eth0
tc -s qdisc show dev eth0            # -s: with statistics (bytes, packets, dropped)
tc class show dev eth0
tc filter show dev eth0

netem: simulating a bad network

The most common use case for CI and chaos testing:

bash
sudo tc qdisc add dev eth0 root netem delay 200ms
sudo tc qdisc add dev eth0 root netem delay 100ms 20ms       # +-20ms jitter
sudo tc qdisc add dev eth0 root netem loss 5%
sudo tc qdisc add dev eth0 root netem corrupt 1%
sudo tc qdisc add dev eth0 root netem duplicate 1%
sudo tc qdisc add dev eth0 root netem reorder 25% 50%
# Combine multiple effects at once:
sudo tc qdisc replace dev eth0 root netem delay 50ms loss 1%
# Remove:
sudo tc qdisc del dev eth0 root

To verify the effect, ping through the interface and watch for retransmits in cmd-ss -ti.

tbf: bandwidth limiting

Token Bucket Filter is a straightforward rate limiter:

bash
sudo tc qdisc add dev eth0 root tbf rate 1mbit burst 32kbit latency 400ms

▸1 Mbit/s outgoing, queue up to 400ms

htb: hierarchical bandwidth sharing

bash
# 100Mbit on the interface, split: 70 for class 1:10, 30 for 1:20
sudo tc qdisc add dev eth0 root handle 1: htb default 20
sudo tc class add dev eth0 parent 1: classid 1:1 htb rate 100mbit
sudo tc class add dev eth0 parent 1:1 classid 1:10 htb rate 70mbit ceil 100mbit
sudo tc class add dev eth0 parent 1:1 classid 1:20 htb rate 30mbit ceil 100mbit
# Route traffic: SSH (port 22) goes to the premium class
sudo tc filter add dev eth0 parent 1: protocol ip prio 1 \
  u32 match ip dport 22 0xffff flowid 1:10

Applying to loopback (for local tests)

netem on lo is the fastest way to run chaos tests locally, without building a network topology:

bash
sudo tc qdisc add dev lo root netem delay 200ms
ping -c 3 127.0.0.1  

▸RTT is now ~200ms

sudo tc qdisc del dev lo root

Capability

All tc add/del operations require CAP_NET_ADMIN. In containers, add --cap-add=NET_ADMIN.

§ команды

bash
tc -s qdisc show dev eth0

Current qdisc with statistics (dropped/overlimits indicate congestion)

bash
sudo tc qdisc add dev eth0 root netem delay 100ms loss 1%

Simulate a bad network: delay plus packet loss (for testing)

bash
sudo tc qdisc replace dev eth0 root netem rate 10mbit

Hard limit of 10 Mbit/s. replace creates the rule if absent, or updates it if present.

bash
sudo tc qdisc del dev eth0 root

Remove all rules and restore the default qdisc

bash
sudo tc -s -d qdisc show dev eth0

Verbose output with detailed statistics and qdisc parameters

§ см. также

  • routing-tableRouting tableThe routing table lists where to send packets for each destination. The longest matching prefix wins.
  • cmd-ipip: Swiss army knife for network configuration`ip` is the iproute2 frontend that replaces the old ifconfig, route, and arp tools. Subcommands: `ip addr` (addresses), `ip link` (interfaces), `ip route` (routing table), `ip neigh` (ARP).
  • tcp-statesTCP states (LISTEN, ESTABLISHED, TIME_WAIT)A TCP session moves through 11 states from LISTEN to CLOSED. The most important in production: LISTEN, ESTABLISHED, TIME_WAIT, CLOSE_WAIT.
Footer
linuxlab-
Copyright © 2026 LinuxLab. All rights reserved.
Tutorials
Pricing
About
Privacy & cookies