TC(8)
๐ TC(8) ๐
okay so bestie, this is TC(8) from Linux โ the manual page for tc, aka the traffic control tool ๐ซถ if you've ever wanted to tell your kernel "slow this down", "prioritize this", or "honestly? drop that", you are in the right place. let's go โจ
๐ธ NAME ๐ธ
tcโ show / manipulate traffic control settings ๐
๐ SYNOPSIS ๐
tc [ OPTIONS ] qdisc [ add | change | replace | link | delete ] dev DEV
[ parent qdisc-id | root ] [ handle qdisc-id ] [ ingress_block BLOCK_INDEX ]
[ egress_block BLOCK_INDEX ] qdisc [ qdisc specific parameters ]
tc [ OPTIONS ] class [ add | change | replace | delete | show ] dev DEV
parent qdisc-id [ classid class-id ] qdisc [ qdisc specific parameters ]
tc [ OPTIONS ] filter [ add | change | replace | delete | get ] dev DEV
[ parent qdisc-id | root ] [ handle filter-id ] protocol protocol prio priority
filtertype [ filtertype specific parameters ] flowid flow-id
tc [ OPTIONS ] filter [ add | change | replace | delete | get ] block BLOCK_INDEX
[ handle filter-id ] protocol protocol prio priority filtertype
[ filtertype specific parameters ] flowid flow-id
tc [ OPTIONS ] chain [ add | delete | get ] dev DEV [ parent qdisc-id | root ]
filtertype [ filtertype specific parameters ]
tc [ OPTIONS ] chain [ add | delete | get ] block BLOCK_INDEX filtertype
[ filtertype specific parameters ]
tc [ OPTIONS ] [ FORMAT ] qdisc { show | list } [ dev DEV ]
[ root | ingress | handle QHANDLE | parent CLASSID ] [ invisible ]
tc [ OPTIONS ] [ FORMAT ] class show dev DEV
tc [ OPTIONS ] filter show dev DEV
tc [ OPTIONS ] filter show block BLOCK_INDEX
tc [ OPTIONS ] chain show dev DEV
tc [ OPTIONS ] chain show block BLOCK_INDEX
tc [ OPTIONS ] monitor [ file FILENAME ]
OPTIONS := { [ -force ] -b[atch] [ filename ] | [ -n[etns] name ] | [ -N[umeric] ] |
[ -nm | -nam[es] ] | [ { -cf | -c[onf] } [ filename ] ] [ -t[imestamp] ] |
[ -t[short] | [ -o[neline] ] | [ -echo ] }
FORMAT := { -s[tatistics] | -d[etails] | -r[aw] | -i[ec] | -g[raph] | -j[son] |
-p[retty] | -col[or] }
so yeah, OPTIONS and FORMAT are both little bundles of choices, and the bracket situation is giving "pick whichever ones you want". ๐
โจ DESCRIPTION โจ
Tc is used to configure Traffic Control in the Linux kernel. and Traffic Control, bestie, consists of the following four iconic behaviours:
๐ฆ SHAPING
when traffic is shaped, its rate of transmission is under control. and shaping is highkey more than just lowering the available bandwidth โ it's also used to smooth out bursts in traffic for better network behaviour. shaping happens on egress. ๐ค
โฐ SCHEDULING
by scheduling the transmission of packets, it's possible to improve interactivity for the traffic that needs it, while still guaranteeing bandwidth to bulk transfers. reordering is also called prioritizing, and it happens only on egress.
๐ฎ POLICING
whereas shaping deals with transmission of traffic, policing pertains to traffic arriving. so policing occurs on ingress. ๐ฅ
๐ DROPPING
traffic exceeding a set bandwidth may also be dropped forthwith โ both on ingress and on egress. no thoughts, just gone.
so the processing of traffic is controlled by three kinds of objects: qdiscs, classes and filters. that's the whole cast. ๐ซถ
๐ QDISCS ๐
qdisc is short for 'queueing discipline' and it is elementary to understanding traffic control. whenever the kernel needs to send a packet to an interface, it gets enqueued to the qdisc configured for that interface. immediately afterwards, the kernel tries to get as many packets as possible from the qdisc, so it can hand them over to the network adaptor driver. it's giving "inbox zero, but for packets". ๐ฌ
a simple QDISC is the pfifo one, which does no processing at all and is a pure First In, First Out queue. it does however store traffic when the network interface can't handle it momentarily. it's the chill one. ๐
๐งบ CLASSES ๐งบ
some qdiscs can contain classes, which contain further qdiscs โ traffic may then be enqueued in any of the inner qdiscs, which are within the classes. when the kernel tries to dequeue a packet from such a classful qdisc, it can come from any of the classes. a qdisc may for example prioritize certain kinds of traffic by trying to dequeue from certain classes before others. so some classes are simply the main characters. ๐
๐ FILTERS ๐
a filter is used by a classful qdisc to determine in which class a packet will be enqueued. whenever traffic arrives at a class with subclasses, it needs to be classified. various methods may be employed to do so, and one of these are the filters. all filters attached to the class are called, until one of them returns with a verdict. if no verdict was made, other criteria may be available โ and this differs per qdisc.
โ ๏ธ it is important to notice that filters reside within qdiscs โ they are not masters of what happens. filters are the vibe consultants, not the CEO. ๐
the available filters are:
basicโ filter packets based on an ematch expression. seetc-ematch(8)for details. ๐bpfโ filter packets using (e)BPF, seetc-bpf(8)for details.cgroupโ filter packets based on the control group of their process. seetc-cgroup(8)for details.flow,flowerโ flow-based classifiers, filtering packets based on their flow (identified by selectable keys). seetc-flow(8)andtc-flower(8)for details. ๐ธfwโ filter based onfwmark. directly mapsfwmarkvalue to traffic class. seetc-fw(8).routeโ filter packets based on routing table. seetc-route(8)for details.u32โ generic filtering on arbitrary packet data, assisted by syntax to abstract common operations. seetc-u32(8)for details.matchallโ traffic control filter that matches every packet. seetc-matchall(8)for details. it's the "yes, all of you, come in" of filters. ๐ซถ
โก QEVENTS โก
qdiscs may invoke user-configured actions when certain interesting events take place in the qdisc. each qevent can either be unused, or can have a block attached to it. to this block are then attached filters using the "tc block BLOCK_IDX" syntax. the block is executed when the qevent associated with the attachment point takes place. for example, a packet could be dropped, or delayed, etc., depending on the qdisc and the qevent in question. it's the qdisc's way of going "not me watching this happen ๐" and then doing something about it.
for example:
tc qdisc add dev eth0 root handle 1: red limit 500K avpkt 1K \
qevent early_drop block 10
tc filter add block 10 matchall action mirred egress mirror dev eth1
๐ CLASSLESS QDISCS ๐
the classless qdiscs are:
chokeโ CHOKe (CHOose and Keep for responsive flows, CHOose and Kill for unresponsive flows) is a classless qdisc designed to both identify and penalize flows that monopolize the queue. CHOKe is a variation of RED, and the configuration is similar to RED.codelโ CoDel (pronounced "coddle") is an adaptive "no-knobs" active queue management algorithm (AQM) scheme that was developed to address the shortcomings of RED and its variants.[p|b]fifoโ simplest usable qdisc, pure First In, First Out behaviour. limited in packets or in bytes.fqโ Fair Queue Scheduler realises TCP pacing and scales to millions of concurrent flows per qdisc. ๐ฅfq_codelโ Fair Queuing Controlled Delay is a queuing discipline that combines Fair Queuing with the CoDel AQM scheme. FQ_Codel uses a stochastic model to classify incoming packets into different flows and is used to provide a fair share of the bandwidth to all the flows using the queue. each such flow is managed by the CoDel queuing discipline. reordering within a flow is avoided since Codel internally uses a FIFO queue.fq_pieโ FQ-PIE (Flow Queuing with Proportional Integral controller Enhanced) is a queuing discipline that combines Flow Queuing with the PIE AQM scheme. FQ-PIE uses a Jenkins hash function to classify incoming packets into different flows and is used to provide a fair share of the bandwidth to all the flows using the qdisc. each such flow is managed by the PIE algorithm.gredโ Generalized Random Early Detection combines multiple RED queues in order to achieve multiple drop priorities. this is required to realize Assured Forwarding (RFC 2597).hhfโ Heavy-Hitter Filter differentiates between small flows and the opposite, heavy-hitters. the goal is to catch the heavy-hitters and move them to a separate queue with less priority, so that bulk traffic does not affect the latency of critical traffic. goodbye to the people hogging the aux cord ๐งingressโ this is a special qdisc as it applies to incoming traffic on an interface, allowing for it to be filtered and policed.mqprioโ the Multiqueue Priority Qdisc is a simple queuing discipline that allows mapping traffic flows to hardware queue ranges using priorities and a configurable priority to traffic class mapping. a traffic class in this context is a set of contiguous qdisc classes which map 1:1 to a set of hardware exposed queues.multiqโ Multiqueue is a qdisc optimized for devices with multiple Tx queues. it has been added for hardware that wishes to avoid head-of-line blocking. it will cycle through the bands and verify that the hardware queue associated with the band is not stopped prior to dequeuing a packet.netemโ Network Emulator is an enhancement of the Linux traffic control facilities that allow one to add delay, packet loss, duplication and more other characteristics to packets outgoing from a selected network interface. chaos mode: enabled ๐ญpfifo_fastโ standard qdisc for 'Advanced Router' enabled kernels. consists of a three-band queue which honors Type of Service flags, as well as the priority that may be assigned to a packet.pieโ Proportional Integral controller-Enhanced (PIE) is a control theoretic active queue management scheme. it is based on the proportional integral controller but aims to control delay.redโ Random Early Detection simulates physical congestion by randomly dropping packets when nearing configured bandwidth allocation. well suited to very large bandwidth applications.sfbโ Stochastic Fair Blue is a classless qdisc to manage congestion based on packet loss and link utilization history while trying to prevent non-responsive flows (i.e. flows that do not react to congestion marking or dropped packets) from impacting performance of responsive flows. unlike RED, where the marking probability has to be configured, BLUE tries to determine the ideal marking probability automatically. it's the self-sufficient one. โจsfqโ Stochastic Fairness Queueing reorders queued traffic so each 'session' gets to send a packet in turn. take turns bestie, it's not that hard ๐tbfโ the Token Bucket Filter is suited for slowing traffic down to a precisely configured rate. scales well to large bandwidths.
๐ ๏ธ CONFIGURING CLASSLESS QDISCS ๐ ๏ธ
in the absence of classful qdiscs, classless qdiscs can only be attached at the root of a device. full syntax:
tc qdisc add dev DEV root QDISC QDISC-PARAMETERS
to remove, issue:
tc qdisc del dev DEV root
๐ก thepfifo_fastqdisc is the automatic default in the absence of a configured qdisc. so if you never touched anything, congrats, you've been runningpfifo_fastthis whole time.
๐ CLASSFUL QDISCS ๐
bestie the classful qdiscs are the ones with actual classes inside, and here's the whole lineup:
ATMโ maps flows onto virtual circuits of an underlying asynchronous transfer mode device. it's giving vintage networking, but okay ๐DRRโ the Deficit Round Robin Scheduler, aka a way more flexible glow-up of Stochastic Fairness Queuing. and here's the tea: unlike SFQ, there are no built-in queues โ you have to add classes yourself and then set up filters so packets get classified accordingly. this is genuinely useful, like, e.g. for usingREDqdiscs with different settings for particular traffic. also there's no default class โ if a packet can't be classified, it gets dropped. no home, no hope ๐ญETSโ merges the functionality ofPRIOandDRRqdiscs into one single scheduler. it makes it easy to configure a set of strict and bandwidth-sharing bands to implement the transmission selection described in 802.1Qaz. one scheduler, two vibes, iconic โจHFSCโ Hierarchical Fair Service Curve. guarantees precise bandwidth and delay allocation for leaf classes, and allocates excess bandwidth fairly. unlikeHTB, it makes use of packet dropping to achieve low delays, which interactive sessions benefit from. lowkey the people-pleaser of schedulers ๐ซถHTBโ the Hierarchy Token Bucket, implementing a rich linksharing hierarchy of classes with an emphasis on conforming to existing practices. it facilitates guaranteeing bandwidth to classes, while also allowing you to specify upper limits to inter-class sharing. it contains shaping elements based onTBF, and it can prioritize classes. main character energy fr fr ๐PRIOโ a non-shaping container for a configurable number of classes which are dequeued in order. this allows for easy prioritization of traffic, where lower classes are only able to send if higher ones have no packets available. and to make configuration easier, Type Of Service bits are honored by default. the way it justโฆ works ๐QFQโ Quick Fair Queueing, an O(1) scheduler that provides near-optimal guarantees, and is the first to achieve that goal with a constant cost also with respect to the number of groups and the packet length. the QFQ algorithm has no loops, and uses very simple instructions and data structures that lend themselves very well to a hardware implementation. no loops, all vibes ๐ฆ
๐ง THEORY OF OPERATION ๐ง
okay so classes form a tree, where every class has a single parent. but a class may have multiple children. some qdiscs let you add classes at runtime (HTB), while others (PRIO) are created with a static number of children. no take-backsies on that one.
Qdiscs which allow dynamic addition of classes can have zero or more subclasses to which traffic may be enqueued.
Furthermore, each class contains a leaf qdisc which by default has pfifo behaviour, although another qdisc can be attached in place. This qdisc may again contain classes, but each class can have only one leaf qdisc. one leaf per class, that's the rule ๐
When a packet enters a classful qdisc it can be classified to one of the classes within. Three criteria are available, although not all qdiscs will use all three:
- tc filters โ if tc filters are attached to a class, they are consulted first for relevant instructions. Filters can match on all fields of a packet header, as well as on the firewall mark applied by
iptables. - Type of Service โ some qdiscs have built in rules for classifying packets based on the TOS field.
skb->priorityโ userspace programs can encode a class-id in theskb->priorityfield using theSO_PRIORITYoption.
Each node within the tree can have its own filters, but higher level filters may also point directly to lower classes. it's giving shortcuts, and we love that ๐
If classification did not succeed, packets are enqueued to the leaf qdisc attached to that class. Check qdisc specific manpages for details, however. not me giving you homework ๐
๐ท๏ธ NAMING ๐ท๏ธ
All qdiscs, classes and filters have IDs, which can either be specified or be automatically assigned.
IDs consist of a major number and a minor number, separated by a colon โ major:minor. Both major and minor are hexadecimal numbers and are limited to 16 bits. There are two special values: root is signified by major and minor of all ones, and unspecified is all zeros.
- QDISCS โ a qdisc, which potentially can have children, gets assigned a major number, called a 'handle', leaving the minor number namespace available for classes. The handle is expressed as
'10:'. It is customary to explicitly assign a handle to qdiscs expected to have children. - CLASSES โ classes residing under a qdisc share their qdisc major number, but each have a separate minor number called a 'classid' that has no relation to their parent classes, only to their parent qdisc. The same naming custom as for qdiscs applies.
- FILTERS โ filters have a three part ID, which is only needed when using a hashed filter hierarchy.
โ๏ธ PARAMETERS โ๏ธ
The following parameters are widely used in TC. For other parameters, see the man pages for individual qdiscs. iykyk.
๐ธ RATES
Bandwidths or rates. These parameters accept a floating point number, possibly followed by either a unit (both SI and IEC units supported), or a float followed by a '%' character to specify the rate as a percentage of the device's speed (e.g. 5%, 99.5%).
โ ๏ธ Warning: specifying the rate as a percentage means a fraction of the current speed; if the speed changes, the value will not be recalculated. not it being stale ๐ญ
bitor a bare number โ Bits per secondkbitโ Kilobits per secondmbitโ Megabits per secondgbitโ Gigabits per secondtbitโ Terabits per secondbpsโ Bytes per secondkbpsโ Kilobytes per secondmbpsโ Megabytes per secondgbpsโ Gigabytes per secondtbpsโ Terabytes per second
To specify in IEC units, replace the SI prefix (k-, m-, g-, t-) with IEC prefix (ki-, mi-, gi- and ti-) respectively. glow up achieved โจ
TC store rates as a 32-bit unsigned integer in bps internally, so we can specify a max rate of 4294967295 bps.
โฑ๏ธ TIMES
Length of time. Can be specified as a floating point number followed by an optional unit:
s,secorsecsโ Whole secondsms,msecormsecsโ Millisecondsus,usec,usecsor a bare number โ Microseconds.
TC defined its own time unit (equal to microsecond) and stores time values as 32-bit unsigned integer, thus we can specify a max time value of 4294967295 usecs.
๐ฆ SIZES
Amounts of data. Can be specified as a floating point number followed by an optional unit:
bor a bare number โ Bytes.kbitโ Kilobitskborkโ Kilobytesmbitโ Megabitsmbormโ Megabytesgbitโ Gigabitsgborgโ Gigabytes
TC stores sizes internally as 32-bit unsigned integer in byte, so we can specify a max size of 4294967295 bytes. no cap, that's the ceiling ๐ฆ
๐ข VALUES
Other values without a unit. These parameters are interpreted as decimal by default, but you can indicate TC to interpret them as octal and hexadecimal by adding a '0' or '0x' prefix respectively. cute little number dialects ๐
๐ ๏ธ TC COMMANDS ๐ ๏ธ
The following commands are available for qdiscs, classes and filter:
addโ Add a qdisc, class or filter to a node. For all entities, a parent must be passed, either by passing its ID or by attaching directly to the root of a device. When creating a qdisc or a filter, it can be named with thehandleparameter. A class is named with theclassidparameter.deleteโ A qdisc can be deleted by specifying its handle, which may also be'root'. All subclasses and their leaf qdiscs are automatically deleted, as well as any filters attached to them. it takes everyone down with it ๐changeโ Some entities can be modified 'in place'. Shares the syntax of'add', with the exception that the handle cannot be changed and neither can the parent. In other words,changecannot move a node. no relocating bestie ๐ซreplaceโ Performs a nearly atomic remove/add on an existing node id. If the node does not exist yet it is created.getโ Displays a single filter given the interface DEV, qdisc-id, priority, protocol and filter-id.showโ Displays all filters attached to the given interface. A valid parent ID must be passed.linkโ Only available for qdiscs and performs areplacewhere the node must exist already.
๐ MONITOR ๐
The tc utility can monitor events generated by the kernel such as adding/deleting qdiscs, filters or actions, or modifying existing ones. it's literally just watching, lowkey peaceful ๐ฆ
The following command is available for monitor :
fileโ If the file option is given, the tc does not listen to kernel events, but opens the given file and dumps its contents. The file has to be in binary format and contain netlink messages.
๐ OPTIONS ๐
-b,-b filename,-batch,-batch filenameโ read commands from provided file or standard input and invoke them. First failure will cause termination of tc.-forceโ don't terminate tc on errors in batch mode. If there were any errors during execution of the commands, the application return code will be non zero. it's giving "keep going, we'll deal later" ๐ซถ-o,-onelineโ output each record on a single line, replacing line feeds with the'\'character. This is convenient when you want to count records withwc(1)or togrep(1)the output.-n,-net,-netns <NETNS>โ switches tc to the specified network namespace NETNS. Actually it just simplifies executing of:
ip netns exec NETNS tc [ OPTIONS ] OBJECT { COMMAND | help }
to
tc -n[etns] NETNS [ OPTIONS ] OBJECT { COMMAND | help }
-N,-Numericโ Print the number of protocol, scope, dsfield, etc directly instead of converting it to human readable name.-cf,-conf <FILENAME>โ specifies path to the config file. This option is used in conjunction with other options (e.g.-nm).-t,-timestampโ Whentc monitorruns, print timestamp before the event message in format:
Timestamp: <Day> <Month> <DD> <hh:mm:ss> <YYYY> <usecs> usec
-ts,-tshortโ Whentc monitorruns, prints short timestamp before the event message in format:
[<YYYY>-<MM>-<DD>T<hh:mm:ss>.<ms>]
-echoโ Request the kernel to send the applied configuration back. it's giving receipts, and honestly? respect ๐
โจ FORMAT โจ
okay so the show command has extra formatting options, and they're lowkey iconic ๐
-s,-stats,-statisticsโ spits out more stats about packet usage ๐-d,-detailsโ gives you more detailed info about rates and cell sizes ๐-r,-rawโ outputs raw hex values for handles, no decoding bestie โจ-p,-prettyโ for theu32filter, it decodes offset and mask values into equivalent filter commands based on TCP/IP. and in JSON output, it adds whitespace so it's actually readable ๐-iecโ prints rates in IEC units (ie.1K = 1024)-g,-graphโ shows classes as an ASCII graph. if the-soption was specified it also prints generic stats info under each class. heads up tho: classes can be filtered only by thedevoption ๐-c[color][={always|auto|never}โ configures color output. if the parameter is omitted or set toalways, color output is enabled no matter what stdout's doing. if it'sauto, stdout gets checked to be a terminal before color output turns on. if it'snever, color output is off, periodt. if you specify it multiple times, the last one wins. also this flag is just ignored if-jsonis also given ๐-j,-jsonโ displays results in JSON format ๐-nm,-nameโ resolves the class name from/etc/iproute2/tc_cls, or from whatever file the-cfoption points at. this file is literally just a mapping of classid to class name:
# Here is comment
1:40 voip # Here is another comment
1:50 web
1:60 ftp
1:2 home
and listen, tc will not fail if -nm was specified without the -cf option but /etc/iproute2/tc_cls doesn't exist โ which is what makes it possible to pass the -nm option for creating a tc alias ๐ซถ
-br,-briefโ prints only the essential data needed to identify the filter and action (handle,cookie, etc.) plus stats. ngl this one is currently only supported bytc filter showandtc actions lscommands โจ
๐ธ EXAMPLES ๐ธ
tc -g class show dev eth0
Shows classes as an ASCII graph on the eth0 interface. iconic โจ
tc -g -s class show dev eth0
Shows classes as an ASCII graph with stats info under each class. the upgrade we deserved ๐
๐ HISTORY ๐
tc was written by Alexey N. Kuznetsov and added in Linux 2.2. a whole legend, fr fr ๐
๐ฆ SEE ALSO ๐ฆ
tc-basic(8), tc-bfifo(8), tc-bpf(8), tc-cake(8), tc-cgroup(8), tc-choke(8), tc-codel(8), tc-drr(8), tc-ematch(8), tc-ets(8), tc-flow(8), tc-flower(8), tc-fq(8), tc-fq_codel(8), tc-fq_pie(8), tc-fw(8), tc-gact(8), tc-hfsc(7), tc-hfsc(8), tc-htb(8), tc-mqprio(8), tc-pfifo(8), tc-pfifo_fast(8), tc-pie(8), tc-red(8), tc-route(8), tc-sfb(8), tc-sfq(8), tc-stab(8), tc-tbf(8), tc-u32(8)
User documentation at http://lartc.org/, but please direct bugreports and patches to: <netdev@vger.kernel.org> ๐ฌ
๐ AUTHOR ๐
Manpage maintained by bert hubert (ahu@ds9a.nl)
and that's a wrap bestie!! ๐ this page came from the iproute2 docs, dated 16 December 2001 โ yes it's been serving main character energy since 2001 and it still eats ๐ go configure something gorgeous, you got this ๐โจ
๐ฆ where this page comes from
- alpine 3.23: iproute2-doc 6.17.0-r0 ยท GPL-2.0-or-later
- alpine 3.24: iproute2-doc 7.0.0-r0 ยท GPL-2.0-or-later
- arch rolling: iproute2 7.2.0-1
- arch rolling: iproute2 7.3.0-1 ยท GPL-2.0-or-later
- centos-stream 10: iproute-tc 7.0.0-2.el10 ยท GPL-2.0-or-later
- centos-stream 9: iproute-tc 6.17.0-3.el9 ยท GPL-2.0-or-later
- fedora 44: iproute-tc 6.17.0-2.fc44 ยท GPL-2.0-or-later
- nixos 26.05: iproute2 7.0.0
- nixpkgs unstable: iproute2 7.2.0
- ubuntu resolute: iproute2 6.19.0-1ubuntu1 ยท GPL-2.0-only
- ubuntu resolute: iproute2 6.19.0-1ubuntu1.1 ยท GPL-2.0-only
- ubuntu stonking: iproute2 7.2.0-1ubuntu1 ยท GPL-2.0-only
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms