Last Updated: February 25, 2016
·
2.42K
· jdotpy

Linux: iptables port forward to use with Vagrant.

If you are using Vagrant to host your local dev environment you might want to access your apps the way: http://yourdomain.local.

First, add this line to the host /etc/hosts file:

127.0.0.1 yourdomain.local

Save the changes and then type:

$ sudo iptables -t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 80 -j REDIRECT --to-ports 8080

And the trick is done.

A better alternative is to use a rack application proxy like Prax: https://github.com/ysbaddaden/prax