Installing Dnsmasq for wildcard local domains on Debian
Posted on August 14, 2018
Install
sudo apt-get install dnsmasq
Configure
sudo vim /etc/dnsmasq.conf
Add this:
address=/example.com/127.0.0.1 listen-address=127.0.0.1
This maps *.example.com
to 127.0.0.1
– replace with the domain you want to use. It also makes dnsmasq only respond to local requests for security – this is optional.
Restart to load the new configuration:
sudo /etc/init.d/dnsmasq restart
Test it:
nslookup abc.example.com 127.0.0.1
It should say something like:
Server: 127.0.0.1 Address: 127.0.0.1#53 Name: abc.example.com Address: 127.0.0.1
Override the nameserver to use for lookups
sudo vim /etc/dhcp/dhclient.conf
Add:
prepend domain-name-servers 127.0.0.1;
Restart the network:
sudo ifdown eth0; sudo ifup eth0
Adjust as necessary if your interface is not named eth0
. Run ifconfig
to get the interface name if you’re not sure.
Check that it worked:
cat /etc/resolv.conf
It should say something like:
domain home search home nameserver 127.0.0.1 nameserver 192.168.32.254
Note that 127.0.0.1
is the first nameserver.
Test:
nslookup abc.example.com