Thursday, 1 December 2011

Linux traffic Control (tc)

The world of Linux's Traffic control is a mysterious thing - you end up spending hours Googling or days reading source code.

For some nitty gritty on tc see an earlier post of mine on tc rate limiting and pitfalls.

TC Queuing Disciplines (qdisc)

Creating:
E.g Add a tbf qdisc on eth0:
sudo tc qdisc add dev eth0 root tbf rate 10mbit burst 100kb latency 50ms

Listing:
E.g. Show qdiscs on all interfaces:
tc qdisc show

Delete:
E.g. Delete all qdiscs on eth0 interface:
sudo tc qdisc delete dev eth0 root


TC Filters

Creating:
Here's some good info on the u32 filter (here and here). Some more with a quick overview from LARTC mail list (the source of most useful info on tc etc). Someone put together a tc manual.

Listing:
E.g. Show filters on eth0 interface:
sudo tc filter show dev eth0 root

Here's some example output:
filter parent ffff: protocol ip pref 49152 u32

Deleting:
To delete the above example filter (bold section copied from filter show output):
sudo tc filter del dev eth0 parent ffff: protocol ip pref 49152 u32

[updated:17feb12, 5,6jul12,29jan20: more explanations+archive.org link for 1st link as it's gone MIA, link to older article of mine; Added TC qdisc cmds]