Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
OS X Redirect ports 80 and 443 to 8080 and 8443 respectively

Changes with .dev domains in mind.

Create /etc/pf.anchors/dev, containing:

rdr pass inet proto tcp from any to any port 80 -> 127.0.0.1 port 8080
rdr pass inet proto tcp from any to any port 443 -> 127.0.0.1 port 8443

Edit /etc/pf.conf. After rdr-anchor "com.apple/*" insert rdr-anchor "dev" (on its own line). After load anchor "com.apple" from "/etc/pf.anchors/com.apple" insert load anchor "dev" from "/etc/pf.anchors/dev" (again on its own line). It'll look something like this:

scrub-anchor "com.apple/*"
nat-anchor "com.apple/*"
rdr-anchor "com.apple/*"
rdr-anchor "dev"
dummynet-anchor "com.apple/*"
anchor "com.apple/*"
load anchor "com.apple" from "/etc/pf.anchors/com.apple"
load anchor "dev" from "/etc/pf.anchors/dev"

Test the config:

sudo pfctl -v -n -f /etc/pf.conf

Then reload:

sudo pfctl -ef /etc/pf.conf
@Dobika

This comment has been minimized.

Copy link

@Dobika Dobika commented Aug 10, 2018

Hello!

Thank your for this gist. Is it possible to make pfctl permanent? I have to run it every startup.

@immersiontravis

This comment has been minimized.

Copy link

@immersiontravis immersiontravis commented Aug 20, 2018

@Dobika, I haven't tried this yet, but this guy has a recommended solution that uses the vagrant-triggers plugin:

https://www.danpurdy.co.uk/web-development/osx-yosemite-port-forwarding-for-vagrant/

@Dobika

This comment has been minimized.

Copy link

@Dobika Dobika commented Sep 17, 2018

Thank you @immersiontravis, I'll look into it!

@Haarolean

This comment has been minimized.

Copy link

@Haarolean Haarolean commented Jun 8, 2019

There's no need to tamper the pf.conf itself, you can create a custom one.
touch /etc/pf-anything.conf

@jbis9051

This comment has been minimized.

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