Understanding how to check the name server configuration on a Linux system is essential for network troubleshooting, system administration, and ensuring proper domain name resolution. Name servers, also known as DNS servers, translate human-friendly domain names into IP addresses, allowing your system to connect to websites and other services efficiently.
This comprehensive guide explains multiple methods to check the name server settings on Linux, how to interpret the results, and tips for troubleshooting DNS-related issues. Whether you are a beginner or an experienced user, you will find valuable information on verifying and managing DNS servers.
What is a Name Server?
Name servers are specialized servers that handle the Domain Name System (DNS) lookups. When you type a website URL into your browser, the name server translates that URL into the IP address of the server hosting the website.
Linux systems rely on configured name servers to resolve domain names system-wide. These settings can be configured at different levels, including the system resolver files and the network manager.
Note: Incorrect DNS settings can cause network failures, slow internet access, or inability to reach certain domains.
Common DNS Configuration Files in Linux
Before diving into commands, it is important to know where DNS configurations are stored in Linux systems. The main configuration files and locations include:
| File/Location | Description |
|---|---|
/etc/resolv.conf |
Main system resolver configuration file. Lists name servers used by the system. |
/etc/nsswitch.conf |
Configures the order in which name resolution sources are queried. |
| NetworkManager settings | Manages DNS configuration dynamically on systems using NetworkManager. |
/etc/systemd/resolved.conf |
Configuration for systemd-resolved, which handles DNS resolution on newer systems. |
Method 1: Checking Name Servers Using resolv.conf
The most traditional and widely used method to check DNS servers on Linux is by examining the /etc/resolv.conf file. This file contains the IP addresses of the DNS servers the system queries for name resolution.
To view the contents of resolv.conf, use the following command in the terminal:
cat /etc/resolv.conf
A typical output looks like this:
nameserver 8.8.8.8
nameserver 8.8.4.4
search example.com
Explanation:
nameserverlines specify the IP addresses of DNS servers.searchspecifies the domain suffixes to append during resolution.
Important: On some systems, /etc/resolv.conf may be dynamically managed and overwritten by network management services such as NetworkManager or systemd-resolved.
Method 2: Using nmcli Command (NetworkManager)
Many modern Linux distributions use NetworkManager to manage network connections. NetworkManager maintains its own DNS settings that may override /etc/resolv.conf.
You can query the DNS servers configured for a specific connection or device using nmcli:
nmcli device show | grep IP4.DNS
This command outputs the DNS servers assigned to each network device, for example:
IP4.DNS[1]: 192.168.1.1
IP4.DNS[2]: 8.8.8.8
You can also check DNS for a specific connection:
nmcli connection show <connection-name> | grep ipv4.dns
Replace <connection-name> with the active connection name, which you can list by:
nmcli connection show --active
Method 3: Using systemd-resolve or resolvectl
On systems running systemd with systemd-resolved service enabled, DNS resolution is handled by this service. You can check the DNS servers used by systemd-resolved by running:
systemd-resolve --status
Or, on newer systemd versions:
resolvectl status
The output includes detailed information about the current DNS servers per network interface, the current DNS domain, and more, such as:
Global
DNS Servers: 8.8.8.8
8.8.4.4
DNSSEC NTA: 10.in-addr.arpa
16.172.in-addr.arpa
This is a very reliable way to get DNS info on modern Linux systems.
Method 4: Using dig or nslookup Commands
While dig and nslookup are primarily used to query DNS servers, they can help identify which name server your system is using by specifying the default server queried.
Run dig without specifying a server:
dig google.com
At the end of the output, look for the line starting with SERVER:, which shows the IP and port of the DNS server that answered the query. For example:
; <> DiG 9.16.1-Ubuntu <> google.com
;; SERVER: 8.8.8.8#53(8.8.8.8)
Similarly, with nslookup:
nslookup google.com
You will see something like:
Server: 192.168.1.1
Address: 192.168.1.1#53
This indicates your system queried the DNS server at 192.168.1.1.
Understanding DNS Resolution Order
Linux systems use /etc/nsswitch.conf to determine the order of name resolution methods, such as DNS, files, or mDNS. The relevant line looks like this:
hosts: files dns myhostname
This means the system first checks local files like /etc/hosts, then queries DNS, and finally uses the local hostname.
Knowing this helps to understand that even if DNS servers are configured correctly, local files or other services might affect name resolution.
Diagnosing DNS Issues
Sometimes, DNS resolution fails or is slow. Here are some steps to diagnose problems:
- Check the configured name servers: Use
cat /etc/resolv.conforsystemd-resolve --status. - Test connectivity to DNS servers: Use
pingornc -zv <dns-server-ip> 53to check if the DNS server is reachable. - Use
digornslookupto test queries directly. - Restart network services: Sometimes restarting NetworkManager or systemd-resolved can fix temporary issues.
How to Change Name Server Settings
If you need to change the DNS servers your Linux system uses, the method depends on your setup.
Editing /etc/resolv.conf
Directly editing this file is not recommended on systems where it is managed automatically because it will be overwritten. However, for static setups, add or modify lines like:
nameserver 1.1.1.1
nameserver 8.8.8.8
Using NetworkManager
Change DNS via nmcli or the graphical network settings:
nmcli connection modify <connection-name> ipv4.dns "8.8.8.8 8.8.4.4"
nmcli connection up <connection-name>
Configuring systemd-resolved
Edit /etc/systemd/resolved.conf and set the DNS servers:
[Resolve]
DNS=8.8.8.8 8.8.4.4
FallbackDNS=1.1.1.1
Then restart the service:
sudo systemctl restart systemd-resolved
Summary of Commands to Check Name Server in Linux
| Command | Description | Typical Output |
|---|---|---|
cat /etc/resolv.conf |
Show configured name servers in resolver file. | nameserver 8.8.8.8nameserver 8.8.4.4 |
nmcli device show | grep IP4.DNS |
Show DNS configured by NetworkManager. | IP4.DNS[1]: 192.168.1.1 |
systemd-resolve --statusresolvectl status |
Show detailed DNS info from systemd-resolved. | Global DNS Servers and interface-specific info. |
dig google.com |
Query DNS and show the server used. | SERVER: 8.8.8.8#53(8.8.8.8) |
nslookup google.com |
Resolve domain and show DNS server used. | Server: 192.168.1.1 |
Additional Tips and Best Practices
- Backup configuration files before making changes.
- Use reliable DNS servers: Public DNS servers like Google (8.8.8.8), Cloudflare (1.1.1.1), and OpenDNS (208.67.222.222) are popular choices.
- Check for DNS leaks if using VPN or proxy services.
- Regularly update your system to benefit from improved DNS resolution services and security patches.
Conclusion
Checking and understanding the name server settings on Linux is crucial for network functionality and troubleshooting. Multiple methods exist depending on your Linux distribution and network management system.
From examining /etc/resolv.conf to querying NetworkManager and systemd-resolved, each approach provides insights into your system’s DNS configuration. Using tools like dig and nslookup helps validate the DNS servers actively used for domain resolution.
With this guide, you can confidently inspect, diagnose, and configure DNS settings on your Linux system, ensuring smooth and reliable network connectivity.