How to set up QoS bandwidth rate limit on OpenWRT

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 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 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

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

5 thoughts on “How to set up QoS bandwidth rate limit on OpenWRT

  1. This is not helpful without knowing what the tc parameters mean.

    OpenWRT desperately needs what DD-WRT already has in its base release: A simple screen that lets you prioritize traffic by protocol. Skype, bittorrent, etc., all can be set to have one of four priorities (Express, Premium, Normal, Bulk).

    Individual ports or IP addresses can easily be given priority.

    There is just nothing like this in OpenWRT except in Gargoyle but 4MB ROM routers cannot run both OpenWRT & Gargoyle.

    Even a 2MB ROM router can run QoS simply in DD-WRT. So there is just no way OpenWRT can supplant DD-WRT for 4MB routers, and DD-WRT will remain the only option for the older router.

    This is really the only truly fatal flaw in OpenWRT.

  2. $ opkg kmod-sched
    Do you mean $ opkg install kmod-sched
    also that package doesn't seem to be available
    root@OpenWrt:~# opkg install kmod-sched
    Unknown package 'kmod-sched'.
    Collected errors:
    * opkg_install_cmd: Cannot install package kmod-sched.
    root@OpenWrt:~# insmod sch_tbf
    Failed to find sch_tbf. Maybe it is a built in module ?

Leave a comment

Your email address will not be published. Required fields are marked *