Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to create a demo for a class of mine and I want to configure "fake" domain names on my laptop.

A previous question "Can I specify a port in an entry in my /etc/hosts on OS X?" contained an answer indicating that to do it you must use /etc/hosts plus changes to the iptables

"If OS X uses iptables you could point to some ip in the hosts file like and then:

sudo iptables -t nat -A OUTPUT -p tcp --dport 80 -d -j DNAT --to-destination "

Since OS X doesn't use iptables, how do I do the equivalent using the tools available on OS X? (the original "asker" seemed to know how to do this, so it wasn't explained).

Thanks in advance.

share|improve this question
In theory you could set up a reverse proxy to do the job. But I agree with Jenny D some more Input on the target scenario would be helpful. – Roman Sep 15 '12 at 17:14

I'm unclear of how you want to use this, which makes it hard to give a good answer. Is there any particular reason why you can't just use virtual hosts in your webserver instead of setting up separate webservers on separate ports?

I've not found any way to do port redirects with the firewall included in a non-server distribution, but another thing you could do is to set up an apache webserver as a reverse proxy, or use socks.

share|improve this answer
Maybe I should go the route of using apache as a reverse proxy, but I thought that using /etc/hosts plus changes to iptables seemed an more straightforward approach. I just want to type in class and have it served by a node.js server listening in on port 3001 (or something). I need to have several servers running on localhost at the same time for the demo. – Fred Finkle Sep 15 '12 at 17:19
Given your requirements, I'd go with the other answer from Eric Dannielou instead. – Jenny D Sep 17 '12 at 6:54

If it's for a class demo, I'd do a much simpler thing than using firewall :

  • Assign multiple ip to your nic :,,, ...
  • Modify /etc/hosts accordingly.
  • Make your different services listen on those ip on port 80.

However, this site is not for home related questions, you may be interested in similar sites like or

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.