Skip to content

Instantly share code, notes, and snippets.

@mandarinx
Last active August 29, 2015 14:07
Show Gist options
  • Save mandarinx/ce22eb9a51de2ea624da to your computer and use it in GitHub Desktop.
Save mandarinx/ce22eb9a51de2ea624da to your computer and use it in GitHub Desktop.
Port forwarding on OS X

Edit the hosts file

sudo nano /etc/hosts

Add this line somewhere after 127.0.0.1 localhost:

127.0.0.1       your.domain.com

Save and exit (Ctrl + O, Ctrl + X). Flush the DNS cache:

dscacheutil -flushcache

###Port forwarding

Place the following code in /etc/pf.anchors/localhost.dev:

rdr pass on lo0 inet proto tcp from any to any port 80 -> 127.0.0.1 port 3000

NOTE: The trailing line break is required. Otherwise pf will say you have a syntax error.

Next, add two lines to /etc/pf.conf to load your new rule. It is important where these lines go. Add this line right after rdr-anchor "com.apple/*":

rdr-anchor "localhost"

Add this line directly after load anchor "com.apple" from "/etc/pf.anchors/com.apple":

load anchor "pow" from "/etc/pf.anchors/com.pow"

Again, make sure to maintain the final line break.

Next, reload the rules into pf by running sudo pfctl -f /etc/pf.conf

Finally, enable pf by running sudo pfctl -e

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