LinuxCommandLibrary

wondershaper

Limit network bandwidth usage

TLDR

Show the current [s]tatus of a specific [a]dapter

$ wondershaper -s -a [adapter_name]
copy

Clear limits from a specific [a]dapter
$ wondershaper -c -a [adapter_name]
copy

Set a specific maximum [d]ownload rate (in Kbps)
$ wondershaper -a [adapter_name] -d [1024]
copy

Set a specific maximum [u]pload rate (in Kbps)
$ wondershaper -a [adapter_name] -u [512]
copy

Set a specific maximum [d]ownload rate and [u]pload rate (in Kpbs)
$ wondershaper -a [adapter_name] -d [1024] -u [512]
copy

Display [h]elp
$ wondershaper -h
copy

SYNOPSIS

wondershaper <interface> <download_rate> <upload_rate>
wondershaper clear <interface>
wondershaper -c <interface>
wondershaper -a <interface> -d <download_rate> -u <upload_rate>

PARAMETERS

<interface>
    The network interface to shape (e.g., eth0, wlan0).

<download_rate>
    The desired maximum download speed in kilobits per second (kbit/s). This indirectly limits incoming traffic.

<upload_rate>
    The desired maximum upload speed in kilobits per second (kbit/s).

clear
    Removes any existing wondershaper traffic shaping rules from the specified interface.

-c, --clear
    An alias for the 'clear' command, used to remove shaping rules.

-a, --adapter <interface>
    Specifies the network interface to apply shaping to.

-d, --download <rate>
    Sets the download speed limit in kbit/s.

-u, --upload <rate>
    Sets the upload speed limit in kbit/s.

-v, --version
    Displays the wondershaper script version.

-h, --help
    Shows the command's help message.

DESCRIPTION

wondershaper is a simple shell script designed to easily manage and limit network bandwidth on a Linux interface. It acts as a high-level wrapper around the more complex tc (traffic control) and iptables commands, providing basic Quality of Service (QoS) functionality. Its primary goal is to prevent large downloads or uploads from monopolizing the entire network connection, ensuring a smoother internet experience for interactive tasks like web browsing, online gaming, and video calls. It achieves this by prioritizing small, interactive packets and limiting the overall data rates for both upload and effective download speeds. While not suitable for intricate traffic management, it offers a quick and effective solution for common home or small office network congestion issues.

CAVEATS

Requires root privileges to execute.
The script uses tc (traffic control) and iptables under the hood. Ensure these utilities are installed and functional on your system.
The specified "download" limit for wondershaper primarily limits your interface's upload capacity, which in turn causes the remote sender to slow down due to dropped packets, thereby achieving an effective download limit. It does not directly limit incoming data rate.
It's a relatively simple script; for complex or dynamic QoS requirements, direct tc configuration or dedicated QoS solutions might be necessary.

HOW IT WORKS

wondershaper sets up Hierarchical Token Bucket (HTB) and Stochastic Fairness Queueing (SFQ) disciplines on the specified interface. It uses iptables to mark different types of traffic (e.g., interactive, bulk) and then applies different queueing disciplines and priorities based on these marks. This ensures that latency-sensitive traffic (like SSH, DNS, or ACK packets) gets priority over bulk data transfers (like large downloads/uploads).

UNITS

It is crucial to remember that <download_rate> and <upload_rate> values are specified in kilobits per second (kbit/s), not kilobytes per second (KB/s) or megabits per second (Mbit/s). For example, 1 Mbps = 1000 kbit/s.

HISTORY

wondershaper emerged as a popular script in the early 2000s, designed to simplify the often-intimidating configuration of Linux's tc command. Its aim was to provide a straightforward way for users to implement basic traffic shaping and QoS without delving into the complexities of netfilter and iproute2. It has been included in various Linux distributions' utility sets or as a widely shared standalone script, remaining a go-to for quick and easy bandwidth management.

SEE ALSO

tc(8), iptables(8), ip(8)

Copied to clipboard