Introduction
Network connectivity is a fundamental aspect of any modern computing environment. While many things can go wrong, one of the most common issues is Domain Name System (DNS) resolution failure. DNS is the service that translates human-friendly domain names (like www.google.com) into IP addresses that computers use to connect to each other. If DNS isn't working, you might be connected to the internet but still unable to reach any websites.
This lab provides a structured, hands-on approach to diagnosing and resolving a DNS-related network problem. You will learn a sequence of commands to test your connection, identify the DNS issue, correct the configuration, and confirm that your connection is fully restored.
By the end of this lab, you will be equipped with a reliable checklist of initial troubleshooting steps to tackle DNS connectivity challenges on a Linux system.
Confirm the Problem by Pinging a Domain Name
When troubleshooting, the first step is always to confirm the problem. A common way to test internet connectivity is with the ping command. Let's try to ping a well-known domain, google.com. We will use the -c 4 option to send only four packets.
Execute the following command in your terminal:
ping -c 4 google.com
You will see an error message indicating a name resolution failure.
ping: google.com: Temporary failure in name resolution
This error tells us that the system was unable to translate the domain name google.com into an IP address. This strongly suggests a problem with DNS.
Isolate the Problem by Pinging an IP Address
We suspect a DNS issue, but we need to confirm that our basic internet connection is still working. We can do this by pinging a public IP address directly, which bypasses the DNS name resolution process. We'll use Google's public DNS server IP, 8.8.8.8.
Run the following command:
ping -c 4 8.8.8.8
This time, the ping should be successful. You will see replies from the server.
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=116 time=1.23 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=116 time=1.28 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=116 time=1.30 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=116 time=1.25 ms
--- 8.8.8.8 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3005ms
rtt min/avg/max/mdev = 1.230/1.265/1.301/0.026 ms
Since we can ping an IP address but not a domain name, we have now confirmed that the problem is with DNS resolution.
Inspect and Correct DNS Settings
Now that we know DNS is the problem, let's look at the DNS configuration file. On Linux, this is typically /etc/resolv.conf. This file tells the system which DNS servers to use.
Let's view its contents:
cat /etc/resolv.conf
The output will show the nameserver that was configured by our setup script.
nameserver 192.0.2.1
The IP address 192.0.2.1 is reserved for documentation and testing purposes; it does not point to a real DNS server. This is the cause of our problem.
To fix this, we need to replace the incorrect nameserver with a valid one. We will use Google's public DNS server, 8.8.8.8. We can overwrite the file using the echo and tee commands. This requires sudo privileges.
echo "nameserver 8.8.8.8" | sudo tee /etc/resolv.conf
Now, view the file again to confirm the change.
cat /etc/resolv.conf
The output should now show the correct nameserver.
nameserver 8.8.8.8
With a valid nameserver configured, we are one step closer to resolving the issue.
Flush the Local DNS Cache
Your system keeps a temporary cache of recently looked-up domain names to speed up future requests. After changing DNS settings, it's good practice to flush this cache to ensure the system uses the new settings immediately and doesn't rely on old, potentially incorrect, cached data.
On modern Linux systems, you can use the resolvectl command, which is part of systemd-resolved, to manage the DNS cache. To flush the caches, run the following command. It requires sudo privileges.
sudo resolvectl flush-caches
This command will not produce any output if it is successful. To verify that the cache has been cleared, you can check the cache statistics using the statistics command.
resolvectl statistics
Look for the Current Cache Size line in the output. After flushing, this value should be 0, confirming that the cache has been cleared. Note that other statistics like Hits and Misses will retain their previous values.
...
Cache
Current Cache Size: 0
Cache Hits: 24
Cache Misses: 67
...
Flushing the DNS cache is an important step to ensure your system is not using stale DNS records.
Confirm DNS Resolution and Connectivity
Now that we have corrected the DNS server configuration and flushed the local cache, it's time to verify the fix. We will repeat the same command from Step 1 that previously failed.
Let's try to ping google.com again.
ping -c 4 google.com
This time, the command should succeed. You will see the domain name get resolved to an IP address, and you will receive replies from the server. (Note: The exact IP address for google.com may vary).
PING google.com (142.250.189.238) 56(84) bytes of data.
64 bytes from nuq04s39-in-f14.1e100.net (142.250.189.238): icmp_seq=1 ttl=119 time=4.43 ms
64 bytes from nuq04s39-in-f14.1e100.net (142.250.189.238): icmp_seq=2 ttl=119 time=4.43 ms
64 bytes from nuq04s39-in-f14.1e100.net (142.250.189.238): icmp_seq=3 ttl=119 time=4.40 ms
64 bytes from nuq04s39-in-f14.1e100.net (142.250.189.238): icmp_seq=4 ttl=119 time=4.43 ms
--- google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 4.400/4.421/4.434/0.012 ms
Success! You have now successfully diagnosed and resolved a DNS connectivity issue.
Summary
Congratulations on completing this lab! You have successfully walked through a standard procedure for troubleshooting and resolving a common DNS-related network problem on a Linux system.
In this lab, you learned how to:
- Use
pingto test connectivity and differentiate between a general network failure and a DNS-specific issue. - Inspect your system's DNS server configuration in
/etc/resolv.conf. - Correct an invalid DNS configuration to restore name resolution.
- Flush the local DNS cache using
resolvectl flush-cachesto clear stale entries. - Confirm that the fix is working by successfully pinging a domain name.
These fundamental skills form a solid foundation for tackling many common network issues. You can now apply this logical, step-by-step process whenever you suspect DNS problems in the future.



