Recently there was a requirement to configure local domains like simpsoft.local, jenkins.simpsoft.local etc.. for the development team. While this could be achieved simply by declaring IP-domain mapping at host machine (/etc/hosts), is not a good solution for a large web development team. dnsmasq is a little gem in Linux perfectly fits in this situation.
dnsmasq a local DNS server with forwarding to upstream DNS
dnsmasq accepts DNS queries and either answers them from a small, local, cache or forwards them to a real, recursive, DNS server. dnsmasq is DHCP + local DNS with forwarding of all query types to upstream DNS + DNS caching + TFTP server. Being easy to configure it also has reputation for its light weight foot print. As a DHCP is already running in my envioronment, I only need its DNS capabilities. On a debian box install the server as root
apt-get install dnsmasq
Server’s static I.P. is 192.168.1.10
Configure IP-domain mapping and DNS forwarding to upstream DNS
Given, simpsoft.local, jenkins.simpsoft.local should point to server having static I.P. 192.168.1.10 ; dbadmin.simpsoft.local, gitweb.simpsoft.local should point to 192.168.1.11 and salescommission.simpsoft.local, insurancecompany.simpsoft.local must point 192.168.1.12
Hence as root we need to edit /etc/dnsmasq.conf with following
address=/simpsoft.local/192.168.1.10 address=/jenkins.simpsoft.local/192.168.1.10 address=/dbadmin.simpsoft.local/192.168.1.11 address=/gitweb.simpsoft.local/192.168.1.11 address=/salescommission.simpsoft.local/192.168.1.12 address=/insurancecompany.simpsoft.local/192.168.1.12
We need to use dnsmasq as primary nameserver to get the local domains. That’s why we also need to instruct dnsmasq to pass queries can’t be resolved locally to upstram DNS.
Given google DNS as upstream for this setup, we need to add following at /etc/dnsmasq.conf
#DNS forwarding to upstream google DNS server=184.108.40.206 server=220.127.116.11
Let’s activate our local DNS
service dnsmasq start
What to do at host/client system ?
Nothing if DHCP server uses dnsmasq as primary DNS. Otherwise Linux boxes should place the I.P. of dnsmasq as only / very first nameserver at /etc/resolv.conf
#IP of dnsmasq server as only/first nameserver nameserver 192.168.1.10
Window boxes also need the same, i.e. I.P. of dnsmasq must be the first DNS
Check the setup
Let’s use nslookup and dig to see how our local DNS resolving local domain and DNS forwarding. We have to execute these tests from a Linux box which is configured to use dnsmasq server as primary DNS