I'm connected to local area network with access to the Internet through gateway. There is DNS server in local network which is capable of resolving hostnames of computers from local network.

I would like to configure systemd-resolved and systemd-networkd so that lookup requests for local hostnames would be directed (routed) exclusively to local DNS server and lookup requests for all other hostnames would be directed exclusively to another, remote DNS server.

Let's assume I don't know where the configuration files are or whether I should add more files and require their path(s) to be specified in the answer.


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 DHCP= option:


or specify its address explicitly using DNS= option:


In addition we need to specify (in the same section) local domains using Domains= option

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.

This way 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 specified domains.

This way 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 /etc/systemd/resolved.conf file:

DNS= 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.

See also:


  • 4
    Have you considered not using .local in this example? Certainly with avahi, this was supposed to be reserved for MDNS and misusing it was a big no-no. It would be clearer to me to use example.com or .example. – sourcejedi May 8 '18 at 17:17
  • @sourcejedi For reference .local is defined as special domain in RFC 6762 – Multicast DNS in section Multicast DNS Names. Thanks, fixed. – Piotr Dobrogost May 9 '18 at 7:48
  • Unrelated note: you can self-accept answers too. – intelfx May 9 '18 at 13:41
  • @intelfx Not so fast – You can accept your own answer tomorrow :) – Piotr Dobrogost May 9 '18 at 13:47
  • 1
    I think it would be useful to add the location of the configuration file for local network interface. Not sure to be right is it /etc/systemd/network/*.network ? Found here superuser.com/a/1365864 – Pierre Cordier Oct 22 '18 at 15:47

Just to expand on @piotrDobrogost 's excellent answer, don't forget to config /etc/nsswitch.conf to use systemd-resolved as a DNS resolution source. Your hosts directive should look as follows for your particular use case:


hosts:  files resolve dns

So if you limit the resolution to only those domains specified in the Domains directive in /etc/systemd/resolved.conf as Piotr details above, DNS should next be consulted in the order of name resolution sources specified /etc/nsswitch.conf when domains are NOT found in Domains directive:

The following link references the requirement to specify resolve in /etc/nsswitch.conf so systemd-resolved is consulted during name resolution:


SystemD documentation I've found to be dire. I had to piece together an understanding from multiple links, including Piotr's answer above ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.