Skip to content

Latest commit

 

History

History
81 lines (59 loc) · 3.97 KB

File metadata and controls

81 lines (59 loc) · 3.97 KB

/etc/resolv.conf

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.

Key Components and Directives

  1. nameserver:

    • Purpose: Specifies the IP address of a DNS server that the system should query.
    • Usage: You can have multiple nameserver lines; the resolver will try them in order.
    • Example:
      nameserver 8.8.8.8
      nameserver 8.8.4.4
      
  2. 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
      
  3. search:

    • Purpose: Lists multiple domains to be appended in order to a short, unqualified name during the lookup process.
    • Usage: Only one of either domain or search should be used.
    • Example:
      search example.com sub.example.com
      
  4. 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 the nameserver entries for load balancing.
    • Example:
      options timeout:2 attempts:3 rotate
      

How It Works

  • Resolver Library: When an application needs to resolve a hostname, it reads the /etc/resolv.conf file to determine which DNS servers to contact.
  • Query Process: The resolver library tries the listed nameserver entries 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.

Dynamic Management

  • Systemd-resolved: On some modern Linux distributions, /etc/resolv.conf may be managed dynamically by services like systemd-resolved or NetworkManager. 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.

Example /etc/resolv.conf

# /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

Troubleshooting Tips

  • 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-resolved is managing /etc/resolv.conf. If so, you may need to adjust settings within those services.
  • Permissions and Symlinks: Ensure that /etc/resolv.conf is accessible by applications and that any symlink points to a valid file.

Conclusion

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.