Skip to content

Instantly share code, notes, and snippets.

@pajtai
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pajtai/16df0303d7948f0e4da8 to your computer and use it in GitHub Desktop.
Save pajtai/16df0303d7948f0e4da8 to your computer and use it in GitHub Desktop.
Using pf for port forwarding on macs

Since ipfw is deprecated and removed on Yosemite and Maveriks, and there are no iptables on Mac you have to use pfctl for port forwarding.

This is important in Vagrant, where usually port 8080 is exposed, but you want to be able to use port 80 on your host browser.

Here is how to setup 80 <-> 8080 port forwarding on your mac (include empty lines at the end of each file... one of them is supposedly picky about it).

After adding the two files below as root, to start (enable) port forwarding do:

sudo pfctl -ef /etc/pf-vagrant.conf

To stop (disable) port forwarding do:

sudo pfctl -d
# /etc/pf-vagrant.conf
rdr-anchor "forwarding"
load anchor "forwarding" from "/etc/pf.anchors/vagrant.forwarding"
# /etc/pf.anchors/vagrant.forwarding
rdr pass on lo0 inet proto tcp from any to 127.0.0.1 port 80 -> 127.0.0.1 port 8080
rdr pass on lo0 inet proto tcp from any to 127.0.0.1 port 443 -> 127.0.0.1 port 8443
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment