MacKuba

🍎 Kuba Suder's blog on Mac & iOS development

Bandwidth limiting in MacOSX

Categories: Mac Comments: 0 comments

I played a bit with bandwidth limiting tools in MacOSX recently. The reason was that I was uploading huge files to DivShare, and my Firefox took all the available upload bandwidth; and since upload bandwidth happens to be quite useful even when you’re not really uploading anything, everyone at home (including me) had serious problems with using the web at the time. So I thought I could try to force Firefox somehow to limit the maximum upload speed.

I’ve found a plugin which does exactly that, but it was only for Windows… (a plugin for a cross-platform browser which is not cross-platform? come on…). So I started looking for some system-wide solution. I found two pages that explained how to do this – it turns out it’s pretty easy, at least for someone that’s not afraid of the command line.

Everything is done using the ipfw command (IP FireWall?…). First you have to create one or more “pipes” with a constant share of bandwidth assigned:

sudo ipfw pipe <pipe_nr> config bw <amount>kbit/s

(I’m guessing “bw” is for “bandwidth”…) Then you can (if you want) create one or more “queues” in each pipe, with priorities or weights assigned. Users of one queue may borrow bandwidth from another queue if it doesn’t use it, but you can’t borrow bandwidth from another pipe. Queues are defined like this:

sudo ipfw add queue <queue_nr> config pipe <pipe_nr> weight <weight>

(Weight is an integer number between 0 and 100.) And then you write filters that direct specific traffic to chosen pipes and queues. Filters can match IPs, ports, and probably other things too…:

sudo ipfw add pipe <pipe_nr> [not] [dst-port <port> | src-ip <ip> | dst-ip <ip> | ...]

You can always clear all the rules using:

sudo ipfw flush

In my case it was simpler – I didn’t need any complex traffic shaping rules with priorities and so on, I just wanted to cut Firefox’s speed a bit. So that was all I needed:

sudo ipfw pipe 1 config bw 200kbit/s
sudo ipfw add pipe 1 dst-port http

That way I directed all HTTP traffic to pipe number 1, limiting it to 200 kbit/s, leaving the remaining 312kbit/s for everything else. Firefox’s upload speed immediately fell down to about 25 KB/s, my sister stopped complaining, and everyone was happy ;) Later I also found a GUI program which is supposed to control traffic shaping, called Dummymac, but for some reason it doesn’t work at all on my computer, it doesn’t even start. Maybe it’s incompatible with Leopard… I guess I’ll have to learn some Objective C and write my own :)


Leave a comment

*

*
This will only be used to display your Gravatar image.

*

What's the name of the base class of all AppKit and UIKit classes?

*