You need to use a portable lightweight userspace bandwidth shaper called trickle. It can run in in collaborative mode or in stand alone mode. trickle works by taking advantage of the unix loader preloading.
| Tutorial details | |
|---|---|
| Difficulty | Intermediate (rss) |
| Root privileges | Yes (for installation) |
| Requirements | trickle |
Installation
Type the following apt-get command under Debian / Ubuntu Linux to install trickle software:
$ sudo apt-get install trickle
Sample outputs:
Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: trickle 0 upgraded, 1 newly installed, 0 to remove and 20 not upgraded. Need to get 43.0 kB of archives. After this operation, 180 kB of additional disk space will be used. Get:1 http://debian.osuosl.org/debian/ squeeze/main trickle amd64 1.07-9 [43.0 kB] Fetched 43.0 kB in 1s (30.6 kB/s) Selecting previously deselected package trickle. (Reading database ... 280975 files and directories currently installed.) Unpacking trickle (from .../trickle_1.07-9_amd64.deb) ... Processing triggers for man-db ... Setting up trickle (1.07-9) ...
Install trickle under CentOS / RHEL / Fedora Linux
First, turn on EPEL repo and type the following yum command to install trickle software:
# yum install trickle
Sample outputs:
Loaded plugins: auto-update-debuginfo, protectbase, rhnplugin
0 packages excluded due to repository protections
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package trickle.x86_64 0:1.07-9.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================
Package Arch Version Repository
Size
=============================================================
Installing:
trickle x86_64 1.07-9.el6 epel 41 k
Transaction Summary
=============================================================
Install 1 Package(s)
Total download size: 41 k
Installed size: 89 k
Is this ok [y/N]: y
Downloading Packages:
trickle-1.07-9.el6.x86_64.rpm | 41 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : trickle-1.07-9.el6.x86_64 1/1
Verifying : trickle-1.07-9.el6.x86_64 1/1
Installed:
trickle.x86_64 0:1.07-9.el6
Complete!How do I use trickle?
The syntax is:
trickle -u uploadLimit program trickle -d downloadLimit program trickle -u {UPLOAD_LIMIT} -d {DOWNLOAD_LIMIT} program-binary
Examples
Start ftp client limiting its upload capacity to 100 KB/s:
trickle -u 100 ftp
Start ftp client limiting its download capacity at 50 KB/s:
trickle -d 50 ftp
You can combine both options:
trickle -u 100 -d 50 ftp
You can pass other args to the ftp command:
trickle -u 100 -d 50 ftp ftp.cyberciti.biz
trickle -u 100 -d 50 ftp ftp.cyberciti.biz 8021
Use the wget command to download an iso file from openbsd.org ftp server:
$ wget http://ftp.openbsd.org/pub/OpenBSD/5.2/i386/install52.iso
Sample outputs:
--2012-12-04 16:00:16-- http://ftp.openbsd.org/pub/OpenBSD/5.2/i386/install52.iso
Resolving ftp.openbsd.org... 129.128.5.191
Connecting to ftp.openbsd.org|129.128.5.191|:80... connected.
HTTP request sent, awaiting response... 206 Partial Content
Length: 237457408 (226M), 230422880 (220M) remaining [text/plain]
Saving to: `install52.iso'
7% [> ] 1,86,94,640 2.94M/s eta 79s
Now, use trickle to download iso file but limit capacity at 50 KB/s:
trickle -d 50 wget http://ftp.openbsd.org/pub/OpenBSD/5.2/i386/install52.iso
Sample outputs:
trickle: Could not reach trickled, working independently: No such file or directory
--2012-12-04 16:00:32-- http://ftp.openbsd.org/pub/OpenBSD/5.2/i386/install52.iso
Resolving ftp.openbsd.org... 129.128.5.191
Connecting to ftp.openbsd.org|129.128.5.191|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 237457408 (226M) [text/plain]
Saving to: `install52.iso.2'
0% [ ] 2,45,760 49.9K/s eta 77m 22s
Limit bandwidth in a single shell for all commands
Launch bash or ksh shell limiting its upload capacity to 250 KB/s, and download capacity at 500 KB/s:
trickle -d 500 -u 250 bash
OR
trickle -d 500 -u 250 ksh
Now, for all programs launched inside currently running bash or ksh shell will follow bandwidth shaper rules:
wget http://example.com/foo.iso
sftp file.mp4 user@server1.cyberciti.biz:~/Downloads/
Other options
From the man page:
-h Help (this) -v Increase verbosity level -V Print trickle version -s Run trickle in standalone mode independent of trickled -dSet maximum cumulative download rate to KB/s -u Set maximum cumulative upload rate to KB/s -w Set window length to KB -t Set default smoothing time to s -l Set default smoothing length to KB -n Use trickled socket name -L Set latency to milliseconds
Check out related media
(Video 01: Linux / Unix Internet Bandwidth Throttling For A Specific Shell Using Trickle Utility)
See also:
- Linux FTP Server Traffic Control And Throttle Port 21 Using Iptables and Tc.
- trickle project home page.
- man page trickle
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop












{ 8 comments… read them below or add one }
Thank you for this HowTo, very usefull, but can I limit network bandwidth for multiple ip address in my local network, which use a common Internet channel with use trickle software?
Noop. Try iptables+tc.
Thanx
Very nice userland app, thanks but unfortunatelly `wget` is not a good example since it already has a builtin –not-too-long option called –limit-rate eg.
$ wget –limit-rate=120.5k ftp://mycloudshare.com/WeddingBlueray25gigs.iso
Wget usually doesn’t upload much so he doesn’t have a –limit-upload-rate option :).
At the begining of this article i thought that bash extended his ulimit built-in command (see: `man 1 bash`) but indeed it was an other trick :)
I should have used ftp or any other tool as an example. I appreciate your feedback and comment.
Vivek, a typo here (copy & paste but not edited),
You wrote 3 times:
trickle -u 100 -d 50 ftp
Instead of:
trickle -u 100 ftp
trickle -d 50 ftp
trickle -u 100 -d 50 ftp
;-)
but very nice topic to me. Well done again!
Philippe,
Thanks for the heads up!
Thanks! I found trickle on the first site I’ve visited along with many manuals, but it didn’t work. I was trying to limit bandwidth on jhbuild, but it was launching new independent processes to download files. You gave me the trick with “bash”.