This page includes AI-assisted insights. Want to be sure? Fact-check the details yourself using one of these tools:

Get the exact connection name

VPN

How to Get DNS Server in Linux Step by Step Guide: DNS Resolution Essentials, resolv.conf, systemd-resolve, nmcli, NetworkManager

To get the DNS server in Linux step by step, start by locating your resolver configuration with /etc/resolv.conf and then verify using system utilities like systemd-resolve, resolvectl, NMCLI, or NetworkManager.

In this guide, you’ll learn how DNS is handled on Linux, how to identify the DNS servers currently in use, and how to change or optimize them for faster, more private, or more reliable lookups. We’ll cover multiple methods because different Linux distributions and desktop environments use different defaults systemd-resolved, NetworkManager, or plain resolv.conf. You’ll also find practical, step-by-step commands you can run today, plus troubleshooting tips and common pitfalls. By the end, you’ll know exactly how to view, configure, and verify DNS servers across a variety of setups.

What you’ll get in this article:

  • A clear breakdown of where DNS data lives on Linux resolv.conf, systemd-resolved, NetworkManager
  • Step-by-step commands to view and verify DNS servers
  • How to set DNS servers per-interface and globally
  • How to handle Linux distributions that overwrite DNS settings
  • Do’s and don’ts for reliable DNS configuration
  • Quick tips for performance, privacy, and basic troubleshooting
  • A handy FAQ with practical questions you’re likely to run into

Useful URLs and Resources text only for reference
Apple Website – apple.com
Artificial Intelligence Wikipedia – en.wikipedia.org/wiki/Artificial_intelligence
Google Public DNS – dns.google
Cloudflare DNS – 1.1.1.1
Cloudflare DoH – developers.cloudflare.com/1.1.1.1/dns-over-https
ISC DNS – isc.org
Arch Linux Wiki – wiki.archlinux.org
Ubuntu Documentation – help.ubuntu.com
systemd-resolved – man.archlinux.org/systemd-resolved
NetworkManager – nmcli docs

Overview of DNS on Linux

DNS on Linux can be managed by multiple components, and the exact setup depends on your distro and desktop environment. The two most common scenarios are:

  • A simple setup where /etc/resolv.conf contains one or more nameserver entries nameserver 1.2.3.4 and a search line. This is the legacy style and is still in use on some minimal servers or containers.
  • A modern setup where a resolver service runs in the background like systemd-resolved or NetworkManager and /etc/resolv.conf points to a local stub resolver often 127.0.0.53. The actual DNS servers are configured by the service or network manager and may differ per interface.

Why this matters: the DNS server you configure determines how name lookups are resolved, how fast they are, and what privacy or security features you get like DNS over TLS/DoH support in some stacks. If you’re troubleshooting or trying to improve performance, you’ll often need to identify whether your system uses /etc/resolv.conf directly or whether a resolver service is intercepting and returning results.

A few quick facts to keep in mind:

  • A typical Linux environment might route DNS queries through a local stub resolver 127.0.0.53 that forwards to upstream DNS servers you configured.
  • You can change DNS per interface or globally depending on the tool in use systemd-resolved, NetworkManager, or manual resolv.conf edits.
  • Many modern distros favor systemd-resolved or NetworkManager to manage DNS automatically, which can override manual edits to /etc/resolv.conf.

Check Current DNS Settings

Before changing anything, it’s good to know what you’re starting with. Here are the common ways to check your current DNS servers.

  • View resolv.conf How to repartition disk in ubuntu server a comprehensive guide

    • cat /etc/resolv.conf
    • If you see a line like nameserver 127.0.0.53, you’re likely using a local stub resolver. If you see actual IPs like 8.8.8.8, those are the upstream DNS servers currently in use.
  • Check systemd-resolved status

    • systemctl is-active systemd-resolved
    • resolvectl status
    • If your distro uses systemd-resolved, you’ll often see DNS information per interface here.
  • Check NetworkManager DNS

    • nmcli device show
    • nmcli connection show –active
    • These commands reveal per-connection DNS values as configured by NetworkManager.

Code snippets for quick reference:

cat /etc/resolv.conf
systemctl is-active systemd-resolved
resolvectl status
nmcli device show
nmcli connection show --active

If /etc/resolv.conf is a symlink to another file for example, /run/systemd/resolve/stub-resolv.conf or /run/resolvconf/resolv.conf, follow the actual chain to see who manages it.

Method 1: Using /etc/resolv.conf

This is the old, straightforward method. It’s most visible on minimal installs or containers where no resolver daemon is running. How to Find the Primary DNS Server The Ultimate Guide: DNS Addresses, Primary vs Secondary DNS, and Troubleshooting

