This article offers a 5 min howto about configuring your own DNS server (perhaps for your company or maybe for your home network) using DNSmasq. Obviously, only the surface is covered on this post.
Given my router does not allow me to add host entries for local DNS resolution, I decided to use DNSMasq on one of my internal network servers to be able to do it. Once configured, I would make all internal devices use this “personal” DNS server instead of the router one.
For Debian based distributions, it can be installed via apt package manager:
sudo apt install dnsmasq
service dnsmasq start
service dnsmasq stop
Enable automatic start
systemctl enable dnsmasq
The goal is to make DNS cache act as DNS proxy for non-internal DNS names. To do it so, we must set the DNS server we want DNSmasq to ask to in order to resolve those external names. It can be either, your ISPs, a public one like googles or, like in my case, my routers.
This is done in /etc/resolv.conf. For example, to set google’s DNS server:
Or to set more than one (my router’s and google’s):
nameserver 192.168.100.1 nameserver 18.104.22.168
Each time you want a new internal DNS name to be resolved, all you have to do is add a new line on /etc/hosts
192.168.100.117 testhost.mydomain.com testhost
and reload the service
sudo service dnsmasq reload
Test it and confirm both the internal and external names are being resolved
$ nslookup > server 192.168.100.22 Default server: 192.168.100.22 Address: 192.168.100.22#53 > testhost Server: 192.168.100.22 Address: 192.168.100.22#53 Name: testhost Address: 192.168.100.117 > google.com Server: 192.168.100.22 Address: 192.168.100.22#53 Non-authoritative answer: Name: google.com Addresses: 2a00:1450:4003:80b::200e 22.214.171.124
Configure your devices
Now you have a working new DNS server, just configure your internal network devices to use it.