resolv.conf

From Gentoo Wiki
Jump to: navigation, search

Resources

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 tools. It is commonly used to manage DNS requests.

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.

nameserver

The nameserver option takes the IP address that the resolver should query, either in IPv4 or IPv6 form. Multiple lines may be specified, but each line must have only one IP address. A maximum of three 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 127.0.0.1.

search

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 example.com, and you requested http://test/index.html, it would first query http://test.example.com/index.html, and then http://test/index.html.

domain

The domain option specifies the local domain name. It is essentially an entry into the search list for devices on the local domain.

The domain and search keywords are mutually exclusive, and if both are present, the one that appears last takes preference. For more syntax options, check resolv.conf(5) in the manpages.

Network configuration tools

NetworkManager

When using NetworkManager, /etc/resolv.conf should be a symlink pointing at /run/NetworkManager/resolv.conf.

DHCPCD

By default, dhcpcd overwrites /etc/resolv.conf with the suggested configuration of the connected network. This behaviour can be completely disbled 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.

systemd-resolved

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

Two main features are supported:

  • Stub resolver: the nameserver is pointed at systemd-resolved, listening on 127.0.0.53. 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 options/features depend on the version of systemd installed and which target is used for the symlink.

Symlink target Stub resolver Search path < systemd-234 systemd-234/235 >= systemd-236
/run/systemd/resolve/stub-resolv.conf Yes Yes No No Yes
/run/systemd/resolve/resolv.conf No Yes Yes Yes Yes
/lib/systemd/resolv.conf Yes No No Yes Yes
/usr/lib/systemd/resolv.conf Yes No Yes No No

openresolv

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.

External resource