Skip to content

Instantly share code, notes, and snippets.

@markusguenther
Last active November 6, 2019 08:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markusguenther/8655d2924cc97eb9d1f19e73bdeaa019 to your computer and use it in GitHub Desktop.
Save markusguenther/8655d2924cc97eb9d1f19e73bdeaa019 to your computer and use it in GitHub Desktop.

Setup local domain without a DNS

step 1 : Assign at least two IP address to your MAC OS (one per domain), let's say :

192.168.0.10
192.168.0.11

To setup the second IP you will have to add a second Ethernet Adapter (logical not physical).

Step 2 : As you don't have a DNS server, you could setup your /etc/hosts file, by adding :

192.168.0.10     dev.foo.com
192.168.0.11     dev.bar.com

Step 3 : Assign aliases to your loopback interface :

sudo ifconfig lo0 192.168.0.10 alias
sudo ifconfig lo0 192.168.0.11 alias

Step 4 : Setup ipfw to forward packets :

sudo ipfw add fwd 127.0.0.1,123 tcp from me to 192.168.0.10 dst-port 80
sudo ipfw add fwd 127.0.0.1,456 tcp from me to 192.168.0.11 dst-port 80

You are done !

Now :

http://dev.foo.com redirects to localhost:123 http://dev.bar.com redirects to localhost:456

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment