• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

TinyGrab

Your Trusted Source for Tech, Finance & Brand Advice

  • Personal Finance
  • Tech & Social
  • Brands
  • Terms of Use
  • Privacy Policy
  • Get In Touch
  • About Us
Home » How to check the DNS server in Linux?

How to check the DNS server in Linux?

April 14, 2025 by TinyGrab Team Leave a Comment

Table of Contents

Toggle
  • How to Check the DNS Server in Linux: A Comprehensive Guide
    • Diving Deep into DNS Detection Methods
      • 1. The resolvectl status Command
      • 2. Examining the /etc/resolv.conf File
      • 3. Using nmcli (NetworkManager Command-Line Interface)
      • 4. Leveraging systemd-resolve (Directly)
      • 5. Using dig or nslookup (For Active DNS Server Detection)
      • Understanding the Importance of DNS
    • Frequently Asked Questions (FAQs)
      • 1. What is DNS and why is it important?
      • 2. Why would I need to check my DNS server?
      • 3. How do I change my DNS server in Linux?
      • 4. What are some popular public DNS servers?
      • 5. Can I use more than two DNS servers?
      • 6. What is the difference between resolvectl and /etc/resolv.conf?
      • 7. How do I flush the DNS cache in Linux?
      • 8. My /etc/resolv.conf file says “DO NOT EDIT THIS FILE.” What does that mean?
      • 9. How do I determine which network interface is being used for internet connection?
      • 10. What does DNSSEC mean, and how do I check if it’s enabled?
      • 11. Why am I getting different DNS servers when using different methods?
      • 12. How can I prevent my DNS settings from being overwritten automatically?

How to Check the DNS Server in Linux: A Comprehensive Guide

Checking your DNS (Domain Name System) server in Linux is a fundamental troubleshooting and configuration task. There are multiple ways to achieve this, from using command-line tools to examining configuration files. I’m going to walk you through the most effective methods, giving you a rock-solid understanding of how to pinpoint your active DNS servers on any Linux system.

The most straightforward way to check your DNS server in Linux is to use the **resolvectl status** command. This command provides detailed information about your system’s DNS configuration, including the current DNS servers being used. Alternatively, you can inspect the /etc/resolv.conf file or use tools like nmcli and systemd-resolve for more specific information. Each method offers unique insights, making it essential to understand them all.

Diving Deep into DNS Detection Methods

Let’s dissect the different ways you can uncover the DNS servers your Linux system is currently leveraging. We will cover commands and configurations, arming you with the knowledge to handle any situation.

1. The resolvectl status Command

resolvectl is part of the systemd-resolved service and is, in many modern distributions, the go-to method for DNS management. This command offers a holistic view of your system’s DNS configuration.

  • How to use it: Simply open your terminal and type resolvectl status.

  • What it shows: The output will display a lot of information, but you’re primarily interested in the “Current DNS Server” and “DNS Servers” sections. These sections list the IP addresses of the DNS servers being used. You may see different interfaces listed as well, which is common in systems with multiple network connections.

  • Example:

    resolvectl status 

    The output will look something like this:

    Global       Protocols: LLMNR=resolve -mDNS -DNSOverTLS DNSSEC=no/unsupported resolv.conf mode: stub  Link 2 (enp0s3)       Current Scopes: DNS LLMNR/IPv4 LLMNR/IPv6     Current DNS Server: 8.8.8.8            DNS Servers: 8.8.8.8                         8.8.4.4        DNS Domain: ~. 

    This indicates that the DNS servers 8.8.8.8 and 8.8.4.4 are being used through the enp0s3 interface.

  • Benefits: Provides a comprehensive overview, works well with systemd-resolved, and supports modern DNS features.

2. Examining the /etc/resolv.conf File

Historically, the /etc/resolv.conf file has been the standard location for specifying DNS servers in Linux. While its role has evolved with the introduction of tools like systemd-resolved, it’s still a crucial file to understand.

  • How to use it: Use a text editor or the cat command to view the contents of the file. For example:

    cat /etc/resolv.conf 
  • What it shows: The file contains lines starting with nameserver, followed by the IP address of a DNS server.

  • Example:

    nameserver 8.8.8.8 nameserver 8.8.4.4 

    This signifies that 8.8.8.8 and 8.8.4.4 are the configured DNS servers.

  • Important Note: On many modern systems, /etc/resolv.conf is a symbolic link to a file managed by systemd-resolved or NetworkManager. Directly editing this file might not have the desired effect.

3. Using nmcli (NetworkManager Command-Line Interface)

If your system uses NetworkManager, nmcli provides a powerful way to inspect network connections and their DNS settings.

  • How to use it: Use the command nmcli dev show <interface_name>, replacing <interface_name> with the name of your network interface (e.g., eth0, wlan0).

  • What it shows: The output will include a section labeled IP4.DNS or IP6.DNS, listing the DNS servers associated with that interface.

  • Example:

    nmcli dev show eth0 

    The output might include lines like:

    IP4.DNS[1]:                             8.8.8.8 IP4.DNS[2]:                             8.8.4.4 

    Again, this confirms that 8.8.8.8 and 8.8.4.4 are being used as DNS servers.

  • Benefits: Provides connection-specific DNS information and integrates well with NetworkManager configurations.

4. Leveraging systemd-resolve (Directly)

Although resolvectl is generally preferred, you can directly use systemd-resolve for certain tasks.

  • How to use it: Utilize the command systemd-resolve --status. This mirrors some of the output of resolvectl status but is more focused on the systemd-resolved aspects.

  • What it shows: It will show the status of the systemd-resolved service, including links and associated DNS servers.

  • Example:

    systemd-resolve --status 

    The information presented is similar to that of resolvectl status, with potentially more details relevant to systemd-resolved itself.

5. Using dig or nslookup (For Active DNS Server Detection)

These are older, but still relevant, tools that can reveal which DNS server is actively resolving queries.

  • How to use it: Use the commands dig google.com or nslookup google.com. dig is generally preferred.
  • What it shows: The output will include the IP address of the server that responded to the DNS query. Look for the “SERVER:” line in the dig output.
  • Example: bash dig google.com or bash nslookup google.com In the dig output, you’ll find a section like: ;; SERVER: 192.168.1.1#53(192.168.1.1) ;; WHEN: Mon Oct 28 10:00:00 2024 ;; MSG SIZE rcvd: 59 This indicates that the DNS server at 192.168.1.1 is being used.

Understanding the Importance of DNS

Knowing your DNS servers is critical for network troubleshooting. Incorrect or non-functioning DNS servers can prevent you from accessing websites and online services. Being able to quickly identify and verify your DNS configuration is a powerful skill for any Linux user.

Frequently Asked Questions (FAQs)

Here are 12 frequently asked questions related to checking DNS servers in Linux, covering various aspects and providing valuable additional information.

1. What is DNS and why is it important?

DNS (Domain Name System) translates human-readable domain names (like google.com) into IP addresses that computers use to communicate. Without DNS, you’d have to remember IP addresses for every website you visit. It’s absolutely crucial for the Internet as we know it.

2. Why would I need to check my DNS server?

You might need to check your DNS server for several reasons:

  • Troubleshooting network connectivity: If you can’t access websites, an incorrect DNS server could be the culprit.
  • Verifying DNS changes: After changing your DNS settings, you’ll want to confirm that the changes have taken effect.
  • Identifying potential DNS hijacking: Unusual DNS server addresses could indicate a security issue.
  • Optimizing network performance: Switching to a faster DNS server can improve browsing speeds.

3. How do I change my DNS server in Linux?

The method for changing your DNS server depends on your network management setup. If using NetworkManager, you can modify the DNS settings through the graphical interface or using nmcli. If using systemd-resolved, you might need to edit configuration files or use resolvectl. Refer to your distribution’s documentation for the best approach.

4. What are some popular public DNS servers?

Some popular public DNS servers include:

  • Google Public DNS: 8.8.8.8 and 8.8.4.4
  • Cloudflare DNS: 1.1.1.1 and 1.0.0.1
  • OpenDNS: 208.67.222.222 and 208.67.220.220

5. Can I use more than two DNS servers?

Yes, you can configure multiple DNS servers. Your system will typically try the servers in the order they are listed. If the first server is unavailable, it will try the second, and so on.

6. What is the difference between resolvectl and /etc/resolv.conf?

resolvectl is a command-line tool for managing systemd-resolved, a system service that provides network name resolution. /etc/resolv.conf is a configuration file that historically specified DNS servers. On modern systems, /etc/resolv.conf is often a symbolic link managed by systemd-resolved or NetworkManager, so direct editing might not be effective. resolvectl allows you to view the DNS configuration managed by systemd-resolved.

7. How do I flush the DNS cache in Linux?

The command to flush the DNS cache depends on the DNS resolver being used. If you are using systemd-resolved, you can use the command sudo systemd-resolve --flush-caches. If you are using nscd (Name Service Cache Daemon), you can use the command sudo systemctl restart nscd.

8. My /etc/resolv.conf file says “DO NOT EDIT THIS FILE.” What does that mean?

This message usually indicates that /etc/resolv.conf is being managed by a network management tool like NetworkManager or systemd-resolved. Directly editing the file will likely be overwritten. You should use the appropriate tool to modify your DNS settings.

9. How do I determine which network interface is being used for internet connection?

The command ip route will show the default gateway and the associated network interface. The output will look something like this: “default via 192.168.1.1 dev eth0”. In this example, eth0 is the interface.

10. What does DNSSEC mean, and how do I check if it’s enabled?

DNSSEC (Domain Name System Security Extensions) adds a layer of security to DNS by digitally signing DNS records. This helps prevent DNS spoofing and other attacks. resolvectl status will often indicate if DNSSEC validation is enabled.

11. Why am I getting different DNS servers when using different methods?

This can happen if different network interfaces are configured to use different DNS servers, or if your system is using a combination of configuration methods. For example, one interface might be configured through NetworkManager, while another relies on a manually configured /etc/resolv.conf file (or its target file).

12. How can I prevent my DNS settings from being overwritten automatically?

The best way to prevent automatic overwrites is to understand which tool is managing your DNS settings (NetworkManager, systemd-resolved, etc.) and configure it accordingly. Avoid directly editing /etc/resolv.conf if it’s managed by another service. Consult your distribution’s documentation for specific instructions.

By mastering these techniques and understanding the nuances of DNS management in Linux, you’ll be well-equipped to tackle any DNS-related challenges that come your way. Remember to always consult your distribution’s official documentation for the most accurate and up-to-date information. Good luck!

Filed Under: Tech & Social

Previous Post: « Can You Pay a Best Buy Credit Card with a Gift Card?
Next Post: How to stop AirPods from beeping? »

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

NICE TO MEET YOU!

Welcome to TinyGrab! We are your trusted source of information, providing frequently asked questions (FAQs), guides, and helpful tips about technology, finance, and popular US brands. Learn more.

Copyright © 2025 · Tiny Grab