The resolv.conf file’s search directive is being truncated because it exceeds the system’s limit, causing DNS lookups for certain hostnames to fail.

Common Causes and Fixes

  1. Excessive Search Domains:

    • Diagnosis: Check the length of your search directive in /etc/resolv.conf.
      cat /etc/resolv.conf | grep search
      
      If the output line is very long, it’s likely the culprit.
    • Fix: Reduce the number of domains in the search list. The maximum length for the search directive is 256 characters, including dots and spaces. For example, if you have search domain1.com domain2.com domain3.com domain4.com domain5.com domain6.com domain7.com domain8.com domain9.com domain10.com, you might need to trim it to something like search domain1.com domain2.com domain3.com domain4.com domain5.com.
    • Why it works: The system’s DNS resolver library has a hardcoded limit for the search directive to prevent buffer overflows. Shortening the list brings it within this limit.
  2. NetworkManager Overwriting resolv.conf:

    • Diagnosis: If you’re using NetworkManager, it might be regenerating /etc/resolv.conf with an overly long search list. Check the NetworkManager configuration.
      nmcli connection show --active
      
      Look for the connection profile associated with your active network interface. Then, inspect its DNS settings.
    • Fix: Configure NetworkManager to use a shorter search list or to ignore DNS settings from DHCP. Edit the connection profile:
      nmcli connection edit <connection_name>
      
      Navigate to ipv4.dns-search and set it to an empty list or a shorter list. Alternatively, set ipv4.dns to no and manually manage /etc/resolv.conf or use a different DNS management tool.
    • Why it works: NetworkManager, by default, populates resolv.conf based on DHCP lease information or static configuration. By explicitly setting a shorter search list or disabling its DNS management for that connection, you prevent it from writing the overly long entry.
  3. DHCP Client Overwriting resolv.conf:

    • Diagnosis: If your system obtains its IP address and DNS settings via DHCP, the DHCP client (like dhclient or dhcpcd) might be receiving a long list of search domains from the DHCP server and writing them to /etc/resolv.conf.
      grep 'supersede domain-name-servers' /etc/dhcp/dhclient.conf # For dhclient
      
      Check your DHCP client configuration files for directives that control DNS updates.
    • Fix: Configure your DHCP client to ignore the domain-name-servers or domain-search options from the DHCP server, or to only accept specific domains. For dhclient, you can add prepend domain-name-servers 8.8.8.8; and supersede domain-search ""; to /etc/dhclient.conf or /etc/dhcp/dhclient.conf.
    • Why it works: This tells the DHCP client to either ignore the search domain list provided by the server entirely or to prepend specific DNS servers, effectively preventing the long list from being written to resolv.conf.
  4. Systemd-resolved Interference:

    • Diagnosis: Modern systems often use systemd-resolved for DNS resolution. It manages /etc/resolv.conf as a symlink, often pointing to /run/systemd/resolve/stub-resolv.conf or /run/systemd/resolve/resolv.conf. Check which file /etc/resolv.conf points to.
      ls -l /etc/resolv.conf
      cat /etc/resolv.conf
      
      If systemd-resolved is active, its configuration can lead to this issue if it receives a long search list from the network configuration.
    • Fix: Configure systemd-resolved to use a shorter search list or to ignore DHCP-provided search domains. Edit /etc/systemd/resolved.conf and set Domains=~., which tells resolved to use the domain given by DHCP (if any) as the only search domain, or to set DNSStubListener to yes and manage DNS via resolvectl. To enforce a short search list, you might set Domains=domain1.com domain2.com.
    • Why it works: systemd-resolved processes DNS information from various sources. By configuring its Domains setting, you explicitly control what search domains it uses or how it interprets them, overriding potentially long lists from DHCP.
  5. Manual resolv.conf Edits with Incorrect Syntax:

    • Diagnosis: If /etc/resolv.conf is not managed by NetworkManager or systemd-resolved and is edited manually, a syntax error could be the cause.
      cat -n /etc/resolv.conf
      
      Look for lines exceeding 256 characters or incorrect spacing.
    • Fix: Ensure each domain in the search directive is separated by a single space and that the total line length does not exceed 256 characters. For example:
      search short.domain.com another.short.domain.com
      
    • Why it works: Strict adherence to the DNS resolver library’s parsing rules, including the character limit and spacing, is necessary for the search directive to be processed correctly.
  6. Multiple DNS Configuration Sources:

    • Diagnosis: On complex systems, it’s possible that multiple services are attempting to manage /etc/resolv.conf, leading to conflicting or overly long configurations. For instance, if NetworkManager is active but you also have static entries in /etc/resolv.conf that are then overwritten by DHCP.
    • Fix: Consolidate your DNS management. Choose one primary method: NetworkManager, systemd-resolved, or manual configuration (if on a static system without NetworkManager). Disable or reconfigure other services to prevent them from interfering. For example, if using NetworkManager, ensure dns=none is set in /etc/NetworkManager/NetworkManager.conf if you want to manage resolv.conf manually.
    • Why it works: Having a single, authoritative source for DNS configuration prevents race conditions and ensures that the resolv.conf file is populated correctly and consistently.

The next error you’ll likely encounter if this is not fixed is a "Name or service not known" or similar DNS resolution failure for hostnames that rely on the truncated search list.

Want structured learning?

Take the full Dns course →