Update: It seems I’ve created a monster. I’ve had my first two Google searchers arrive on this blog entry searching for “limit roomate downloading” and “netgear limit roomate”. Well after years of experimenting with QoS this is the best method I’ve found to do exactly that, so enjoy.
For part of the year I’m on a rural wifi network that, on a good day, gives me 3 megabits per second download speed and 700kbps upload speed. I’ve tried multiple rural providers, had them rip out their equipment because of the packet loss (that means you Skybeam), I’ve shouted at Qwest to upgrade the local exchange so we can get DSL, but for now I’m completely and utterly stuck on a 3 megabits downlink using Mile High Internet.
I have an occasional room-mate, my nephew, who downloads movies on iTunes and it uses about 1.5 to 3 megabits. I’ve tried configuring quality of service (QoS) on various routers including Netgear and Linksys/Cisco and the problem is that I need a zero latency connection for my SSH sessions to my servers. So while QoS might be great if everyone’s using non-realtime services like iTunes downloads and web browsing, when you are using SSH or a VoIP product like Skype, it really sucks when someone is hogging the bandwidth.
The problem arises because of the way most streaming movie players download movies. They don’t just do it using a smooth 1 megabit stream. They’ll suck down as much as your connection allows, buffer it and then use very little bandwidth for a few seconds, and then hog the entire connection again. If you are using SSH and you hit a key, it takes a while for the router to say: “Oh, you wanted some bandwidth, ok fine let me put this guy on hold. There. Now what did you want from me again? Hey you still there? Oh you just wanted one real-time keystroke. And now you’re gone. OK I guess I’ll let the other guy with a lower priority hog the bandwidth again until you hit another keystroke.”
So the trick, if you want to effectively deal with the movie downloading room-mate is to limit the amount of bandwidth they can use. That way netflix, iTunes, youtube, amazon unbox or any other streaming service has to use a constant 1 megabit rather than bursting to 3 megabits and then dropping to zero – and you always have some bandwidth available without having to wait for the router to do it’s QoS thing.
Here’s how you do it.
First install DD-WRT firmware on your router. I use a Netgear WNDR3300 router and after using various Linksys/Cisco routers I swear by this one. It has two built in radios so you can create two wireless networks, one on 2Ghz and one of 5Ghz. It’s also fast and works 100% reliably.
Then look up your router on dd-wrt’s site and download DD-WRT for your router and install it. I use version “DD-WRT v24-sp2 (10/10/09) std – build 13064”. There are newer builds available, but when I wrote this this was the recommended version.
Once you’re all set up and you have your basic wireless network with DD-WRT, make sure you disable QoS (it’s disabled by default).
Then configure SSH on DD-WRT. It’s a two step process. First you have to click the “Services” tab and enable SSHd. Then you have to click the Administration tab and enable SSH remote management.
Only the paid version of DD-WRT supports per user bandwidth limits, but I’m going to show you how to do it free with a few shell commands. I actually tried to buy the paid version of DD-WRT to do this, but their site is confusing and I couldn’t get confirmation they actually support this feature. So perhaps the author can clarify in a comment.
Because you’re going to enter shell commands, I recommend adding a public key for password-less authentication when you log in to DD-WRT. It’s on the same DD-WRT page where you enabled the SSHd.
Tip: Remember that with DD-WRT, you have to “Save” any config changes you make and then “Apply settings”. Also DD-WRT gets confused sometimes when you make a lot of changes, so just reboot after saving and it’ll unconfuse itself.
Now that you have SSHd set up, remote ssh login enabled and hopefully your public ssh keys all set up, here’s what you do.
SSH to your router IP address:
ssh root@192.168.1.1
Enter password.
Type “ifconfig” and check which interface your router has configured as your internal default gateway. The IP address is often 192.168.1.1. The interface is usually “br0”.
Lets assume it’s br0.
Enter the following command which clears all traffic control settings on interface br0:
tc qdisc del dev br0 root
Then enter the following:
tc qdisc add dev br0 root handle 1: cbq \
avpkt 1000 bandwidth 2mbit
tc class add dev br0 parent 1: classid 1:1 cbq \
rate 700kbit allot 1500 prio 5 bounded isolated
tc filter add dev br0 parent 1: protocol ip \
prio 16 u32 match ip dst 192.168.1.133 flowid 1:1
tc filter add dev br0 parent 1: protocol ip \
prio 16 u32 match ip src 192.168.1.133 flowid 1:1
These commands will rate limit the IP address 192.168.1.133 to 700 kilobits per second.
If you’ve set up automatic authentication and you’re running OS X, here’s a perl script that will do all this for you:
#!/usr/bin/perl
my $ip = $ARGV[0];
my $rate = $ARGV[1];
$ip =~ m/^\d+\.\d+\.\d+\.\d+$/ &&
$rate =~ m/^\d+$/ ||
die “Usage: ratelimit.pl\n”;
$rate = $rate . ‘kbit’;
print `ssh root\@192.168.1.1 “tc qdisc del dev br0 root”`;
print `ssh root\@192.168.1.1 “tc qdisc add dev br0 root handle 1: cbq avpkt 1000 bandwidth 2mbit ; tc class add dev br0 parent 1: classid 1:1 cbq rate $rate allot 1500 prio 5 bounded isolated ; tc filter add dev br0 parent 1: protocol ip prio 16 u32 match ip dst $ip flowid 1:1 ; tc filter add dev br0 parent 1: protocol ip prio 16 u32 match ip src $ip flowid 1:1″`;
You’ll see a few responses for DD-WRT when you run the script and might see an error about a file missing but that’s just because you tried to delete a rule on interface br0 that might not have existed when the script starts.
These rules put a hard limit on how much bandwidth an IP address can use. What you’ll find is that even if you rate limit your room mate to 1 megabit, as long as you have 500 kbit all to yourself, your SSH sessions will have absolutely no latency, Skype will not stutter, and life will be good again. I’ve tried many different configurations with various QoS products and have not ever achieved results as good as I’ve gotten with these rules.
Notes: I’ve configured the rules on the internal interface even though most QoS rules are generally configured on an external interface because it’s the only thing that really really seems to work. The Cisco engineers among you may disagree, but go try it yourself before you comment. I’m using the Linux ‘tc’ command and the man page is here.
PS: If you are looking for a great router to install DD-WRT on, try the Cisco-Linksys E3200. It has a ton of RAM and the CPU is actually faster at 500 MHz than the E4200 which is more expensive and only has a 480 MHz CPU. It also is the cheapest Gigabit Ethernet E series router that Cisco-Linksys offers. Here is the Cisco-Linksys E3200’s full specs on DD-WRT’s site. The E3200 is fully DD-WRT compatible but if you are lazy and don’t want to mess with DD-WRT, check out the built in QoS (Quality of Service) that the E3200 has built in on this video.
This is GREAT!!! The only problem I have is doing it by IP address since it’s normally assigned dynamically. My son’s computer is normally the bandwidth hog since he’s streaming movies and conducting internet life on a near 24/7 basis. I’ve gone so far as to create a separate wireless network for him and allow him to connect *only* to that WiFi network. I configured rules to prevent his network from being able to see any of the other networks so have essentially carved out a network that he and his friends can connect to. I’d *really* (emphasis on REALLY) love to be able to limit this network to a certain amount of bandwidth. (Think of it as a guest network per se.) If that isn’t possible, perhaps limiting by MAC address would be the second best option. I can’t tell you how many times my network has gone to a crawl (SSH sessions disconnecting, all hell breaking loose) because one of his friends comes over and is running a P2P program that sucks all the available bandwidth. I have 24Mbps download and 6Mbps upload on a pretty consistent basis so my network rocks – it just gets abused…
I’ve created a restriction policy and put it in place based on MAC address. I add his friends computers and apply the setting. BOOM! Internet is back to stable for me and there’s weeping and wailing coming from his bedroom. I hate to completely cut him off so just limiting him to 1-2Mbps would be ideal.
Please let me know if you can think of anyway to achieve this great feat!
Thanks!
Commented on December 1, 2011 at 10:49 pm
Yes you can limit it by making a different segment for him. For example, if your complete network is 192.168.1./24 like the examples given, you can set static IPs in the dhcp server of the router within the trusted range of 192.168.1.2-127, and then set the dhcp dynamic range to 128+
Then in the tc filter commands, use 192.168.1.128/25 instead of a specific IP address. That is shorthand for 192.168.1.128 with a netmask of 255.255.255.128. That makes all IPs 128 and above restricted to the limit set. And since that is the dynamic range given by the dhcp server, only trusted devices you assign IPs below 128 will not be subject to the limit. You can get fancy and add multiple limits, using 1:2 instead of 1:1 as well.
Commented on January 14, 2012 at 11:22 pm
Hello. I am about to buy a Netgear WNDR3300 router to apply this guide.
My goal is to limit the bandwidth use of an Ipod touch and a PC connected wirelessly to my current router.
My network also assigns random IP addresses to each device. I want to use your method to create two divisions of IPs in the DHCP server to help me set apart throttled devices from restriction-free ones.
Could you explain with a bit more detail how to create these “groups” and how do I assign static IPs to restriction-free devices?
I want to understand how this is going to work before I buy the router.
Thanks!!
Commented on April 3, 2012 at 12:59 pm
Look at setting up Vlans. Then apply the above to the Vlan you want. EX: Vlan1 is 192.168.2.x and Vlan3 is 192.168.3.x
Commented on March 22, 2013 at 3:24 pm
DD WRT has a function that allows the DHCP server to always issue a specific PC with the same IP address dynamically. This is done by associating a MAC address with a static IP lease. This can be set under the Services tab > DHCP Server > Static Leases. You put in the MAC address and the desired IP address (which should be out of range of the DHCP server) and that IP will automatically be assigned to that a specific PC whenever it connects.
This would then allow you to follow Mark’s instructions above.
Commented on August 24, 2012 at 1:45 pm
Hi, Need a solution:-
I have a belkin router in my home, my room mate have limited my bandwidth allocation, how can i reset the same. and get the access to the full bandwidth?
Thank you in advance
Commented on January 3, 2012 at 4:54 am
Hi
Great tutorial. It seems like it is exactly what I have been looking for….however, beeing a newbie in this field, I need a little more guidance to get all the way home.
quote: ” Because you’re going to enter shell commands, I recommend adding a public key for password-less authentication when you log in to DD-WRT.”
How do I add a public key?
Commented on January 5, 2012 at 4:53 pm
Perhaps you can tell us what each line of command means. I like to know what I’m doing. Also what if I am using a 15 Mbps internet connection. Will the commands be different? Lastly, how can I undo this. Thanks.
Commented on January 12, 2012 at 8:40 pm
actually this information is useful for me but i want to restrict all user who connect with my router in my office so who to do this for all user
please give me solution
as soon as possible it’s argent
Commented on January 14, 2012 at 6:36 am
Nice article, exactly what I’m looking for, except I am having a problem with step 2:
root@DD-WRT:~# tc class add dev br0 parent 1: classid 1:1 cbq \
> rate 1kbit allot 1500 prio 5 bounded isolated
RTNETLINK answers: No such file or directory
root@DD-WRT:~#
Anyone have any suggestions?
Commented on January 17, 2012 at 8:39 am
Oh duh, you mention that error and that I can ignore it. Reading: how does it work? =)
Commented on January 17, 2012 at 8:44 am
If I want to do this for a handful of different ips that are not in any particular range, is that possible?
Commented on February 3, 2012 at 12:29 pm
sorry to bother you, i was trying to do the same but with a liksys wrt54g2 but all i get is:
root@DD-WRT:~# tc qdisc del dev br0 root
RTNETLINK answers: No such file or directory
root@DD-WRT:~# tc qdisc add dev br0 root handle 1: cbq \
> avpkt 1000 bandwidth 6mbit
RTNETLINK answers: Invalid argument
root@DD-WRT:~# tc class add dev br0 parent 1: classid 1:1 cbq \
> rate 700kbit allot 1500 prio 5 bounded isolated
RTNETLINK answers: No such file or directory
root@DD-WRT:~# tc filter add dev br0 parent 1: protocol ip \
> prio 16 u32 match ip dst 192.168.1.249 flowid 1:1
RTNETLINK answers: Invalid argument
root@DD-WRT:~# tc filter add dev br0 parent 1: protocol ip \
> prio 16 u32 match ip src 192.168.1.249 flowid 1:1
RTNETLINK answers: Invalid argument
any ideas?
thanks in advance
Commented on February 15, 2012 at 8:25 pm
What operating system are you running?
Commented on October 5, 2012 at 1:57 pm
Great idea ! i would like to ask something more.
In my situation , i am in quite identical to yours, i have a 2 gig avalability at my laptop from a 30 gig at the model from the service provider. So i don’t ask help for that aspect, nothing can be done, already tryed. What i am concernng about is there is only one ”cvlient” me, but i have a constant 3 other pc that use my bandwith limit for free. ( it is accepted that way ) But my problem is that i have a limited bandwith download after what i have a penality fee by each gig over what make an expensive fine by the end of the month. Guess WHAT ? nobody take exess bandwith lolll ! so as i can’t see what every one use as programme and download, i don’t want to slowdown them but to install a ”filtering download bandwith limit for EACH one i add on my network ( under my rooter..dd-wrt linksys modelwrt54G/GL/GS.) Is there a setting or a command lines that would settle me for that ? That way, what ever or when ever they use the bandwith,when reached their each specified limit, their connection will be stop until the next paramater. ( ex: 500mb/day or 3 gig a week or 12 gig / month ) I would b able to have a better control of the bandwith regardless of anybody use,just by the mac adress download limit. Thank’s a lot
Notify me if something is confusing in my explanation
Commented on February 19, 2012 at 12:45 pm
hiii in my hostel someone is hacking the speed of wifi and his speed is of 1mbps but here in my laptop it is only 3 kbps .. plz help me what to do .. m cnfused
should i use any software..
or can anybody tell me what is that guy using and what is he doing … plz help me
Commented on February 23, 2012 at 10:33 am
hi
i have DIR-615(Dlink) and loaded DD-WTR for it.
i limited bandwidth with tc commands but
cleared all limitation when i turn off router
Commented on March 7, 2012 at 6:43 am
Hi Ali Reza,
Mind sharing with me on how you do it?
thanks
Commented on March 17, 2012 at 6:59 pm
Hi Reza, mind share the configuration step to me? tq
Commented on May 16, 2012 at 8:14 pm
I stumbled on your post and this is exactly what i am looking for. however, i can’t figure out
SSH to your router IP address:
ssh root@192.168.1.1
Enter password.
Type “ifconfig” and check which interface your router has configured as your internal default gateway. The IP address is often 192.168.1.1. The interface is usually “br0″.
How do i get there? I set up my private key and can connect thru WinSCP following the dd-wrt wiki.
Commented on March 14, 2012 at 10:06 pm
I’m stuck on the same thing – how do I “ssh to my router”?
Commented on September 30, 2012 at 6:01 pm
Google “putty.exe”. The first link should place you right on the download page. Free ssh client.
Commented on October 4, 2012 at 7:43 pm
Would this also work for Tomato firmware?
Commented on March 15, 2012 at 6:57 am
Hi, nice tutorial! I have one question – since our line is asynch in that we have 4Mbps down and 512kbps up, how would I limit the down speed to700kbps and the up speed to 100 kbps?
Thanks again, cool article!
Commented on May 18, 2012 at 5:47 am
HEY! CAN SOMEONE HELP ME! HOW CAN I DISABLE THIS LIMITATION, CAUSE MY BROTHER USED THIS “hogging of bandwidth”. I have DL SPEED of 400-2mb before but now it fell to 20kbps. Were sharing a Router…..
PLS HELP ME! im not that “techy” so EASY INSTRUCTIONS ARE VERY MUCH APPRECIATED!
THANKS IN ADVANCE!
Commented on May 19, 2012 at 8:55 pm
Now how to introduce packet delays and the like? That would be cool to know.
Commented on May 23, 2012 at 7:52 am
What a surprise.
Author uses technical terms unknown to non-techies … And lo and behold, author runs a technology company.
What a surprise.
Commented on June 10, 2012 at 11:16 am
It’s not even that technical, a subject like this requires a slightly techinical answer.
Have you considered instead of moaning about the lingo/jargo used. Actually Googling (that’s how you go here right) the lingo and consider reading. There is an ever increasing number of lazy people always wanting the quick solution with minimal learning. The author could not of made it any easier for you.
Thanks Mark, brilliant solution to quite a complex problem. I would ignore comments from the “sloth-like” people.
Commented on June 18, 2012 at 6:16 am
Great info – thanks! No good deed goes unpunished – I have two questions. First, do you know how to apply the limit to the upload speed? Second, is there a line to remove the rule, aside from just increasing the limit?
Thanks again!
Commented on July 2, 2012 at 3:29 pm
Just restore your router to default using reset button for 30 sec
Commented on March 22, 2013 at 3:14 pm
Hey, nice tutorial 😀 I wish my Router supported it :/ My Italian room mate has been hogging the bandwidth for ages.
Ignore the stupid, arrogant haters in above posts 😛
You sure know your stuff!
Thanks
Commented on August 12, 2012 at 4:52 am
I am running a cyber cafe with 10 computers, DIR 615 dlink router and a wimax MODEM for internet. All the computers are connected to the router through wirelless cards. How can I limit the download and upload bandwith through my rouuter? THANKS in advance.
Commented on September 7, 2012 at 1:09 am
Follow the above instructions, or hire someone to configure it.
Commented on January 20, 2013 at 2:28 pm
Excellent tutorial, which after I’ve digested it will probably do just what I’m looking for. Many thanks Mark!
Just one aside: I’ve printed the man page for tc and have to say that whilst I have some experience with Linux, the tc command seems pretty opaque!
Commented on January 2, 2013 at 4:10 pm
OK, I’ve run the tc commands and the router didn’t snivel, so maybe it’ll work.
What sort of tc command can I run to check that the commands have ‘taken’, so I can be sure that my brother-in-law will be bandwidth limited when he stream sports channels when he visits us, please?
Jim
Commented on January 3, 2013 at 10:21 am
Sir i am in a hostel. our wifi is hacked by one of our colleague. only his laptop has wifi connectivity 24*7. I am not able to connect. i think he has hacked our wifi for sure. please help me i am in deep trouble
Commented on February 23, 2013 at 3:08 am
Try net cut utility. U can identify his IP address and MAC too and prevent him from disconnecting you from the network.
Commented on April 2, 2013 at 11:44 pm
Hi Mark, awesome tutorial!, listen we have are a small company in Mexico City and I need your help to to this, I tried to follow the steps mentioned here but when I run this command “tc qdisc del dev br0 root” it throws “RTNETLINK answers no such file or directory” anyways, I was wondering if you could help us via skype of course we will pay for your advice, could be anytime any day just let me know, my email is ferfr01@gmail.com
Thanks in advance!
Commented on April 4, 2013 at 10:37 am
Is there a way to determine if this change to my router is working? All of the commands executed without an error so I am assuming everything is working. Right?
Commented on June 8, 2013 at 8:54 am
My satellite ISP has a 30 day usage limit of 10gb, which is enough for my needs, but when guests visit I’d like to limit their total usage to 100mb per day or less.
Does anyone know if this can be accomplished?
Commented on August 16, 2013 at 10:17 am
How do you apply this on ip ranges? Do I have to redo the commands every time per ip?
Commented on September 4, 2013 at 7:13 am
How do you apply this for ip ranges? Do I have to redo the commands every time for each ip address?
Commented on September 4, 2013 at 7:14 am
How do you apply it for ip ranges? Do I have to execute the commands every time for each ip?
Commented on September 6, 2013 at 2:52 am
Hi,
I’m not sure if anyone is still reading these comments but I had a questions I was hoping someone could help me answer.
I have several hosts in my network that I would like to limit the bandwidth so that no one can exceed 3mbits so that one person doesn’t hog the entire line.
Should I just make another filter entry for each IP and put them all under the same class or do I have to create a separate class and/or qdisc for each IP that I want to limit?
Commented on November 26, 2013 at 2:24 pm
How to provide the limited data for IP addresses to the month? IS ANY ONE HELP ME ON THIS Section?
Commented on November 29, 2013 at 11:17 am
Hey I wanted to know what are the commands for setting QoS on basis of services? Please help me
Commented on December 10, 2013 at 4:23 am
Enabling SSH Remote Management is not needed and can open your router to possible attacks. I wouldn’t recommend it.
Awesome blog post. Helped me throttle a friend who is staying with me for a while. He’s a Steam fan and downloads new games daily and it was dragging my 5Mbit DSL connection threw the mud. This seems to be working beautifully. Thanks!
Commented on March 24, 2014 at 2:59 pm
you’re truly a just right webmaster. The site loading speed is incredible. It kind of feels that you are doing any distinctive trick. In addition, The contents are masterpiece. you’ve performed a magnificent task in this subject! faegeekbagkg
Commented on April 29, 2014 at 7:40 pm
nice commands … However this is NOT needed anymore in the new dd-wrt firmware versions …. I am using dd-wrt v24-sp2 (05/27/14) build 24160 … Under QoS , you have full control on bandwidth limit for upload and download for either aggregated WAN interface , or per client, per MAC address , service , just full control over bandwidth limitation ….
My dd-wrt router is the second router which is cascaded to my main (fast router), and I am using the aggregated WAN limit to avoid limiting users one by one , so guests and bandwidth abusing users are allowed only to access dd-wrt router
P.s. My home router has bandwidth of 24MB, while I limited the dd-wrt router with 512kbps only …. It’s working like charm 🙂
Commented on July 13, 2014 at 5:53 am
Thanks for an easy to follow howto. The tc’s manpage is dense and it great to have a useful application. I would like to make a change to limit the bandwidth everyone on a particular subnet (my guest wifi is on a different subnet). Is it possible to replace the IP address by a netmask in the tc command lines? Thanks in advance!
Commented on January 3, 2015 at 4:30 pm
I’d like to know this also!
Commented on January 17, 2015 at 11:44 am
what happens if there is a file server on the network? will this also rate-limit the file transfer?
Commented on February 2, 2015 at 8:53 pm
hello,
we tested the rules limiting download and works properly but the rules limiting upload not working nor for Mac or by ip. Can you help us?
thanks
Commented on March 16, 2015 at 11:50 am