Skip to content

Instantly share code, notes, and snippets.

@dews
Last active October 23, 2024 15:04
Show Gist options
  • Save dews/3e31edaafb718e410ded9226c2545734 to your computer and use it in GitHub Desktop.
Save dews/3e31edaafb718e410ded9226c2545734 to your computer and use it in GitHub Desktop.
Limit mac bandwidth

Mac limit bandwidth

Enable firewall

Apple menu -> System Preferences -> Security & Privacy -> Firewall

sudo pfctl -e

Example

sudo dnctl pipe 1 config bw 10Kbit/s
sudo dnctl pipe 2 config bw 10Kbit/s
# The second will overwrite first. If you want to set both, use next example
echo "dummynet in all pipe 1" |sudo pfctl -f -
echo "dummynet out all pipe 2" |sudo pfctl -f -

Example - limit speed, set in and out in the same time

echo $'dummynet in all pipe 2\n dummynet out all pipe 1' |sudo pfctl -f -
echo $'dummynet in all from any to example.com pipe 2\n dummynet out all from any to example.com pipe 1' |sudo pfctl -f -

Example - block domain

echo $'block in proto tcp from jrxncdkk2ls00000.m2.exosite.io to any' |sudo pfctl -f -

When you're done

sudo dnctl -q flush
sudo pfctl -f /etc/pf.conf

Disable firewall

sudo pfctl -d

Show info

sudo pfctl -sa

Ref:

https://spin.atomicobject.com/2016/01/05/simulating-poor-network-connectivity-mac-osx/

@AngDrew
Copy link

AngDrew commented Apr 13, 2021

thanks a lot! it helps so much

@andreamoro-git
Copy link

the rule echo $'dummynet in all from any to example.com pipe 2 [...etc...]

stdin:1: syntax error
pfctl: Syntax error in config file: pf rules not loaded)

I am trying to limit bandwidth for a specific streaming site that doesn't let me choose video quality... any clue?

@chajiuqqq
Copy link

Using GUI application is easier to limit bandwidth or delay or loss, such as Apple's Network Link Conditioner
See bandwidth-shaper-or-bandwidth-controller-application-for-mac-os-x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment