1

On my production Debian server I use this to forward requests that come in to port 80 to a non-root process running on port 8080:

sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

(The process is a Node.js cluster, but I doubt that it's relevant to this question.)

I develop on my Mac and am trying to build a more elegant environment for myself without adding any unnecessary software to my computer. I added an entry to my /private/etc/hosts file so I can use a pretty local domain:

127.0.0.1 myapp.dev

Now I want to access it without specifying a port. In other words, rather than http://myapp.dev:8080, I would prefer http://myapp.dev. I would also prefer not running my web server directly on port 80 so that it does not have root privileges.

I know my computer comes with a firewall, but I have not been able to find much information about it. So I'm looking for a simple way to forward anything coming to port 80 off to port 8080 like the IP Tables solution on Debian. I would most prefer to use the firewall that came with my computer and to set this up in the simplest way possible.

Can anyone tell me how to do this?

Bonus Points: Is there a simple way to ignore all requests coming to port 80 (and 8080 for that matter) except those from my own computer on which the web server is running?

1

One solution, using IPFW, which co-exists with PF as of OS X 10.9 (Mavericks) is to simply run the command:

sudo ipfw add 100 fwd 127.0.0.1,8080 tcp from any to me 80

You must log in to answer this question.