On Ubuntu 14.04 I'm using dnsmasq to resolve wildcard example.com domains to the local machine (desktop computer at home).
After much reading around I cannot for the life of me sort out the same on a clean install of 18.04.
All I want to achieve at the moment is:
- for
ping example.com
to ping 127.0.0.1 and not 93.184.216.34; - for
ping anysubdomain.example.com
to also ping 127.0.0.1; - and for
ping google.com
to ping the real google.com via the router/IP DNS.
Surely this must be simple, even trivial?
But I'm stumped. I can get the example.com's resolving but only at the expense of breaking everything else.
How can I do this?
Here are the steps for ubuntu since 18.04. It's a little bit long since
systemd-resolved
does not play very well withNetworkManager
when configured withdnsmasq
.Yet I still recommend starting
dnsmasq
fromNetworkManager
, because network connectivity changes (WIFI, wired, ...) will be handled transparently.Enable dnsmasq in NetworkManager
Edit the file
/etc/NetworkManager/NetworkManager.conf
, and add the linedns=dnsmasq
to the[main]
section, it will look like this :Let NetworkManager manage
/etc/resolv.conf
Configure
example.com
Reload
NetworkManager
and testingNetworkManager should be reloaded for the changes to take effect.
Then we can verify that we can reach some usual site :
And lastly verify that the
example.com
and subdomains are resolved as127.0.0.1
:First make sure in
/etc/NetworkManager/NetworkManager.conf
the following line is not present or commented out:Restart NetworkManager:
Make sure the NetworkManager-controlled dnsmasq is not running anymore, either by killing the process or rebooting your system.
Then install dnsmasq:
Add the following to
/etc/dnsmasq.d/example.com
:Restart dnsmasq:
Now you should have a wildcard dns override for example.com.
This won't be as simple as editing the hosts file. You have a couple of options:
This python DNS proxy that will handle wildcards in /etc/hosts
Using DNSmasq
Based on pim's answer, I have created a gist containing a simple Bash script which uses DNSMasq in combination with NetworkManager to setup the .test domain pointing to 127.0.0.1
See the gist at https://gist.github.com/archan937/d35deef3b1f2b5522dd4b8f397038d27.
You can execute the script with the following command:
Cheers!