tc
Traffic control: shaping and prioritizing network traffic
TLDR
Add constant network delay to outbound packages
Add normal distributed network delay to outbound packages
Add package corruption/loss/duplication to a portion of packages
Limit bandwidth, burst rate and max latency
Show active traffic control policies
Delete all traffic control rules
Change traffic control rule
SYNOPSIS
tc qdisc [add | change | replace | link | delete ] dev dev [parent qdisc-id | root] [handle qdisc-id] qdisc-type [qdisc-parameters]
tc class [add | change | replace | delete] dev dev parent qdisc-id classid class-id class-type [class-parameters]
tc filter [add | change | replace | delete] dev dev parent qdisc-id protocol protocol [prio priority] filter-type [filter-parameters] flowid flow-id
PARAMETERS
qdisc
Specifies that you are working with a queuing discipline (qdisc).
class
Specifies that you are working with a class within a qdisc.
filter
Specifies that you are working with a filter to classify traffic.
add
Adds a new qdisc, class, or filter.
change
Modifies an existing qdisc, class, or filter.
replace
Replaces an existing qdisc, class, or filter.
link
Links a qdisc to a network interface.
delete
Deletes an existing qdisc, class, or filter.
dev dev
Specifies the network interface (e.g., eth0, wlan0).
parent qdisc-id
Specifies the parent qdisc or class ID.
root
Specifies that the qdisc is the root qdisc of the interface.
handle qdisc-id
Assigns a handle to the qdisc for referencing it later.
classid class-id
Assigns a class ID to a class.
qdisc-type
Specifies the type of qdisc (e.g., htb, sfq, tbf).
class-type
Specifies the type of class (e.g., htb).
protocol protocol
Specifies the protocol for the filter (e.g., ip, arp).
prio priority
Assigns a priority to the filter.
filter-type
Specifies the type of filter (e.g., u32, fw).
flowid flow-id
Specifies the flowid to which packets matching the filter are directed.
DESCRIPTION
The tc command in Linux is a powerful utility used to configure the Traffic Control (QoS) facilities provided by the Linux kernel.
It allows administrators to shape network traffic by prioritizing, delaying, policing, or dropping packets based on various criteria. This is achieved through complex queuing disciplines (qdiscs), classes, filters, and actions.
tc can be used to improve network performance under heavy load, guarantee bandwidth for critical applications, and limit bandwidth usage for less important traffic. It is a complex tool, requiring a good understanding of networking concepts and traffic shaping techniques. Common use cases include prioritizing VoIP traffic, limiting bandwidth for peer-to-peer applications, and implementing fair queuing algorithms. Configuration is typically persistent between reboots, requiring careful planning and testing. Incorrect configuration can severely impact network performance.
tc operates primarily on network interfaces to control the flow of packets at the kernel level.
CAVEATS
Incorrect tc configurations can severely degrade network performance and even lead to network outages. Testing and careful planning are essential. Different qdiscs, classes and filters have vastly different parameters that must be configured correctly. Traffic control is applied only on egress traffic by default.
COMMON <B><I>QDISCS</I></B>
HTB (Hierarchical Token Bucket): A classful qdisc that allows you to create a hierarchy of classes for prioritizing traffic.
SFQ (Stochastic Fairness Queuing): A classless qdisc that fairly distributes bandwidth among different flows.
TBF (Token Bucket Filter): A classless qdisc that limits the rate of traffic.
U32 FILTER
The u32 filter is a powerful, yet complex filter that allows you to match packets based on almost any field in the packet header. It requires a deep understanding of packet structures and bitwise operations.
HISTORY
The tc command and the associated Traffic Control subsystem have been a part of the Linux kernel for many years, evolving alongside advancements in networking technology. Initial development focused on providing basic queuing disciplines and traffic shaping capabilities. Over time, more sophisticated algorithms and features were added to support various network traffic management requirements. Development is ongoing, as new qdiscs and filtering mechanisms are implemented to address the increasing complexity of modern networks.