2

Assume I have a VM running on OSX with private IP 10.0.0.1 which can be accessed from the host machine.

I was wondering how can I map a pseudo domain, *.app.dev, to the private IP on my host machine so that on my host machine I can resolve the domain *.app.dev to 10.0.0.1.

The purpose of this setup is to have virtual environment for development and not pollute my host machine with unnecessary packages and services.

edit: I realize that /etc/hosts can accomplish non wildcard domain names, I should have been more clear and mention wildcard domain names.

Bill
  • 123

2 Answers2

3

You can do this with dnsmasq.

Dnsmasq is a very small DNS server usually used as a proxy. It offers a lot of ways to manipulate DNS lookups, one of which is to respond to all DNS queries for a domain with a single IP.

The example dnsmasq.conf file has specific example for this:

# Add domains which you want to force to an IP address here.
# The example below send any host in double-click.net to a local
# web-server.
#address=/double-click.net/127.0.0.1

The following 2 lines are all that you would need to get running

server=8.8.8.8
address=/app.dev/10.0.0.1

(You can change the server parameter to whatever upstream server you want. Or use resolv-file to use a resolv.conf file)

Then just configure your system to use 127.0.0.1 as a DNS server.

phemmer
  • 71,831
  • Thanks for this answer, (with the help of http://bhamrick.com/2013/04/18/setup-a-wildcard-tld-using-dnsmasq-on-os-x/) I was able to achieve the desired outcome! – Bill Oct 27 '13 at 03:44
1

The easiest way is to add the following line to /private/etc/hosts:

10.0.0.1  app.dev 
jofel
  • 26,758