What you’ll see:

  • nameserver lines with IP addresses
  • optional search domain entries

How to set DNS with resolv.conf temporary:

  • Edit /etc/resolv.conf and add:
    • nameserver 8.8.8.8
    • nameserver 1.1.1.1
    • search yourdomain.local

Important caveat:

  • On many systems, resolv.conf is managed by a service resolvconf, NetworkManager, or systemd-resolved. Manual edits can be overwritten. If you want persistence, use the appropriate tool for your setup see the sections below.

Example:

sudo bash -c 'printf "nameserver 8.8.8.8\nnameserver 1.1.1.1\n" > /etc/resolv.conf'

Method 2: Using systemd-resolved resolvectl

If your Linux system uses systemd-resolved, you’ll typically see a local DNS stub at 127.0.0.53 and the real servers configured behind the scenes. Discover How to Find When Someone Changes DNS Server Log and Audit DNS Activity

How to view:

systemctl status systemd-resolved
resolvectl status

How to set DNS for a specific interface:

sudo resolvectl dns eth0 8.8.8.8 1.1.1.1

How to set a global DNS fallback in most cases you’ll instead edit /etc/systemd/resolved.conf:

sudo nano /etc/systemd/resolved.conf

Add or modify:


DNS=8.8.8.8 1.1.1.1
FallbackDNS=9.9.9.9

Then restart: How to Open SQL Server in Visual Studio 2017 A Step by Step Guide: Connect, LocalDB, SSDT

sudo systemctl restart systemd-resolved

Notes:

  • If you’re on a distro that uses a different approach for the resolver, you may still see /etc/resolv.conf pointing to 127.0.0.53 as a result of systemd-resolved’s management.

Method 3: Using NetworkManager nmcli

NetworkManager is common on desktop-oriented Linux distros Ubuntu Desktop, Fedora Workstation, etc.. It manages DNS per-connection and can override manual edits to /etc/resolv.conf.

Check active DNS:

nmcli device show

Add DNS servers to a connection:


nmcli connection show --active

# Example: add DNS to the “WIFI-Name” connection
nmcli connection modify "WIFI-Name" ipv4.dns "8.8.8.8 1.1.1.1" ipv4.dns-search ""
nmcli connection up "WIFI-Name" --renew

If IPv6 is used, you can similarly set ipv6.dns: The Ultimate Guide How To Share A Server In Discord Like A Pro

nmcli connection modify "WIFI-Name" ipv6.dns "2001:4860:4860::8888" ipv6.dns-search ""

Notes:

  • Some systems also apply DNS from DHCP. If your DHCP server provides DNS, NM might override manual settings when renewing the lease. You can disable that by setting ignore automatically obtained DNS or by configuring a static connection.

Method 4: System-wide DNS changes for permanence

Some users want DNS changes to survive reboots or service restarts without manual edits to resolv.conf every time.

  • On systemd-resolved-enabled systems:
    • Edit /etc/systemd/resolved.conf as shown in the earlier example.
    • Then restart systemd-resolved.
  • On NetworkManager-enabled systems:
    • Use nmcli to set ipv4.dns and ipv6.dns on the active connection, and ensure the connection is reactivated.
  • If you’re using a DNS cache or a local DNS forwarder like dnsmasq:
    • Update its configuration to point to your chosen upstream servers, then restart the service.

Practical tip:

  • On many distros, resolv.conf is a symlink to a generated file. Always check the link target first before editing:
ls -l /etc/resolv.conf

Step-by-Step Guide: A Practical Workflow

Step 1: Identify your resolver manager

  • Check if systemd-resolved is running:
    • systemctl is-active systemd-resolved
  • Check if NetworkManager is managing DNS:
    • systemctl is-active NetworkManager
  • If neither is active, you’re likely using resolv.conf directly.

Step 2: Decide how you want DNS configured How to enable sftp server in ubuntu a comprehensive guide

  • Per-interface: use resolvectl systemd or nmcli NetworkManager
  • Globally: edit /etc/systemd/resolved.conf or use NetworkManager’s global settings

Step 3: Pick DNS servers

  • Common choices: Google DNS 8.8.8.8, 8.8.4.4, Cloudflare 1.1.1.1, 1.0.0.1, Quad9 9.9.9.9, 149.112.112.112
  • For privacy and performance, consider CleanDNS or your own ISP’s DNS if you trust it.

Step 4: Apply changes with the appropriate tool

  • systemd-resolved:
    • resolvectl dns eth0 8.8.8.8 1.1.1.1
    • Restart resolver after changes if needed
  • NetworkManager:
    • nmcli connection modify “” ipv4.dns “8.8.8.8 1.1.1.1”
    • nmcli connection up “
  • Direct resolv.conf edit if supported:
    • Add nameserver lines and ensure no conflicts with a running resolver

