The /etc/resolv.conf file is a critical configuration file on Unix-like systems that determines how the system resolves domain names into IP addresses. It is used by the system’s resolver library and various applications (like web browsers, email clients, and command-line tools) to locate DNS (Domain Name System) servers.
-
nameserver:- Purpose: Specifies the IP address of a DNS server that the system should query.
- Usage: You can have multiple
nameserverlines; the resolver will try them in order. - Example:
nameserver 8.8.8.8 nameserver 8.8.4.4
-
domain:- Purpose: Specifies the local domain name. If a hostname is not fully qualified (i.e., it lacks a dot), the resolver appends this domain name.
- Example:
domain example.com
-
search:- Purpose: Lists multiple domains to be appended in order to a short, unqualified name during the lookup process.
- Usage: Only one of either
domainorsearchshould be used. - Example:
search example.com sub.example.com
-
options:- Purpose: Specifies various settings for the resolver. Common options include:
timeout:n: Specifies the number of seconds the resolver will wait for a response from a DNS server.attempts:n: Specifies the number of times the resolver will retry a query.rotate: Tells the resolver to rotate among thenameserverentries for load balancing.
- Example:
options timeout:2 attempts:3 rotate
- Purpose: Specifies various settings for the resolver. Common options include:
- Resolver Library: When an application needs to resolve a hostname, it reads the
/etc/resolv.conffile to determine which DNS servers to contact. - Query Process: The resolver library tries the listed
nameserverentries in the order they appear. If the first server doesn't respond within the specified timeout, it moves on to the next. - Domain and Search: If the queried hostname is not fully qualified, the resolver appends the domain or search list to form a fully qualified domain name (FQDN) before querying.
- Systemd-resolved: On some modern Linux distributions,
/etc/resolv.confmay be managed dynamically by services likesystemd-resolvedorNetworkManager. In these cases, the file might be a symbolic link (e.g., to/run/systemd/resolve/stub-resolv.conf) and get updated automatically based on network conditions. - Manual vs. Automatic: If you're managing DNS settings manually, ensure that no other service is overwriting your changes. You may need to disable the dynamic management or configure it properly.
# /etc/resolv.conf - DNS configuration file
# The primary DNS server
nameserver 8.8.8.8
# The secondary DNS server
nameserver 8.8.4.4
# Domain search list
search example.com sub.example.com
# Resolver options: wait 2 seconds, try 3 attempts, and rotate through nameservers
options timeout:2 attempts:3 rotate
- Stale or Incorrect Settings: If name resolution isn’t working, verify that the DNS servers listed are correct and reachable.
- Dynamic Updates: Check if your system’s network manager or
systemd-resolvedis managing/etc/resolv.conf. If so, you may need to adjust settings within those services. - Permissions and Symlinks: Ensure that
/etc/resolv.confis accessible by applications and that any symlink points to a valid file.
The /etc/resolv.conf file is essential for proper network communication on Unix-like systems, guiding how domain names are translated into IP addresses. Understanding its structure and directives—such as nameserver, domain, search, and options—helps you configure DNS settings effectively, troubleshoot issues, and ensure that your system can locate the services it needs on the network.