Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 xyz.com to some ip in the hosts file like 157.166.226.25 and then:

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

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
1  
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. –  Thomas Sep 15 '12 at 17:14
add comment

2 Answers

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 http:www.example.com in class and have it served by a node.js server listening in on 127.0.0.1 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
add comment

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

  • Assign multiple ip to your nic : 127.0.0.1, 157.166.226.25, 10.0.0.1, 1.2.3.4 ...
  • 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 http://unix.stackexchange.com or http://superuser.com

share|improve this answer
add comment

Your Answer

 
discard

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.