Domain name resolution

From ArchWiki
(Redirected from Resolv.conf)
Jump to: navigation, search

This article explains how to configure domain name resolution and resolve domain names.

Name Service Switch

"NSS" redirects here. For Mozilla cryptographic libraries, see Network Security Services.

The Name Service Switch (NSS) facility is part of the GNU C Library (glibc) and backs the getaddrinfo(3) API, used to resolve domain names. NSS allows system databases to be provided by separate services, whose search order can be configured by the administrator in nsswitch.conf(5). The database responsible for domain name resolution is the hosts database, for which glibc offers the following services:

Systemd provides three NSS services for hostname resolution:

Check if you can resolve domain names

NSS databases can be queried with getent(1). You can resolve a domain name through NSS using:

$ getent hosts domain_name
Note: While most programs resolve domain names using NSS, some may read resolv.conf and/or /etc/hosts directly. See Network configuration#Local hostname resolution.

Glibc resolver

The glibc DNS resolver reads /etc/resolv.conf (resolv.conf(5)) for every resolution to determine the nameservers and options to use.

Nameservers listed first are tried first, up to three nameservers may be listed. Lines starting with a number sign are ignored.

Note: The glibc resolver does not cache queries. See #Performance for more information.

Overwriting of resolv.conf

Network managers tend to overwrite resolv.conf, for specifics see the corresponding section:

To prevent programs from overwriting resolv.conf you can also write-protect it by setting the immutable file attribute.

Tip: If you want multiple processes to write to resolv.conf, you can use openresolv.

Limit lookup time

If you are confronted with a very long hostname lookup (may it be in pacman or while browsing), it often helps to define a small timeout after which an alternative nameserver is used. To do so, put the following in /etc/resolv.conf.

options timeout:1

Hostname lookup delayed with IPv6

If you experience a 5 second delay when resolving hostnames it might be due to a DNS-server/Firewall misbehaving and only giving one reply to a parallel A and AAAA request (source). You can fix that by setting the following option in /etc/resolv.conf:

options single-request

Local domain names

If you want to be able to use the hostname of local machine names without the fully qualified domain names, then add a line to resolv.conf with the local domain such as:


That way you can refer to local hosts such as as simply mainmachine1 when using the ssh command, but the drill command still requires the fully qualified domain names in order to perform lookups.


systemd-resolved(8) is a systemd service that provides network name resolution to local applications via a D-Bus interface, the resolve NSS service (nss-resolve(8)), and a local DNS stub listener on

systemd-resolved has four different modes for handling the glibc resolver's resolv.conf (described in systemd-resolved(8)). We will focus here on the two most relevant modes.

  1. The mode in which systemd-resolved is a client of the /etc/resolv.conf. This mode preserves /etc/resolv.conf and is compatible with the procedures described in this page.
  2. The systemd-resolved's recommended mode of operation: the DNS stub file as indicated below contains both the local stub as the only DNS servers and a list of search domains.
search lan

The service users are advised to redirect the /etc/resolv.conf file to the local stub DNS resolver file /run/systemd/resolve/stub-resolv.conf managed by systemd-resolved. This propagates the systemd managed configuration to all the clients. This can be done by deleting or renaming the existing /etc/resolv.conf and replacing it by a symbolic link to the systemd stub:

# ln -s /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf

In this mode, the DNS servers are provided in the resolved.conf(5) file:


In order to check the DNS actually used by systemd-resolved, the command to use is:

$ systemd-resolve --status
  • To understand the context around the DNS choices and switches, one can turn on detailed debug information for systemd-resolved as described in Systemd#Diagnosing a service.
  • The mode of operation of systemd-resolved is detected automatically, depending on whether /etc/resolv.conf is a symlink to the local stub DNS resolver file or contains server names.


The #Glibc resolver does not cache queries. If you want local caching use #Systemd-resolved or set up a local caching DNS server and use

Tip: The dig and drill #Lookup utilities report the query time.

Internet service providers usually provide working DNS servers. A router may also add an extra DNS server in case it has its own cache server. Switching between DNS servers is transparent for Windows users, because if a DNS server is slow or does not work it will immediately switch to a better one. However, Linux usually takes longer to timeout, which could cause delays.

Lookup utilities

To query specific DNS servers and DNS/DNSSEC records you can use dedicated DNS lookup utilities. These tools implement DNS themselves and do not use NSS.

For example, to query a specific nameserver with drill for the TXT records of a domain:

$ drill @nameserver TXT domain

If you do not specify a DNS server dig and drill use the nameservers defined in /etc/resolv.conf.

See also