Skip to content

Instantly share code, notes, and snippets.

@egyleader
Last active Mar 23, 2022
Embed
What would you like to do?
Limit network bandwidth in linux using wondershaper

this gist will help you limit your network bandwidth using wondershaper tool !!

Why to limit bandwidth?

there are a lot of reasons you would do that, it is very useful when you are trying to :

  1. control your internet quota or
  2. throttle internet connection to know how certain app or service work on slow connections .
  3. have more than one wifi adapter and need to control the speed each one connects to internet
  4. any other reason IDK about 🤷🏻‍♂ !

so here we go

1. install wonder shaper tool

sudo apt install wondershaper  [On Debian/Ubuntu]
sudo yum install wondershaper  [On CentOS/RHEL]
sudo dnf install wondershaper  [On Fedora 22+]
sudo pacman -S wondershaper [ on Archlinux and based systems]

2. find your interface name

you need to find your wifi card id that you will limit by running this command

ifconfig

output will be like

br-85a34b55f6de: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
... other stuff 

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
... other stuff 


wlp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
... other stuff 

so here my wifi adapter name is 'wlp2s0' and lo is wired ethernet , you should know the one you need by other info like the ip or data usage , but if you have one wifi adapter it is usually wlp2s0.

3. run this command with your adapter name

sudo wondershaper -a wlp2s0 -d 4000 -u 1024

with the -d argument represents download speed in kb and -u represents upload speed in kb

4. to clear the limit and have full internet speed you run

sudo wondershaper -c -a wlp2s0

you also need to run this command before applying any new limit on the same adapter

5. I've made shell scripts to help you switch easily between high speed and low speed

you can find them in this gist 👇🏻

#!/bin/bash
sudo wondershaper -c -a wlp2s0
echo speed limit removed
#!/bin/bash
sudo wondershaper -a wlp2s0 -d 8000 -u 2500
echo speed limit added to 8MB download and 2.5MB upload
#!/bin/bash
sudo wondershaper -c -a wlp2s0
sudo wondershaper -a wlp2s0 -d 4000 -u 1024
echo speed limit added to 4MB download and 1MB upload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment