How to Solve DNS Resolution Error on Linux Server?
Step by step guide for temporary failure in name resolution, domain resolution failure and apt update DNS errors.
Although Linux servers appear to have an internet connection, domain addresses may not be resolved. In this case, the server can access IP addresses, but google.com, debian.org, ubuntu.com or license/API services.
This problem especially manifests itself in the following processes:
- apt update or yum update Error received during
- WHMCS license, payment or API links not working
- Game panel cannot connect to remote API addresses
- Domain ping not working while ping IP is running on the server
- Temporary failure in name resolution error seen
1. Understanding If DNS Is Really the Problem
First check the server's public internet access by pinging its IP address.
ping -c 4 8.8.8.8
If this command responds, the server has access to the Internet at the IP level. Now test domain resolution:
ping -c 4 google.com
If IP ping works but domain ping does not work, the problem is most likely on the DNS side.
2. Checking Current DNS Settings
In Linux systems, DNS servers are usually /etc/resolv.conf is defined in the file.
cat /etc/resolv.conf
A healthy DNS setting usually looks like this:
nameserver 1.1.1.1 nameserver 8.8.8.8
If the file is empty, contains incorrect IP addresses, or only writes local/non-working DNS addresses, domain resolution may fail.
3. Temporary DNS Definition
For quick testing, you can define temporary DNS with the following command:
echo "nameserver 1.1.1.1" > /etc/resolv.conf echo "nameserver 8.8.8.8" >> /etc/resolv.conf
Test again later:
ping -c 4 google.com
4. Persistent DNS Setting on Ubuntu / Debian Systems
On modern Ubuntu systems, network settings are usually netplan It is managed by . List Netplan files:
ls /etc/netplan/
Edit the file:
nano /etc/netplan/01-netcfg.yaml
Example DNS definition:
network:
version: 2
ethernets:
eth0:
dhcp4: true
nameservers:
addresses:
- 1.1.1.1
- 8.8.8.8To apply the setting:
netplan apply
If you are connected via SSH and are unsure of the network setting, be careful. Incorrect netplan setting may break your SSH connection.
5. CentOS / AlmaLinux / Rocky Linux DNS Setting
On RedHat-based systems, DNS settings can be made via NetworkManager.
To see the active connection name:
nmcli con show
Example DNS setting:
nmcli con mod "System eth0" ipv4.dns "1.1.1.1 8.8.8.8" nmcli con up "System eth0"
Your connection name may be different. You must use your own connection name in the command.
6. systemd-resolved Check
DNS resolution on some systems systemd-resolved It is managed by the service.
systemctl status systemd-resolved
If the service is down you can start it:
systemctl enable systemd-resolved systemctl start systemd-resolved
To see DNS status:
resolvectl status
7. DNS Checking for Package Update Errors
When DNS is corrupt, package managers won't work either. For example, the following errors may occur:
Temporary failure resolving 'archive.ubuntu.com' Could not resolve host Name or service not known
In this case, the package store should not be considered corrupt. DNS resolution should be tested first.
Common Mistakes
- Thinking there is no internet but not realizing that actually only DNS is corrupted
- Writing temporary DNS in /etc/resolv.conf file and thinking it is a permanent solution
- Incorrect whitespace indentation in Netplan file
- Misspelling the NetworkManager connection name
- Thinking that the working API or licensing system is faulty due to a DNS problem
FAQ
IP ping works but domain ping does not work, what is the problem?
There is most likely a DNS resolution problem. The server can access the internet, but it cannot translate domain names into IP addresses.
Which DNS servers can I use?
Commonly available are 1.1.1.1, 1.0.0.1, 8.8.8.8 and 8.8.4.4. Private DNS server may be preferred in corporate structures.
Why does resolv.conf change by itself?
Because the file is automatically managed by netplan, NetworkManager or systemd-resolved on most systems.
Safety and Operations Recommendations
- Be sure to perform a domain resolution test after DNS change.
- Add DNS errors in payment, licensing, and API systems to the first checklist.
- Define at least two DNS addresses instead of a single DNS.
- If your server provider provides private DNS, consider that as well.
- Note that incorrect netplan setting may break the SSH connection.
This article is specially prepared for PvPServer.