
How to Find Your DNS Server IP on Linux: A Step-by-Step Guide
Whether you’re troubleshooting a network issue, optimizing your internet speed, or tightening your security, knowing your DNS server’s IP address is essential. The Domain Name System (DNS) acts as the internet’s phonebook, translating human-friendly domain names (like example.com
) into computer-friendly IP addresses. When this system falters, your access to the web can become slow or stop entirely.
Fortunately, Linux provides several straightforward command-line tools to quickly identify which DNS servers your system is using. Here are four simple and effective methods to find your DNS server IP.
Method 1: The Classic Approach with resolv.conf
For decades, the /etc/resolv.conf
file has been the primary location for DNS configuration on Linux systems. This file contains the IP addresses of the nameservers your system queries.
To view its contents, open your terminal and use the cat
command:
cat /etc/resolv.conf
You will see output similar to this:
# Generated by NetworkManager
nameserver 8.8.8.8
nameserver 8.8.4.4
In this output, the lines beginning with nameserver
list the IP addresses of the DNS servers. In the example above, the system is configured to use Google’s public DNS servers.
Important Note: On many modern Linux distributions (like Ubuntu 20.04 and newer), you might see nameserver 127.0.0.53
. This is not an error. It means your system is using a local DNS caching service called systemd-resolved
. To find the actual upstream DNS servers, you’ll need the next method.
Method 2: The Modern Method with systemd-resolve
If your system uses systemd-resolved
, the systemd-resolve
command is the most accurate way to check your DNS configuration. It provides a comprehensive overview of your system’s DNS settings, including servers used for each network interface.
Run the following command in your terminal:
systemd-resolve --status
The output will be detailed, but you should look for a section called “Global” or a section for your specific network interface (e.g., eth0
or wlan0
).
Global
DNS Servers: 1.1.1.1
1.0.0.1
DNS Domain: ~.
...
Link 2 (enp0s3)
Current Scopes: DNS
LLMNR setting: yes
MulticastDNS setting: no
DNSSEC setting: no
DNSSEC supported: no
DNS Servers: 1.1.1.1
1.0.0.1
The IP addresses listed under “DNS Servers” are the ones your system is actively using. This command is the definitive source of truth on most modern Linux systems.
Method 3: Using NetworkManager’s nmcli
For systems that use NetworkManager to handle network connections (common in desktop environments and distributions like Fedora and CentOS), the nmcli
command-line tool is a powerful option.
To find your DNS servers, you can ask nmcli
to show the details of your active device and then filter for the DNS lines:
nmcli dev show | grep IP4.DNS
The output will be clean and direct:
IP4.DNS[1]: 8.8.8.8
IP4.DNS[2]: 8.8.4.4
This command efficiently queries NetworkManager for its current configuration and displays only the relevant DNS server information.
Method 4: A Practical Test with dig
Sometimes you don’t just want to see what’s configured—you want to confirm which DNS server is actively responding to your requests. The dig
(Domain Information Groper) tool is perfect for this.
Simply dig
any domain name:
dig google.com
Scroll to the bottom of the output. The last few lines will tell you which server answered your query.
;; Query time: 12 msec
;; SERVER: 192.168.1.1#53(192.168.1.1)
;; WHEN: Tue Nov 21 10:30:00 EST 2023
;; MSG SIZE rcvd: 55
The line starting with ;; SERVER:
shows the IP address of the DNS server that handled the request. In this case, it was a local router at 192.168.1.1
. This is an excellent way to verify your settings in a real-world scenario.
Actionable Security and Performance Tips
Knowing your DNS server is the first step. The next is ensuring it’s the right one for you.
- Improve Performance: Your Internet Service Provider’s (ISP) default DNS may not be the fastest. Switching to a public DNS provider like Cloudflare (1.1.1.1) or Google (8.8.8.8) can often result in faster page load times.
- Enhance Security and Privacy: Some third-party DNS providers offer enhanced security features, such as blocking access to known malicious websites or preventing your ISP from logging your browsing history.
- Enable Content Filtering: Services like OpenDNS (208.67.222.222) can be configured to block specific categories of content, making it a useful tool for parental controls or enforcing company policies.
By mastering these simple commands, you gain greater visibility and control over a critical component of your Linux system’s network configuration, allowing you to troubleshoot issues faster and optimize your internet experience.
Source: https://www.tecmint.com/find-my-dns-server-ip-address-in-linux/