Step 5: Verify the changes

  • Check status and DNS list:
    • resolvectl status or systemd-resolve –status
    • nmcli device show to confirm DNS on interfaces
    • cat /etc/resolv.conf for current resolver addresses
  • Run a quick DNS query:
    • dig example.com @8.8.8.8 or nslookup example.com 1.1.1.1
    • The command should return a valid A/AAAA record and the server used in the response

Step 6: Consider advanced options

  • Enable DNS over TLS/DoH in supported setups
  • Use a local caching resolver for speed
  • Create per-user profiles to switch DNS servers easily

Code sample: quick switch via systemd-resolved How to add gifs to your discord server a step by step guide for reactions and channels

# Set Google DNS for all interfaces
sudo resolvectl dns eth0 8.8.8.8 8.8.4.4

# Confirm
resolvectl status

Code sample: quick switch via NetworkManager

sudo nmcli connection modify "WIFI-Name" ipv4.dns "1.1.1.1 8.8.8.8"
sudo nmcli connection up "WIFI-Name"

DNS Security and Privacy Options

  • DNS over HTTPS DoH and DNS over TLS DoT can improve privacy by encoding DNS queries. On Linux, you often enable these via browsers, or through dedicated proxies or tools like dnscrypt-proxy, cloudflared, or Unbound with DoT.
  • If you want DoH or DoT at the system level, you’ll typically run a local DoH/DoT proxy or configure systemd-resolved to forward DNS queries through a DoT-capable upstream.
  • Using modern DNS providers with built-in DNSSEC validation reduces the risk of spoofed responses, but you still need end-to-end security and trust in the resolver.
  • Privacy-aware setups often avoid ISP-provided DNS to reduce leaking browsing patterns. Cloudflare, Google, and Quad9 are common options, but there are many privacy-focused resolvers available.

Performance and Reliability Considerations

  • DNS latency is highly dependent on network paths and resolver quality. Typical DNS lookups can range from 5 ms on fast networks to several tens of milliseconds on slower paths.
  • Caching helps. A properly configured local resolver or a fast upstream like Cloudflare reduces repeated query times.
  • If you frequently switch networks laptops moving between WiFi access points, consider per-network DNS settings to avoid manual reconfiguration every time.
  • Redundancy matters. Using at least two upstream servers gives reliability in case one fails.

Table: Common DNS Tools and Use-Cases

Tool Use-Case Example Command
resolvectl / systemd-resolve Per-interface DNS with systemd resolvectl dns eth0 8.8.8.8 1.1.1.1
nmcli Per-connection DNS with NetworkManager nmcli connection modify “WIFI-Name” ipv4.dns “8.8.8.8 1.1.1.1”
/etc/resolv.conf Directly set DNS legacy nameserver 8.8.8.8
dig/nslookup Verify DNS resolution and server used dig example.com @8.8.8.8

Troubleshooting Common DNS Issues

  • If DNS lookups fail after a change:
    • Verify the resolver manager is running systemd-resolved, NetworkManager
    • Check /etc/resolv.conf and ensure it points to the intended resolver
    • Look for “DNS server not responding” by testing with a known good server like 8.8.8.8
  • If only some domains fail:
    • It could be DNSSEC validation, or a misconfigured per-domain search path. Check DNSSEC status if supported.
  • If you’re using VPNs:
    • VPN clients often push their own DNS servers to prevent leakage. Ensure you understand how the VPN affects DNS resolution on exit.

Automation and Scripting Ideas

  • Create a shell script that:
    • Detects whether systemd-resolved or NetworkManager is in use
    • Applies a preferred DNS list to all interfaces
    • Validates the change by performing a quick DNS lookup for a test domain
  • Use a per-user script to quickly switch DNS for a given session or network while traveling.

Sample snippet:

#!/bin/bash
# Quick switch: set Google and Cloudflare as DNS for all active connections
DNS_SERVERS="8.8.8.8 8.8.4.4 1.1.1.1 1.0.0.1"

for c in $nmcli -t -f NAME connection show --active; do
  nmcli connection modify "$c" ipv4.dns "$DNS_SERVERS" ipv4.dns-search ""
  nmcli connection up "$c"
done

# Verify
nmcli connection show --active

Common Pitfalls to Avoid

  • Editing /etc/resolv.conf directly on systems managed by NetworkManager or systemd-resolved will often be overwritten on reboot or when the network service restarts.
  • Mixing per-interface DNS with global DNS without understanding who manages the resolver can lead to inconsistent behavior.
  • Relying on a single DNS server can be risky if that server becomes unreachable; always provide redundancy two or more servers.
  • Forgetting to restart the appropriate service after changes can leave you with stale settings.

