How to set up QoS bandwidth rate limit on OpenWRT

Last updated on September 29, 2020 by Dan Nanni

OpenWRT is an operating system used for embedded devices such as commodity home routers to route network traffic. It provides rich feature sets for network management, including firewall, QoS policy, port forwarding, monitoring, etc. One of the useful features of OpenWRT is to configure QoS policy such as bandwidth limiting for connected devices. If you would like to configure upload and download rate limiting on OpenWRT, you can follow the instructions below. This setup has been tested on OpenWRT Kamikaze 8.09 with Linksys WRT54GL router.

In this example, I am going to cap the upload and download bandwidth of my Linksys router at 2Mbits/sec and 4Mbits/sec respectively.

My WRT54GL router has two interfaces: (1) eth0 for WAN interface connecting to external networks, and (2) br-lan for LAN interface connected to the internal network.

First, SSH to WRT54GL router as root. Follow the rest of the steps below.

Optionally, set up proxy if the router is behind a proxy.

$ export http_proxy=http://your_proxy_host:port_number

Using OpenWRT's package manager called opkg, install necessary software and kernel modules.

$ opkg update
$ opkg install tc iptables-mod-ipopt
$ opkg kmod-sched

Then, verify that all necessary kernel modules are installed. The names of kernel modules start with sch_.

$ ls /lib/modules/$(uname -r) | grep sch 

Next, insert a kernel module needed for rate limiting. In this case, I choose token bucket filter.

$ insmod sch_tbf

For upload bandwidth limiting, I set up the outgoing rate limit on WAN interface eth0 as follows.

$ tc qdisc add dev eth0 root tbf rate 2mbit burst 10kb latency 50ms peakrate 4mbit minburst 1540

For download bandwidth limiting, I set up the outgoing rate limit on LAN interface br-lan as follows.

$ tc qdisc add dev br-lan root tbf rate 4mbit burst 10kb latency 50ms peakrate 8mbit minburst 1540

To verify that eth0 and br-lan have been configured properly:

$ tc -s qdisc ls dev eth0
$ tc -s qdisc ls dev br-lan

This completes the QoS rate limit setting on OpenWRT. If you would like to disable rate limit later, you can do the following.

$ tc qdisc del dev eth0 root
$ tc qdisc del dev br-lan root

If you are interested, please check out a more general Linux tutorial on rate limiting network bandwidth of individual applications or network interfaces.

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean