Ubuntu 18.04 .local domain dns lookup not working

The accepted answer did not resolve my issue. It was nothing to do with avahi - I did not have avahi service installed. I have my system set to get its IP AND its DNS server settings from DHCP. However, the DHCP supplied DNS was not being checked for queries using .local

The real issue is that Ubuntu 18.04 has its resolv.conf sym-linked to a stub file that points to the localhost for name resolution. Localhost DNS name resolution means that the system refuses to check the supplied DNS server for .local names, believing (incorrectly) that such names are invalid. This is the default setup of /etc/resolv.conf:

ls -la /etc/resolv.conf
lrwxrwxrwx 1 root root 39 Jan 22 13:26 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf

content of the stub file is (comments removed):

 cat /run/systemd/resolve/stub-resolv.conf
 .. removed comments..  
nameserver 127.0.0.53
    search reddog.microsoft.com

the 'real' resolve conf has the 'correct' DNS setting (from DHCP):

cat /run/systemd/resolve/resolv.conf

..removed comments..
nameserver 10.168.200.250 # This is my server that can resolve .local
nameserver 208.67.220.220 # these are optional, fallback DNS servers
nameserver 208.67.222.222
# Too many DNS servers configured, the following entries may be ignored.
nameserver 8.8.8.8
search reddog.microsoft.com

In order to make the system use your preferred DNS resolver instead of localhost, you change the symlink to point to /run/systemd/resolve/resolv.conf instead of /run/systemd/resolve/stub-resolv.conf :

sudo rm -f /etc/resolv.conf
sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf

Immediately after this, resolution of .local started working. No need to reboot or restart any service.


I faced a very similar issue (if not exactly the same) on Linux Mint 19 (Tara). I've managed to solve it by combining 3 different pieces of information. It seems to all be related to recent changes with systemd-resolved.

First, yes I've needed to configure /etc/nsswitch.conf as you did and would expect. As long as dns comes before mdns you should be good. I ended with simply:

hosts:          files dns myhostname

ref: https://unix.stackexchange.com/a/457172/271210

Prior to upgrading to this version of Mint, this is the only thing I needed to do. Now I also ended up making the below two other changes to get it working...


After that I've configured my search domain so systemd-resolved would work as I wanted. So I've edited the file /etc/systemd/resolved.conf, the Domains setting under the [resolve] section. In my case it ended up looking like:

[Resolve]
#DNS=
#FallbackDNS=
Domains=trilliant.local
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#Cache=yes
#DNSStubListener=yes

ref: https://askubuntu.com/a/1031271/872881

I've also changed the avahi configuration to something else ("mdns" if I remember correctly, but it doesn't matter). It shouldn't be required however from my understanding. Just adding for completeness.


But none of it worked until I've called the following:

sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf

ref: https://askubuntu.com/a/938703/872881

After calling this, everything started working perfectly and as expected!

So it's possible I didn't really need to change the /etc/systemd/resolved.conf file but I kept this change since it made sense and allows me to only type a machine's name, without the complete FQDN, for DNS resolution to work.


For me working way for Ubuntu 18.04 is:

Edit avahi conf:

sudo vim /etc/avahi/avahi-daemon.conf

and change .local to .alocal :

[server]
domain-name=.alocal

then, open resolved.conf:

sudo vim /etc/systemd/resolved.conf

and uncomment and edit Domains:

[Resolve]
...
Domains=yourdomain.local
...

and finally restart services:

sudo service systemd-resolved restart
sudo service avahi-daemon restart