In-depth Analysis and Solutions for Temporary Failure in Name Resolution in Linux Systems

Nov 24, 2025 · Programming · 8 views · 7.8

Keywords: Linux DNS Resolution | systemd-resolved | resolv.conf Configuration

Abstract: This paper provides a comprehensive analysis of the common 'Temporary failure in name resolution' error in Linux systems, exploring the relationship between systemd-resolved service and DNS configuration mechanisms. Through detailed code examples and configuration instructions, it offers long-term solutions including disabling systemd-resolved and manual configuration of resolv.conf, while comparing performance differences among various DNS servers. The article combines Ubuntu system characteristics to present complete troubleshooting procedures and preventive measures, suitable for system administrators and developers.

Problem Background and Phenomenon Analysis

In Linux system operations, domain name resolution failures are common network issues. When users attempt to use the ping command to access domain names, the system may return the error message ping: google.com: Temporary failure in name resolution. This phenomenon indicates that the system can perform normal network communication but encounters temporary failures during the domain name to IP address resolution process.

Root Cause Investigation

Through in-depth analysis of Ubuntu systems, we found that such problems are typically closely related to the configuration of the systemd-resolved service. In Ubuntu 18.04 and later versions, the system uses systemd-resolved as the default DNS resolution manager. This service creates symbolic links pointing /etc/resolv.conf to /run/systemd/resolve/stub-resolv.conf. While this design provides flexible DNS management capabilities, it may cause resolution failures in certain network environments.

Solution Implementation

To address the aforementioned problem, we provide the following complete solution:

First, it is necessary to stop and disable the systemd-resolved service. This is achieved through the following command sequence:

sudo systemctl stop systemd-resolved.service
sudo systemctl disable systemd-resolved.service

Next, remove the existing symbolic link configuration:

sudo rm /etc/resolv.conf

Then create a new resolv.conf configuration file:

sudo vim /etc/resolv.conf

Add reliable DNS server addresses in the configuration file, for example:

nameserver 208.67.222.222
nameserver 8.8.8.8
nameserver 1.1.1.1

Configuration Principle Explanation

The core of the above solution lies in bypassing the complex resolution chain of systemd-resolved and directly using static DNS server configuration. We use Python code to simulate the DNS resolution process to understand its working principle:

import socket

def dns_resolve(hostname):
    try:
        # Simulate system DNS resolution process
        ip_address = socket.gethostbyname(hostname)
        return ip_address
    except socket.gaierror as e:
        # Capture resolution failure exception
        print(f"DNS resolution failed: {e}")
        return None

# Test domain name resolution
result = dns_resolve("google.com")
if result:
    print(f"Resolved IP: {result}")
else:
    print("Resolution failed - check DNS configuration")

Network Environment Adaptation

In different network environments, DNS configuration requires corresponding adjustments. For enterprise internal networks, it is recommended to use internal DNS servers; for home or mobile networks, public DNS services such as Google DNS (8.8.8.8) or Cloudflare DNS (1.1.1.1) typically provide better stability.

Implement automated configuration detection through Bash scripts:

#!/bin/bash

# Check current DNS configuration
echo "Current DNS configuration:"
cat /etc/resolv.conf

# Test DNS resolution function
echo -e "\nTesting DNS resolution..."
if ping -c 1 google.com &> /dev/null; then
    echo "DNS resolution: SUCCESS"
else
    echo "DNS resolution: FAILED"
    echo "Recommended action: reconfigure /etc/resolv.conf"
fi

Preventive Measures and Best Practices

To prevent recurrence of similar problems, the following measures are recommended: regularly check DNS server availability, configure multiple backup DNS servers, and monitor network connection status. Additionally, understand the potential impact of system updates on network configuration and adjust relevant settings promptly.

Monitor DNS resolution status through system logs:

# View DNS-related logs
journalctl -u systemd-resolved

# Real-time network connection monitoring
netstat -tuln | grep :53

Performance Optimization Recommendations

When configuring multiple DNS servers, the system attempts resolution sequentially. It is recommended to place the fastest responding DNS server first to improve resolution efficiency. Test response times of different DNS servers using the dig command:

# Test DNS server response times
for dns in 8.8.8.8 1.1.1.1 208.67.222.222; do
    echo "Testing $dns..."
    time dig @$dns google.com | grep "Query time"
done

Through the complete solution and optimization recommendations provided above, users can effectively resolve domain name resolution failures in Linux systems and establish a stable network connection environment.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.