Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Special Files and Directories

The /etc/resolv.conf file

Reference for /etc/resolv.conf: nameserver, search, domain and options lines, who generates the file, systemd-resolved stub addresses and common pitfalls.

/etc/resolv.conf tells the C library's resolver which DNS servers to ask and how to complete short names. When a program looks up example.com, and /etc/hosts does not answer, the resolver sends the query to the servers listed here, in order.

On modern systems the file is usually generated, not hand-written: by systemd-resolved, NetworkManager, dhclient, resolvconf or a container runtime. A manual edit then lasts only until the generator runs again. Check what you have with ls -l /etc/resolv.conf before changing it.

Terminal
nameserver 192.0.2.53
search example.com corp.example.com
options timeout:2 attempts:3

Try it

Bash Reading the resolver configuration

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash Expanding a short name with the search list

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Keyword Description
nameserver ADDRESS An IPv4 or IPv6 address of a DNS server. Up to three are used, in order; the next is tried only after a timeout.
search DOMAIN ... Domains appended to short names, tried in order. Only the last search or domain line counts.
domain NAME The older form of search with one domain.
options ... Tuning: timeout:N seconds per try, attempts:N, ndots:N, rotate, edns0, single-request.
sortlist Prefers answers in given networks (rarely used).

Edge cases: a name with at least ndots dots (default 1) is tried as an absolute name first, then with the search domains; a name with fewer dots goes through the search list first. A trailing dot (example.com.) always means absolute. Lines longer than 255 characters are truncated.

Usage notes

  • 127.0.0.53 means systemd-resolved is running a local stub; the real servers are shown by resolvectl status. Do not replace it by hand, change the settings in the network manager.
  • 127.0.0.11 is Docker's embedded DNS in user-defined networks, as in this sandbox.
  • Edits that vanish: if the file is a symlink or has a "generated by" header, edit the source (netplan, NetworkManager connection, /etc/resolvconf/resolv.conf.d/head).
  • Too many search domains slow every lookup, because each short name tries them all. In Kubernetes, ndots:5 is a famous cause of extra DNS traffic.
  • Test with getent hosts NAME, which uses the real resolver path. dig ignores the search list unless you pass +search.
  • The first server being down adds a delay of timeout seconds to every query until it answers; put the fastest, most reliable server first.
  • Not a place for /etc/hosts-style entries. Names with fixed addresses go in /etc/hosts.