Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Bandwidth throttling in OS X UNIX
Advanced OS X users know that Darwin comes with ipfw, which can be used to set up a custom firewall. This same service however can be used to also limit bandwidth on specific ports.

Example:
sudo ipfw pipe 1 config bw 15KByte/s
creates a pipe that only allows up to 15KB/s to go through.

Then:
sudo ipfw add 1 pipe 1 src-port 80
will attach that pipe to the outgoing traffic on port 80, effectively limiting the outgoing traffic of the web server.
sudo ipfw delete 1
will remove the pipe from the port.

[kirkmc adds: I haven't tested this. Just make sure you remember to turn this off when you no longer need it!]
    •    
  • Currently 4.46 / 5
  You rated: 3 / 5 (13 votes cast)
 
[124,253 views]  

Bandwidth throttling in OS X | 18 comments | Create New Account
Click here to return to the 'Bandwidth throttling in OS X' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Bandwidth throttling in OS X
Authored by: diamondsw on Jan 22, '08 07:58:54AM
Once you have a set of rules that do what you want, it's pretty simple to create a shell script to create those, and a launchd plist to run it on boot. I actually just did something like this on my home network.

(Be nice to my poor Mini, and note that it's under the same bandwidth throttling that's described here!)

[ Reply to This | # ]

Bandwidth throttling in OS X
Authored by: phoopee3 on Jan 22, '08 05:09:09PM

Is this because the rules clear every time the computer reboots? Just curious. I'm looking to use this in an office environment to single out some people who download stuff and hog my bandwidth :)

---
When you do things right, people won't be sure you've done anything at all.



[ Reply to This | # ]
Real-time Changes
Authored by: lullabud on Jan 22, '08 08:08:55AM

One awesome thing about this is that the changes are made in real-time, so if somebody is hogging your bandwidth you can do this trick without having to restart your network or even lose connection of open sockets. This is great for when torrents are killing your surfing speeds, when somebody begins leeching your web-share, etc., because you don't have to kill those active connections to gain the benefit of throttling. This also allows you to use a real-time graph to view the difference your rule is making so you can tweak if necessary.



[ Reply to This | # ]
Bandwidth throttling in OS X
Authored by: zeb on Jan 22, '08 08:52:04AM

That's awesome! I've always wanted to know how to limit my bandwidth so I can test how my websites are loading at dial-up speeds.

Great tip!

---
..:: Zeb ::..

zebellis.com



[ Reply to This | # ]
Bandwidth throttling in OS X
Authored by: picoscope on Apr 30, '08 02:22:12PM

This is a great tip, but does anyone know of a way to limit individual users' TOTAL bandwidth over time? For instance, limit Joe User to download 100MB over 24 hours?



[ Reply to This | # ]
Bandwidth throttling in OS X
Authored by: macshome on Jan 23, '08 11:21:41AM

For those of you wanting more...

We've got a pretty detailed article about dummynet on AFP548.com. I think that MacGeekery.com does as well.

---
http://www.afp548.com
Breaking my server to save yours.



[ Reply to This | # ]
Bandwidth throttling in OS X
Authored by: robleach on Jan 23, '08 01:32:33PM

Well, this is cool. I've been using 'throttled', but I think I may like this technique better because when I watch the network activity, I'm not sure throttled is working very well. The graph in the network monitor definitely goes above the limits I set occasionally. I thought I remembered it working really well when I first set it up, but now I tend to get page stalls when browsing during a period of a lot of network activity (up/downloads going on on my mini). I've been assuming that my issues may stem from wireless network interference, but running iStumbler shows the interference is low. Ah well. I'll try this out. How do I limit bandwidth on all outbound (and separately inbound) ports instead of just one port?

Thanks,
Rob



[ Reply to This | # ]
Bandwidth throttling in OS X
Authored by: redguy on Jan 23, '08 01:52:54PM

One can Waterroof, a very nice frontend that exposes a lot of these features .
http://www.hanynet.com/waterroof/



[ Reply to This | # ]
Bandwidth throttling in OS X
Authored by: regulus on Jan 26, '08 08:34:46AM

This is not working for me. I tried it out on a filesharing (AFP) connection between 2 computers on my home network. From one computer I mounted the hard drive of the second computer. I then transferred a 65 MB file and found that I was getting a transfer speed of over 20 MB/s on my gigabit ethernet network. Then I tried the commands to limit the transfer speed as follows...

sudo ipfw pipe 1 config bw 1MByte/s
sudo ipfw add 1 pipe 1 src-port 548

I then transferred the file again and my transfer speed dropped dramatically, but it dropped to 5 MB/s instead of 1 MB/s. I played around with the commands but no matter what speed I set it always transfers at 5 MB/s. When I delete the rule and the pipe my transfer speed again shoots to over 20 MB/s, so it is doing something but it does not limit the transfer speed as set.

Any thoughts or suggestions?



[ Reply to This | # ]
Bandwidth throttling in OS X
Authored by: jaguarcy on Jan 29, '08 09:43:41AM

Are you measuring the speed in megaBytes, or megabits? 1MByte/s is about 8Mbits/s... That could be one explanation.



[ Reply to This | # ]
Bandwidth throttling in OS X
Authored by: TalonGold on Nov 05, '09 03:39:28PM

I've tried ALL of the ones listed here, AFP simply seems to NOT listen to the ipfw...

All i want to do is regulate AFP bandwidth on my network, anybody have a way to do that?



[ Reply to This | # ]
Bandwidth throttling in OS X
Authored by: regulus on Jan 30, '08 04:56:52AM

Thanks for the suggestion, but that's not it. No matter what speed I set in the shell command (i.e. 1 MB/s or 10 MB/s) it always throttles it to the same speed of 5MB/s. So even if I did confuse mb with MB I still would have seen a difference when changing speeds... but I don't.



[ Reply to This | # ]
Bandwidth throttling in OS X
Authored by: jaguarcy on Jan 31, '08 04:14:09AM
How about adding the pipe to dst-port 548 as well, or to dst-ip ...
Strange, really strange.

[ Reply to This | # ]
Bandwidth throttling in OS X
Authored by: mauldus on Oct 14, '08 04:57:23PM
Note: You may need to set the net.inet.ip.fw.one_pass variable so the packet doesn't pass through to the next firewall rule.

sudo sysctl -w net.inet.ip.fw.one_pass=1

You can also issue the config command again with different bandwidth settings to fine tune the limit without tearing it down and rebuilding it.

[ Reply to This | # ]
What about just iTunes
Authored by: josephaw on Oct 16, '08 10:05:08AM

I want to only throttle the iTunes application. The above tip works fine with iTunes with port 80 but what if I want my other applications to have full access to my bandwidth?
Is there a way from the command line to just limit specific applications?
Thanks, Joe



[ Reply to This | # ]
What about just iTunes
Authored by: HarleyDavidson01 on Dec 13, '08 03:02:29PM

Lighthouse will let you select an app, forward info from the normal port to another internal port, and when used with the script described before, and the internal port number, you can slow a specific app down, while leaving the others to use as much bandwidth as there is left over. This type of solution would work even better if you could define similar behavior by ip adress from inside an airport router, but apple hasn't seen fit to make that part of their software. Still, lighthouse is a great app for this type of control. You can redirect traffic from any number of ports to a single port, and set how much bandwidth the internal port has using these scripts. You can even schedule it using the latest iCal in Leopard if you save these as terminal scripts. If you can find freeware for redirecting by application, please post. I'd love to be able to try it.



[ Reply to This | # ]
Bandwidth throttling in OS X
Authored by: HarleyDavidson01 on Dec 13, '08 03:12:54PM

Hello everybody,
I've seen applications that forward ports based on the application you specify. You could forward information for any app through these, set one specific port, then use the commands at the top of this thread to limit bandwidth to that port. Remember, when you use these commands you are specifying the internal destination; and if you've routed one port to another for a specific application, the only port you need to worry about is which one the application will "see" or use. This will allow you to limit bandwidth to that internal port, and it will "pull" information through the outer one at the limit you've defined. I've tried lighthouse, great for this, but I believe there are others that are freeware. I hope this helps somebody.



[ Reply to This | # ]
Bandwidth throttling in OS X
Authored by: TalonGold on Nov 05, '09 03:39:50PM

I've tried ALL of the ones listed here, AFP simply seems to NOT listen to the ipfw...

All i want to do is regulate AFP bandwidth on my network, anybody have a way to do that?



[ Reply to This | # ]