Skip to content

How to Throttle Your Internet Connection

Tags: digital-minimalism, productivity • Categories: Productivity

Table of Contents

A conversation with a friend recently turned me on to PFSense. It’s an open source firewall system that enables you to control what’s happening in your network. One of the features it enables is packet throttling.

It got me thinking, can I throttle my internet connection speed just on my local machine?

I’ve been interested in digital minimalism for a long time. One of the things I’ve never been able to crack is nudging me towards stopping the use of all of my devices without forcing me to do so. If I’m forced, I’ll need an escape hatch for when my predetermined schedule doesn’t work, and then I’ll abuse that escape hatch. However, if I’m nudged towards turning off all of my technology for the day, I won’t end up looking for the escape hatch, and I’ll just become annoyed enough that I’ll stop using it.

Throttling my internet connection speed after a certain point in the day would be the perfect solution for me. I could tie this in as a script that fires off using my productivity tool hyper-focus so at a certain point in the day, my internet my internet connection would be automatically throttled & unthrottled.

Shell Scripts to Throttle Your Mac’s Network Connection

After bumping into this npm package I knew it was possible and was able to simplify usage to a couple shell scripts which I integrated into my hyper-focus config:

throttle-internet() {
    local DOWNLOAD_LIMIT="1000Kbit/s"
    local UPLOAD_LIMIT="200Kbit/s"

    # Configure pipe for incoming traffic (download)
    (sudo dnctl pipe 1 config bw $DOWNLOAD_LIMIT && echo "Download pipe configured") || echo "Failed to configure download pipe"

    # Configure pipe for outgoing traffic (upload)
    (sudo dnctl pipe 2 config bw $UPLOAD_LIMIT && echo "Upload pipe configured") || echo "Failed to configure upload pipe"

    # Apply the rules to all devices
    sudo pfctl -f - <<-EOF
dummynet-anchor "throttle"
anchor "throttle"
EOF

    # Enable PF if not already enabled
    sudo pfctl -e

    sudo pfctl -a throttle -f - <<-EOF
dummynet in all pipe 1
dummynet out all pipe 2
EOF

    echo "Throttling applied to device en1"
}

unthrottle-internet() {
    echo "Unthrottling internet..."

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

    echo "Throttling removed"
}

The only issue with this approach is that it throttles all network traffic, even if you’re using your local device’s IP for communication with an application. This means it’s not just all internet traffic that’s throttled, but any traffic on your local network, and that includes just communication with other applications on your computer. Depending on how certain applications are architected, this can be quite annoying. But it’s worked pretty well for me and has encouraged me to stop using my computer at night and on Sundays.