Application-Level Rate Limiting with Trickle
Trickle operates in user-space to govern bandwidth for specific applications by manipulating socket data transmissions. It leverages dynamic linking, meaning it only functions with programs relying on libc.so. Consequently, statically compiled binaries and UDP traffic are unsupported. A distinct advantage is that administrative privileges are not required for execution.
Checking Application Compatibility
Use the ldd utility to verify dynamic linking against the C library.
ldd /usr/bin/curl | grep libc.so
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f8a9c200000)
Installing Trickle
Debian/Ubuntu:
sudo apt update
sudo apt install trickle
RHEL/CentOS:
sudo yum update
sudo yum install trickle
Usage Examples
Prepend the trickle command along with rate parameters to your target command. The -d flag specifies maximum download speed, while -u dictates upload speed (both measured in KB/s).
trickle -u 150 scp archive.tar.bz2 dev@10.0.5.10:/opt/data
To throttle a web browser's download capacity to 250 KB/s:
trickle -d 250 chromium %u
Interface-Level Rate Limiting with Wondershaper
Wondershaper is a shell script leveraging the Linux tc command and Quality of Service (QoS) to restrict bandwidth on a per-interface basis. It manages outbound traffic via prioritized queuing and inbound traffic via packet dropping. Beyond simple capping, it prioritizes low-latency for interactive protocols (like SSH) even during heavy bulk transfers, preventing uploads from starving downloads.
Installing Wondershaper
Debian/Ubuntu:
sudo apt update
sudo apt install wondershaper
RHEL/CentOS:
sudo yum install epel-release
sudo yum install wondershaper
From Source:
git clone https://github.com/magnific0/wondershaper.git
cd wondershaper
sudo make install
Usage Examples
First, identify the target network interface using ip link or ifconfig. Then apply the rate limits using the -a (adapter), -d (download in Kbps), and -u (upload in Kbps) options.
sudo wondershaper -a eth1 -d 2048 -u 1024
To remove the applied constraints and restore default behavior:
sudo wondershaper -c -a eth1
Display current interface status:
wondershaper -s -a eth1