Convenient Routing with Dnsmasq

If you're a web developer, you may have this issue: Creating a new virtual host in your HTTP server (I still use Apache, so sue me) works fine, but then there's that hosts file where you always have to add the new domain (e.g. mynewproject.dev) and link it with - but not anymore! There's a very simple way of adding and routing a wildcard domain with a quite powerful programme named dnsmasq. Thanks to tomchuck for this solution.
First, get dnsmasq from your repo.
sudo apt-get install dnsmasq
Then create your config file. Note: All files in this folder are parsed by dnsmasq. This allows easy management of different IP ranges.
sudo vim /etc/dnsmasq.d/my-local
Put this into your config:
Save and close the file, then restart the dnsmasq service.
sudo service dnsmasq restart
Now open your DNS config.
sudo vim /etc/resolv.conf
Add your computer as DNS server. Note: If you're planning to use other domains than .dev, you should put it at the top of the file, or at least higher than other nameserver entries.
To make sure everything worked, ping a .dev domain.
ping test.dev
Oh, and you probably want to create an init.d/ script for the dnsmasq service to start on boot.

No comments:

Post a Comment