In the configuration file for local network interface we have to either specify we want to obtain local DNS server address from DHCP server using
or specify its address explicitly using
In addition we need to specify (in the same section) local domains using
Domains=domainA.example domainB.example ~example
We specify local domains
domainA.example domainB.example to get the following behavior (from systemd-resolved.service, systemd-resolved man page):
Lookups for a hostname ending in one of the per-interface domains are
exclusively routed to the matching interfaces.
hostX.domainA.example will be resolved exclusively by our local DNS server.
We specify with
~example that all domains ending in
example are to be treated as route-only domains to get the following behavior (from description of this commit) :
DNS servers which have route-only domains should only be used for the
hostY.on.the.internet will be resolved exclusively by our global, remote DNS server.
Ideally, when using DHCP protocol, local domain names should be obtained from DHCP server instead of being specified explicitly in configuration file of network interface above. See
UseDomains= option. However there are still outstanding issues with this feature – see systemd-networkd DHCP search domains option issue.
We need to specify remote DNS server as our global, system-wide DNS server. We can do this in
DNS=184.108.40.206 220.127.116.11 2001:4860:4860::8888 2001:4860:4860::8844
Don't forget to reload configuration and to restart services:
$ sudo systemctl daemon-reload
$ sudo systemctl restart systemd-networkd
$ sudo systemctl restart systemd-resolved
Above guarantees apply only when names are being resolved by systemd-resolved – see man page for nss-resolve, libnss_resolve.so.2 and man page for systemd-resolved.service, systemd-resolved.