Frequently Asked Questions

How do I know which DNS server I’m using on Linux?

You can check /etc/resolv.conf for direct server entries, or run systemd-resolved status systemd-resolved or nmcli to see per-interface DNS. For a per-interface view, use resolvectl status or nmcli device show.

How can I view DNS settings for a specific interface?

Use resolvectl status to see per-interface DNS settings when systemd-resolved is active. For NetworkManager, run nmcli device show and look for DNS fields associated with the interface. What Happens When a Discord Server Owner Leaves: Ownership Transfers, Admin Prep, and Real-World Tips

How to change DNS servers permanently on Ubuntu 22.04+?

Use NetworkManager: nmcli connection modify “” ipv4.dns “8.8.8.8 1.1.1.1” and then nmcli connection up ““. If using systemd-resolved, edit /etc/systemd/resolved.conf and restart systemd-resolved.

Why does /etc/resolv.conf not show my DNS settings?

On systems using systemd-resolved or NetworkManager, /etc/resolv.conf may be a symlink to a generated file or a local stub 127.0.0.53. The actual settings are managed by the resolver service, not directly by resolv.conf.

How to flush DNS cache on Linux?

  • For systemd-resolved: sudo resolvectl flush-caches
  • For dnsmasq: sudo systemctl restart dnsmasq
  • For NetworkManager managed setups: restarting NetworkManager can flush caches sudo systemctl restart NetworkManager

Can I use both Google DNS and Cloudflare DNS?

Yes. You can specify multiple DNS servers in the order you prefer. The system will attempt the first, and fall back to the next if the first is unavailable.

How to configure DNS for Docker containers?

Docker inherits DNS settings from the host unless you override it in Docker’s daemon.json or container run-time options. Set DNS in the Docker daemon.json with:
{
“dns”:
}
Then restart Docker.

What is the difference between resolv.conf and systemd-resolved?

Resolv.conf is a simple file with nameserver entries. systemd-resolved is a daemon that provides name resolution services and can manage DNS settings per interface, sometimes making resolv.conf a pointer to a local stub. How to add a discord bot in 3 simple steps beginners guide: Quick Setup, Bot Permissions, and Hosting Tips

How to disable DNS caching?

Disabling caching is generally not recommended because it speeds up lookups, but if you need to diagnose DNS issues, you can stop any local resolver cache systemd-resolved, dnsmasq, or NetworkManager’s DNS caching and force direct queries to upstream servers.

How to set the DNS search domain?

In NetworkManager, use ipv4.dns-search with your domain appended: nmcli connection modify “” ipv4.dns-search “example.local”. In systemd-resolved, add a SearchDomains line to /etc/systemd/resolved.conf:


DNS=8.8.8.8
Domains=example.local

How can I check DNS latency to a server?

You can use a tool like dig to measure response time from a specific DNS server:

dig @8.8.8.8 example.com

The “QUERY/ANSWER” section will show the latency, or you can use time command:

time dig @8.8.8.8 example.com

How do I verify DNSSEC is working?

If your resolver supports DNSSEC validation, the dig command will show a DNSSEC status flag in the ANSWER section DO + AD bits and you’ll see a “status: secure” in dig +dnssec output. Some resolvers explicitly report secure results in the header. How to verify your server on discord a step by step guide

Quick Recap

  • You have several ways to view and configure DNS on Linux: /etc/resolv.conf, systemd-resolved, and NetworkManager.
  • Always identify your resolver manager before making changes. This prevents edits from being overwritten.
  • For persistence, prefer tools designed for your environment systemd-resolved or NetworkManager rather than editing resolv.conf directly.
  • Do not forget to test after changes: verify with resolvectl status, nmcli device show, and a practical DNS lookup.

If you want to keep things simple while still having good performance, consider a two-pronged approach: keep a fast primary DNS like Cloudflare or Google and a stable secondary like Quad9 or another trusted resolver. This gives you resilience if one server is temporarily unreachable.

With these steps, you’ll be able to confidently locate, configure, and verify DNS servers on any Linux setup, whether you’re a casual desktop user or a sysadmin managing multiple servers.

Sources:

Vpn翻墙指南:全面解析、最佳实践、在中国如何选择与使用VPN实现快速稳定访问与隐私保护

和運租車機場接送ptt:一篇搞懂預約、費用與常見問題! VPN 安全與線上預約指南

Is your vpn super unlimited not working heres how to fix it How to crash a discord server a comprehensive guide to protecting, preventing downtime, and incident response

Bd net vpn apkpure 在 APKPure 获取和使用 VPN 的完整攻略

Nordvpn dedicated ip review 2026: Fast, Secure, And Reliable Dedicated IP Solutions

Recommended Articles

×