Port forwarding for Vagrant on OSX: ipfw is depreciated
Further to @sgarbesi's response, ipfw was indeed depreciated as of OS X Mavericks. Unfortunately I couldn't access the solution he posted as the link appears to be broken.
He is credited in the solution described here, however: https://www.danpurdy.co.uk/web-development/osx-yosemite-port-forwarding-for-vagrant/
I'm pasting the solution here for completeness, in the hope that it helps someone:
Set up port fowarding on the VM
Add the following to your Vagrantfile, as per the Vagrant documentation:
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "forwarded_port", guest: 443, host: 4443
Install Vagrant Triggers
To install vagrant-triggers you should navigate in a terminal window to the folder where your Vagrantfile is kept and run the following command:
vagrant plugin install vagrant-triggers
Use Vagrant Triggers to automatically enable port forwarding
Add the following to your Vagrantfile:
config.trigger.after [:provision, :up, :reload] do
system('echo "
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 4443
" | sudo pfctl -ef - > /dev/null 2>&1; echo "==> Fowarding Ports: 80 -> 8080, 443 -> 4443 & Enabling pf"')
end
config.trigger.after [:halt, :destroy] do
system("sudo pfctl -df /etc/pf.conf > /dev/null 2>&1; echo '==> Removing Port Forwarding & Disabling pf'")
end
This binds ports 80 and 443 to ports 8080 and 4443 respectively on Vagrant Provision, up and reload and removes it on halt or destroy. Note that pf is not enabled by default on OSX so we pass the -e flag when we add the rules to enable pf and the -d flag to disable it again when we remove the port forwarding.