LinuxCommandLibrary

tc-tbf

Limit network traffic bandwidth using tokens

SYNOPSIS

tc qdisc add dev root tbf rate burst latency [limit ] [ mtu ] [ peakrate ] [ cell_align ] [ overhead ]

PARAMETERS

dev
    The network interface to which the TBF qdisc is attached.

root
    Specifies that the TBF qdisc is attached at the root of the traffic control hierarchy.

rate
    The maximum rate at which traffic is allowed to be transmitted. Expressed in bits per second (e.g., 1mbit for 1 megabit per second).

burst
    The size of the token bucket, representing the maximum amount of data that can be sent in a short burst. A larger burst allows for greater flexibility but can also lead to larger variations in the inter-packet delay. Expressed in bytes.

latency
    The time (in milliseconds) it takes to empty the bucket at the configured rate. This value is used internally to calculate other parameters. A reasonable default value is 400ms.

limit
    The maximum amount of bytes that are queued waiting for tokens. Traffic exceeding this limit will be dropped. (optional)

mtu
    Maximum Transmission Unit. Assumed maximum packet size. (optional)

peakrate
    Maximum rate at which tokens are created to fill the bucket. Enables a small traffic burst even if is smaller. (optional)

cell_align
    Aligns the bucket size to specified number of bytes. (optional)

overhead
    Number of bytes to add to the packet size when doing calculations. useful when tunneling is involved. (optional)

DESCRIPTION

The `tc-tbf` command implements a Token Bucket Filter (TBF) traffic shaping algorithm within the Linux traffic control (tc) subsystem. TBF is a simple and effective queuing discipline (qdisc) used to limit the rate at which traffic is sent out of an interface. It uses a virtual token bucket to regulate the flow. Each packet requires a certain number of tokens to be sent. If enough tokens are available, the packet is transmitted; otherwise, it's delayed or dropped, depending on the configuration. TBF is commonly employed to shape traffic based on rate limits, enabling control over bandwidth utilization and preventing network congestion. Unlike some more complex shapers, TBF is relatively straightforward to configure and understand, making it suitable for basic traffic shaping needs. It's useful for preventing a single host or application from consuming excessive bandwidth, or for conforming traffic to a specific rate.

CAVEATS

TBF is a relatively simple shaper and may not be suitable for all traffic shaping scenarios. For more complex requirements, consider using HTB (Hierarchical Token Bucket) or other more advanced qdiscs. The choice of burst size and latency can significantly impact performance; experimentation may be needed to find optimal values. Over-shaping can lead to packet loss and retransmissions, degrading overall performance.

EXAMPLE USAGE

To limit traffic on interface eth0 to 1 Mbit/s with a burst size of 10KB:
`tc qdisc add dev eth0 root tbf rate 1mbit burst 10k latency 400ms`

MONITORING

You can monitor the TBF qdisc using `tc -s qdisc show dev eth0` to see statistics such as packets and bytes transmitted, dropped packets, and current queue length.

HISTORY

The TBF qdisc has been a part of the Linux traffic control subsystem for a long time, evolving alongside other queuing disciplines. Its relatively simple design has made it a popular choice for basic rate limiting. It has undergone various improvements and bug fixes over the years, with ongoing maintenance within the Linux kernel development community. It's usage is very common when there is a need to manage/limit traffic on a given interface.

SEE ALSO

tc(8), tc-htb(8), tc-cbq(8), iproute2(8)

Copied to clipboard