This guide is a fork from this gist.
Since Mavericks stopped using the deprecated ipfw
(as of Mountain Lion), we'll be using pf
to allow port forwarding.
Create an anchor file under /etc/pf.anchors/com.vagrant
with your redirection rule like:
important note the trailing whitespace is nessesary
rdr pass on lo0 inet proto tcp from any to any port 80 -> 127.0.0.1 port 8080
rdr pass on lo0 inet proto tcp from any to any port 443 -> 127.0.0.1 port 8443
rdr pass on en0 inet proto tcp from any to any port 80 -> 127.0.0.1 port 8080
rdr pass on en0 inet proto tcp from any to any port 443 -> 127.0.0.1 port 8443
Parse and test your anchor file to make sure there are no errors:
sudo pfctl -vnf /etc/pf.anchors/com.vagrant
/etc/pf.conf
is the main configuration file that pf
loads at boot.
We'll need to load the anchor file we previously created:
rdr-anchor "com.vagrant"
load anchor "com.vagrant" from "/etc/pf.anchors/com.vagrant"
Make sure to add these entries to the appropriate spot, like:
scrub-anchor "com.apple/*"
nat-anchor "com.apple/*"
rdr-anchor "com.apple/*"
rdr-anchor "com.vagrant"
dummynet-anchor "com.apple/*"
anchor "com.apple/*"
load anchor "com.apple" from "/etc/pf.anchors/com.apple"
load anchor "com.vagrant" from "/etc/pf.anchors/com.vagrant"
pf
is enabled by default in Yosemite, so if the above doesn't work, reload pf by running the following:
sudo pfctl -ef /etc/pf.conf
run sysctl -w net.inet.ip.forwarding=1;
resatrt your system, and do the bove steps again
There is the possibility that pf.conf
will be overriden with updates to the OS. It might be best to create your own pf config file and load them in additon to the main pf.conf
to prevent this.