What you want is Dnsmasq. Netplan only allows to configure fallback DNS, not a domain DNS.
Prepare installation
- Remove "systemd-resolved"
sudo systemctl disable systemd-resolved
sudo systemctl stop systemd-resolved
- Remove linked resolv.conf
- Make sure it is a link (will point to something like: ...systemd/resolve/stub-resolv.conf):
sudo ls -lh /etc/resolv.conf
- Remove link:
sudo rm /etc/resolv.conf
- Add temporary DNS
sudo echo "nameserver 8.8.8.8" > /etc/resolv.conf
- Install Dnsmasq
sudo apt update
sudo apt install dnsmasq
Problem with dnsmasq.d/lxd
You might get this error when dnsmasq
starts initially:
dnsmasq: cannot access /etc/dnsmasq.d/lxd: No such file or directory
To resolve this just remove symlink ¯\(ツ)/¯
sudo rm /etc/dnsmasq.d/lxd
And restart:
service dnsmasq restart
service dnsmasq status
Configure DNSmasq
Edit /etc/dnsmasq.conf
.
Search and uncomment this options:
- domain-needed
- bogus-priv
- strict-order
- no-resolv
Add your domain DNS servers e.g.:
server=/mycompany.com.pl/192.168.0.123
server=/some.vlan/10.234.0.123
Add generic servers e.g.:
server=1.1.1.1
server=8.8.4.4
Restart when done:
service dnsmasq restart
service dnsmasq status
Note that status will show which DNS servers are actually used (using nameserver ...
).
Final steps
- Set DNS to local:
- Add local DNS in resolve:
sudo echo "nameserver 127.0.0.1" > /etc/resolv.conf
- Update
/etc/netplan/
yaml file too.
- Test with
dig
(or ping
).
- (look for
;; ANSWER SECTION:
)
dig app01.some.vlan
dig server.mycompany.com.pl
- Enable running on boot: