From Gentoo Wiki
(Redirected from DNS)
Jump to:navigation Jump to:search


The /etc/resolv.conf file is used to configure hostname resolution. It may be manually configured by the system administrator, or may be automatically populated by various network configuration and management tools. It is commonly used to manage DNS requests on Linux systems.

Available software

Many tools exist to help manage the /etc/resolv.conf file (or symlink).


By default, dhcpcd overwrites /etc/resolv.conf with the suggested configuration of the connected network. This behavior can be completely disabled by modifying /etc/dhcpcd.conf:

FILE /etc/dhcpcd.conf
nohook resolv.conf

Alternatively, one may edit /etc/resolv.conf.head or /etc/resolv.conf.tail, which will be appended to the start or end of /etc/resolv.conf, respectively.



When using NetworkManager on an OpenRC profile, /etc/resolv.conf should be a symlink pointing at /run/NetworkManager/resolv.conf. This will likely not result in an automatically managed /etc/resolv.conf file for the system, unless the resolvconf USE flag has been enabled for net-misc/networkmanager.

For information on using different DNS plugins with NetworkManager see the dns and rc-manager parts under MAIN SECTION of man 5 NetworkManager.conf.


When using a systemd profile, systemd-resolved is a natural choice to be used as a DNS resolver for NetworkManager. It is enabled by starting the service and creating a symlink (see below).

If migrating from a different profile, the /etc/resolv.conf file should be removed, then a symlink created to the systemd resolver:

root #rm /etc/resolv.conf
root #systemctl enable --now systemd-resolved
root #ln -s /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
root #systemctl restart NetworkManager
root #ls -l /etc/resolv.conf
lrwxrwxrwx 1 root root 32 Jan 12 14:09 /etc/resolv.conf -> /run/systemd/resolve/stub-resolv.conf


The net-dns/openresolv package integrates with several other packages to dynamically update /etc/resolv.conf when network configuration changes occur. When using openresolv, /etc/resolv.conf should be a regular file.


There are multiple options for setting up a resolv.conf symlink to work with systemd-resolved.

Two main features are supported:

  • Stub resolver (Recommended): the nameserver is pointed at systemd-resolved, listening on DNS queries are executed by systemd-resolved.
  • Search path: The "search" directive is used to configure default domain names to be used when resolving single-word DNS queries.

The available features depend on which target is used for the symlink.

Symlink target Stub resolver Search path
/run/systemd/resolve/stub-resolv.conf Yes Yes
/run/systemd/resolve/resolv.conf No Yes
/lib/systemd/resolv.conf Yes No


When using Netifrc to configure static addresses it is also possible to specific dns configuration like so

FILE /etc/conf.d/net

where the IP address and domain are just examples, and eth0 refers to the associated interface

Netifrc will then create a /etc/resolv.conf from these settings


resolv.conf file syntax

The syntax of /etc/resolv.conf is relatively straight-forward. Each line specifies an option: most commonly nameserver, search, or domain. Not every line is necessary; it is entirely possible to have a blank file, while maintaining a working system.


The nameserver option takes the IP address that the resolver should query, either in IPv4 or IPv6 form. Multiple nameserver lines may be specified, but each line must have only one IP address. A maximum of three lines should be present in total. If more than one IP address is present, the resolver queries them in the order listed. If no nameserver entries are present, it will default to


The search option accepts up to six domains, separated by tabs or spaces. This is used if the resolver receives a request without any dots in it. It will then try to resolve the query with the search domain appended, then the original request. For example, if the search domain was, and http://test/index.html was requested, it would first query, and then http://test/index.html.


The domain directive is an obsolete name for the search directive that handles one search list entry only. For more syntax options, check man 5 resolv.conf.


Control of /etc/resolv.conf

To determine which network management utility is controlling the /etc/resolv.conf file, two methods exist:


Typically, the network management utility will write a comment at the top of the file specifying the name of the managing program. This can be checked using head:

user $head -n 1 /etc/resolv.conf
# Generated by resolvconf

symlink target

/etc/resolv.conf will either be a regular file or a symlink to another file. When a symlink, it is easy to reveal what network management tool is controlling the file by looking at the printed path to the target:

user $ls -l /etc/resolv.conf
lrwxrwxrwx 1 root root 32 Jan 12 14:09 /etc/resolv.conf -> /run/systemd/resolve/resolv.conf

External resources