XX-net/XX-Net · warning

load /etc/resolv.conf fail:%r

Error message

load /etc/resolv.conf fail:%r

What it means

This warning is emitted when get_local_dns_server() fails while parsing /etc/resolv.conf to discover the system's local DNS servers. The resolver file is missing, unreadable, or contains entries the parser cannot handle, so the code falls back to hardcoded or configured DNS servers. It is non-fatal: DNS resolution continues using the fallback list.

Source

Thrown at code/default/smart_router/local/dns_query.py:179

            iplist = []
            for i in range(4, ipcount * 4 + 4, 4):
                ip = socket.inet_ntoa(buf[i:i + 4])
                iplist.append(ip)

        elif os.path.isfile('/etc/resolv.conf'):
            try:
                with open('/etc/resolv.conf', 'rb') as fp:
                    iplist = re.findall(br'(?m)^nameserver\s+(\S+)', fp.read())

                xlog.debug("DNS resolve servers:%s", iplist)

                local_ips = g.local_ips
                for ip in local_ips:
                    if ip in iplist:
                        xlog.warn("remove local DNS server %s from upstream", ip)
                        iplist.remove(ip)
            except Exception as e:
                xlog.warn("load /etc/resolv.conf fail:%r", e)

        if not iplist:
            if g.config.country_code == "CN":
                iplist = [
                    b"114.114.114.114",
                    b"114.114.115.115",
                    b"119.29.29.29",
                    b"182.254.118.118",
                    b"223.5.5.5",
                    b"223.6.6.6",
                    b"180.76.76.76"
                ]
            else:
                iplist = [
                    b"1.1.1.1",
                    b"8.8.8.8",
                    b"9.9.9.9",
                    b"208.67.222.222",

View on GitHub (pinned to cfa5bc17b6)

Solutions

  1. Verify /etc/resolv.conf exists and contains a valid 'nameserver x.x.x.x' line
  2. If running in a container, configure DNS (docker --dns 8.8.8.8 or dns: in compose)
  3. Explicitly set the module's DNS server config so fallback IPs are used and the warning is irrelevant
  4. Ensure the process has read permission on /etc/resolv.conf

Example fix

# before: no resolv.conf in container
# after (Dockerfile)
RUN echo 'nameserver 8.8.8.8' > /etc/resolv.conf
Defensive patterns

Strategy: fallback

Validate before calling

import os
DNS_CONF = '/etc/resolv.conf'
if not os.path.exists(DNS_CONF) or not os.access(DNS_CONF, os.R_OK):
    # supply explicit DNS servers instead of relying on resolv.conf discovery
    configure_dns_servers(['8.8.8.8', '1.1.1.1'])

Prevention

When it happens

Trigger: Running on a host where /etc/resolv.conf does not exist (minimal containers, some macOS setups), has restrictive permissions, or contains malformed nameserver lines; also triggered if the file lists only local IPs that get filtered out and subsequent parsing raises.

Common situations: Docker/alpine containers without resolv.conf, chroot/sandboxed environments, systemd-resolved stub resolver oddities, read-only filesystems.

Related errors


AI-assisted analysis of XX-net/XX-Net@cfa5bc17b6 (2026-08-27). Data as JSON: /api/errors/0d74d227df9e3641. Report an issue: GitHub.