Troubleshooting network connectivity often requires you to check the DNS server in Linux. Knowing how to check DNS server in Linux is a fundamental skill for system administrators and developers who need to diagnose name resolution issues quickly. Whether you’re dealing with a slow website or a complete network outage, the DNS server is usually the first place to look. This guide will walk you through multiple methods, from simple command-line tools to checking configuration files, so you can pinpoint the problem fast.
Why Checking The DNS Server Matters
DNS translates domain names into IP addresses. If your system can’t reach the DNS server, you won’t be able to browse the web or access remote servers by name. Checking the DNS server helps you confirm that your system is using the correct resolver. It also reveals if the server is responding or if there’s a misconfiguration in your network settings.
In Linux, there are several ways to find out which DNS server your machine is using. Some methods show the current active server, while others reveal the configured servers in system files. You might also need to check if the DNS server is reachable and working properly.
How To Check Dns Server In Linux Using Command-Line Tools
The fastest way to check your DNS server is through the terminal. Linux offers several built-in commands that give you direct answers. Below are the most reliable methods.
Using The Resolvectl Command
Modern Linux distributions use systemd-resolved for DNS resolution. The resolvectl command is the primary tool to interact with it. To see your current DNS servers, run:
resolvectl status
This command displays detailed information about each network interface. Look for the line that says “DNS Servers” under your active interface (like eth0 or wlan0). It lists the IP addresses of the servers your system is using right now. If you see multiple servers, they are listed in priority order.
For a quicker output, use:
resolvectl dns
This shows only the DNS server IPs for all interfaces. It’s concise and perfect for scripting.
Using The Systemd-Resolve Command
On older systemd systems, you might have systemd-resolve instead. The syntax is similar:
systemd-resolve --status
This command works almost identically to resolvectl. It prints the DNS servers per interface. If you get an error saying the command is not found, your system likely uses a different resolver.
Using The Nmcli Command
If your system uses NetworkManager, nmcli is your best friend. To see DNS servers for your active connection, run:
nmcli dev show | grep DNS
This filters the output to show only DNS-related lines. You’ll see the primary and secondary DNS servers. Alternatively, use:
nmcli con show "YourConnectionName" | grep ipv4.dns
Replace “YourConnectionName” with the actual name from nmcli con show. This shows the configured DNS servers for that specific connection profile.
Checking The /Etc/resolv.conf File
The traditional way to check DNS servers is by reading the /etc/resolv.conf file. This file lists the nameservers your system should use. Open it with:
cat /etc/resolv.conf
Look for lines starting with nameserver. Each line gives one DNS server IP address. However, be aware that this file might be dynamically managed by systemd-resolved or NetworkManager. It may show a local address like 127.0.0.53, which points to a local resolver stub. In that case, the actual upstream DNS servers are hidden and you need to use resolvectl instead.
Using The Dig Command
The dig command is a powerful DNS lookup tool. It can also tell you which server answered your query. To check the default DNS server, run:
dig example.com
Look at the “SERVER” line in the output. It shows the IP address and port of the DNS server that provided the answer. For example: SERVER: 8.8.8.8#53. This tells you the actual server used for that query.
If you want to test a specific DNS server, add its IP at the end:
dig @8.8.8.8 example.com
This forces dig to use that server. It’s useful for comparing responses from different DNS providers.
Using The Nslookup Command
nslookup is another classic tool. To see your current DNS server, run:
nslookup example.com
The first line of output shows the server your system used. It looks like: Server: 192.168.1.1. You can also query a specific server:
nslookup example.com 8.8.8.8
This sends the query to Google’s public DNS. nslookup is available on almost all Linux distributions and is simple to use.
Using The Host Command
The host command is lightweight and fast. To check your DNS server, run:
host example.com
The output shows the IP address of the domain and sometimes the server used. For more detail, add the -v flag:
host -v example.com
This prints verbose information, including the query time and the server that responded. It’s less common than dig but works well for quick checks.
Checking DNS Server Configuration Files
Sometimes you need to see the configured DNS servers, not just the active ones. Configuration files hold the settings that persist across reboots. Here are the key files to inspect.
The /Etc/resolv.conf File Details
We already mentioned this file. It’s the primary DNS configuration file. Besides nameserver lines, it may contain search and domain directives. The search line defines domain suffixes to append when you use short hostnames. For example:
search example.com
nameserver 8.8.8.8
nameserver 8.8.4.4
If this file is managed by a network service, it might be overwritten at boot. To make permanent changes, you need to edit the appropriate network configuration files instead.
NetworkManager Configuration
If you use NetworkManager, DNS settings are stored in connection profiles. To see them, run:
nmcli con show "YourConnectionName" | grep dns
You can also edit the connection with:
nmcli con mod "YourConnectionName" ipv4.dns "8.8.8.8 8.8.4.4"
This sets static DNS servers for that connection. After modification, restart the connection:
nmcli con down "YourConnectionName" && nmcli con up "YourConnectionName"
Systemd-Resolved Configuration
systemd-resolved uses a configuration file at /etc/systemd/resolved.conf. Open it with:
cat /etc/systemd/resolved.conf
Look for the DNS= line. It may contain a space-separated list of DNS servers. If the line is commented out (starts with #), systemd-resolved uses the servers from /etc/resolv.conf or DHCP. You can uncomment and edit this file to set global DNS servers.
Netplan Configuration (Ubuntu)
Ubuntu 18.04 and later use Netplan for network configuration. DNS servers are defined in YAML files under /etc/netplan/. For example:
cat /etc/netplan/01-netcfg.yaml
Look for the nameservers: section. It lists addresses like:
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
After editing, apply changes with:
sudo netplan apply
Testing DNS Server Reachability
Knowing the IP address of your DNS server is only half the battle. You also need to confirm it’s reachable and responding. Here are simple tests.
Ping The DNS Server
A basic ping test checks if the server is online. Run:
ping -c 4 8.8.8.8
Replace 8.8.8.8 with your DNS server IP. If you get replies, the server is reachable. If not, there might be a network issue or firewall blocking ICMP.
Test DNS Resolution With Dig
Use dig to query a known domain:
dig @8.8.8.8 google.com
If you get a response with an IP address, the server is working. Look for the “status: NOERROR” line. Any other status indicates a problem.
Check For DNS Timeouts
Sometimes the server is reachable but slow. Use dig with timing:
dig +time=5 google.com
This sets a 5-second timeout. If the query fails, your DNS server might be too slow or unresponsive. You can also check the query time in the output: “Query time: 12 msec”. High times indicate network congestion or server overload.
Common DNS Issues And How To Diagnose Them
Even after checking your DNS server, you might still face problems. Here are typical issues and how to find them.
Wrong DNS Server Configured
If your system uses an incorrect DNS server, you’ll get resolution failures. Compare the output of resolvectl status with what you expect. If you see a private IP like 192.168.1.1 but you intended to use 8.8.8.8, you need to update your network settings.
DNS Server Not Responding
If dig returns “connection timed out; no servers could be reached”, your DNS server might be down. Try pinging it. If ping works but DNS doesn’t, the server might be blocking queries from your IP or the DNS service itself is stopped.
DNS Cache Issues
Your system caches DNS responses. A stale cache can cause old IP addresses to be used. Flush the cache with:
sudo resolvectl flush-caches
Or for systemd-resolved:
sudo systemd-resolve --flush-caches
After flushing, test again. If the problem goes away, it was a cache issue.
Firewall Blocking DNS
DNS uses UDP port 53 (and sometimes TCP). Check if your firewall allows outbound DNS traffic:
sudo iptables -L -n | grep :53
If you see DROP or REJECT rules for port 53, you need to adjust your firewall settings. On systems with ufw, run:
sudo ufw status
Make sure DNS traffic is allowed.
Automating DNS Server Checks
For system administrators, manual checks are time-consuming. You can automate DNS server verification with simple scripts. Here’s a bash example:
#!/bin/bash
dns_servers=$(resolvectl dns | awk '{print $4}')
for server in $dns_servers; do
if ping -c 1 -W 2 $server &>/dev/null; then
echo "$server is reachable"
else
echo "$server is unreachable"
fi
done
This script gets the DNS servers from resolvectl and pings each one. You can extend it to test resolution with dig. Schedule it with cron to monitor DNS health regularly.
Frequently Asked Questions
How Do I Check The DNS Server In Linux Without Using The Terminal?
You can check DNS servers through the GUI. In GNOME, go to Settings > Network > click the gear icon next to your connection > IPv4 or IPv6 tab. The DNS servers are listed there. In KDE, go to System Settings > Connections > select your connection > IPv4 tab. The GUI shows the same information as the terminal but in a visual format.
What Is The Difference Between /Etc/resolv.conf And Resolvectl?
/etc/resolv.conf is a legacy configuration file that lists nameservers. However, modern systems often use systemd-resolved, which manages DNS dynamically. resolvectl shows the actual active DNS servers, which may differ from the static file. The file might point to a local stub resolver (127.0.0.53) that forwards queries to the real servers.
Why Does My Linux System Show 127.0.0.53 As The DNS Server?
This is the local stub resolver provided by systemd-resolved. It listens on 127.0.0.53:53 and forwards queries to the upstream DNS servers configured in systemd-resolved. This setup allows caching and better integration with network management. To see the real upstream servers, use resolvectl status.
Can I Use Multiple DNS Servers In Linux?
Yes, you can configure multiple DNS servers. They are listed in priority order. The system tries the first server; if it fails, it moves to the next. In /etc/resolv.conf, list them on separate nameserver lines. In NetworkManager, separate IPs with spaces. systemd-resolved also supports multiple servers.
How Do I Check If My DNS Server Is Working For A Specific Domain?
Use dig or nslookup with the domain name. For example, dig google.com returns the IP address if resolution works. If you get “NXDOMAIN”, the domain doesn’t exist. If you get “SERVFAIL”, the DNS server has a problem. You can also use host google.com for a quick check.
Conclusion
Knowing how to check DNS server in Linux is essential for network troubleshooting. You now have multiple tools at your disposal: resolvectl, nmcli, dig, nslookup, and configuration files like /etc/resolv.conf. Each method gives you a different perspective on your DNS setup. Start with resolvectl status for the most accurate view of active servers. Then use dig to test actual resolution. If you encounter issues, check your network configuration files and flush the DNS cache. With these skills, you can quickly identify and fix DNS problems, ensuring your Linux system stays connected and responsive. Remember to automate checks if you manage multiple machines—it saves time and catches issues early.