Linux allows you to control the upload and download speed on specific network ports. This post is a follow-up on the wireless access point setup of a Raspberry Pi. When serving a guest Wifi setup, you may want to limit the bandwidth used by clients on the Raspberry Pi access point so that they won’t use up all Internet bandwidth of your main network. Whatever you case maybe I’ll show you how to throttle the eth0 bandwidth of the Raspberry Pi 3B+.
Install wondershaper
Wondershaper is a simple utility that allows the user to limit the bandwidth of one or more network adapters. It does so by using iproute’s tc
command, but greatly simplifies its operation. Install it by running the following commands:
$ sudo apt update $ sudo apt install wondershaper
wondershaper Usage
A summary of wondershaper syntax is included below.
wondershaper [ interface ] Shows the status of traffic shaping on that interface. wondershaper clear [ interface ] Removes all traffic shaping from that interface. wondershaper [ interface ] [ downlink ] [ uplink ] Configures the wondershaper on the specified interface, given the specified downlink speed in kilobits per second, and the specified uplink speed in kilobits per second.
So for our use case on the Raspberry Pi wireless access point, we want to limit all of the users to a maximum of 10Mbps Download and 5Mbps Upload. We need to apply this limit to the eth0 of the Raspberry Pi.
$ sudo wondershaper eth0 10240 5120 ##confirm it is applied $ sudo wondershaper eth0
That’s it, the bandwidth limiting is now applied and should be working. However, this is not permanent and will be lost on the next reboot. We will solve this in the next step.
Add wondershaper to startup
To run the wondershaper command on every startup of the raspberry pi, we can add the command to the rc.local
file. Edit the rc.local
file and add the command just above the exit 0
line. It should like the one below.
$ cat /etc/rc.local !/bin/sh -e # rc.local # This script is executed at the end of each multiuser runlevel. Make sure that the script will "exit 0" on success or any other value on error. # In order to enable or disable this script just change the execution bits. # By default this script does nothing. Print the IP address _IP=$(hostname -I) || true if [ "$_IP" ]; then printf "My IP address is %s\n" "$_IP" fi wondershaper eth0 10240 5120 exit 0
Wondershaper bandwidth limiting on eth0 should now be applied on every startup of the Raspberry Pi.
– masterkenneth