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
-
Excessive Search Domains:
- Diagnosis: Check the length of your
searchdirective in/etc/resolv.conf.
If the output line is very long, it’s likely the culprit.cat /etc/resolv.conf | grep search - Fix: Reduce the number of domains in the
searchlist. The maximum length for thesearchdirective is 256 characters, including dots and spaces. For example, if you havesearch 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 likesearch 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
searchdirective to prevent buffer overflows. Shortening the list brings it within this limit.
- Diagnosis: Check the length of your
-
NetworkManager Overwriting
resolv.conf:- Diagnosis: If you’re using NetworkManager, it might be regenerating
/etc/resolv.confwith an overly long search list. Check the NetworkManager configuration.
Look for the connection profile associated with your active network interface. Then, inspect its DNS settings.nmcli connection show --active - Fix: Configure NetworkManager to use a shorter search list or to ignore DNS settings from DHCP. Edit the connection profile:
Navigate tonmcli connection edit <connection_name>ipv4.dns-searchand set it to an empty list or a shorter list. Alternatively, setipv4.dnstonoand manually manage/etc/resolv.confor use a different DNS management tool. - Why it works: NetworkManager, by default, populates
resolv.confbased 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.
- Diagnosis: If you’re using NetworkManager, it might be regenerating
-
DHCP Client Overwriting
resolv.conf:- Diagnosis: If your system obtains its IP address and DNS settings via DHCP, the DHCP client (like
dhclientordhcpcd) might be receiving a long list of search domains from the DHCP server and writing them to/etc/resolv.conf.
Check your DHCP client configuration files for directives that control DNS updates.grep 'supersede domain-name-servers' /etc/dhcp/dhclient.conf # For dhclient - Fix: Configure your DHCP client to ignore the
domain-name-serversordomain-searchoptions from the DHCP server, or to only accept specific domains. Fordhclient, you can addprepend domain-name-servers 8.8.8.8;andsupersede domain-search "";to/etc/dhclient.confor/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.
- Diagnosis: If your system obtains its IP address and DNS settings via DHCP, the DHCP client (like
-
Systemd-resolved Interference:
- Diagnosis: Modern systems often use
systemd-resolvedfor DNS resolution. It manages/etc/resolv.confas a symlink, often pointing to/run/systemd/resolve/stub-resolv.confor/run/systemd/resolve/resolv.conf. Check which file/etc/resolv.confpoints to.
Ifls -l /etc/resolv.conf cat /etc/resolv.confsystemd-resolvedis active, its configuration can lead to this issue if it receives a long search list from the network configuration. - Fix: Configure
systemd-resolvedto use a shorter search list or to ignore DHCP-provided search domains. Edit/etc/systemd/resolved.confand setDomains=~., which tellsresolvedto use the domain given by DHCP (if any) as the only search domain, or to setDNSStubListenertoyesand manage DNS viaresolvectl. To enforce a short search list, you might setDomains=domain1.com domain2.com. - Why it works:
systemd-resolvedprocesses DNS information from various sources. By configuring itsDomainssetting, you explicitly control what search domains it uses or how it interprets them, overriding potentially long lists from DHCP.
- Diagnosis: Modern systems often use
-
Manual
resolv.confEdits with Incorrect Syntax:- Diagnosis: If
/etc/resolv.confis not managed by NetworkManager or systemd-resolved and is edited manually, a syntax error could be the cause.
Look for lines exceeding 256 characters or incorrect spacing.cat -n /etc/resolv.conf - Fix: Ensure each domain in the
searchdirective 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
searchdirective to be processed correctly.
- Diagnosis: If
-
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.confthat 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=noneis set in/etc/NetworkManager/NetworkManager.confif you want to manageresolv.confmanually. - Why it works: Having a single, authoritative source for DNS configuration prevents race conditions and ensures that the
resolv.conffile is populated correctly and consistently.
- Diagnosis: On complex systems, it’s possible that multiple services are attempting to manage
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.