The tc command is a powerful tool for manipulating and displaying network traffic control settings on Linux systems. With tc, you can set up rules and policies to control network traffic flows, prioritize certain types of traffic, and shape or limit the bandwidth available to specific network interfaces or applications.
Here are some common use cases for the tc command:
- Traffic shaping: By using tc, you can control the rate of data transfer for specific network interfaces, so that certain types of traffic (such as VoIP or video streaming) receive higher priority and more bandwidth than other types of traffic. This can help improve the quality and responsiveness of real-time applications.
- Bandwidth limiting: tc allows you to limit the amount of bandwidth available to specific applications or network interfaces, which can be useful for preventing network congestion and ensuring that critical applications have enough bandwidth to function properly.
- Network emulation: tc can also be used to simulate network conditions, such as latency, jitter, and packet loss, which can be useful for testing and troubleshooting network applications.
If you encounter the below error while running the command tc:
tc: command not found
you may try installing the below package as per your choice of distribution:
|Debian||apt-get install iproute2|
|Ubuntu||apt-get install iproute2|
|Alpine||apk add iproute2|
|Arch Linux||pacman -S iproute2|
|Kali Linux||apt-get install iproute2|
|CentOS||yum install iproute-tc|
|Fedora||dnf install iproute-tc|
|Raspbian||apt-get install iproute2|
tc Command Examples
1. Add constant network delay to outbound packages:
# tc qdisc add dev eth0 root netem delay delay_in_millisecondsms
2. Add normal distributed network delay to outbound packages:
# tc qdisc add dev eth0 root netem delay mean_delay_msms delay_std_msms
3. Add package corruption/loss/duplication to a portion of packages:
# tc qdisc add dev eth0 root netem corruption|loss|duplication effect_percentage%
4. Limit bandwidth, burst rate and max latency:
# tc qdisc add dev eth0 root tbf rate max_bandwith_mbmbit burst max_burst_rate_kbkbit latency max_latency_before_drop_msms
5. Show active traffic control policies:
# tc qdisc show dev eth0
6. Delete all traffic control rules:
# tc qdisc del dev eth0
7. Change traffic control rule:
# tc qdisc change dev eth0 root netem policy policy_parameters
The tc command can be a bit complex to use, as it requires a good understanding of networking concepts and terminology. However, there are many resources available online to help you get started, such as the man page (man tc) and the Linux Advanced Routing & Traffic Control HOWTO.