How to get DNS server in Linux step by step guide: you’ll learn exactly how to discover, view, and configure DNS servers on Linux systems, plus how to verify that queries are going to the right places. Quick fact: DNS is how your computer translates human-friendly domain names into IP addresses, and misconfigurations can slow you down or break internet access.
In this guide, you’ll get:
- A straightforward, step-by-step method to identify your current DNS servers
- How to set or change DNS servers on common Linux distributions and network managers
- How to verify DNS functionality with real-world tests
- A practical checklist to troubleshoot DNS issues quickly
- Real-world stats and best practices to keep your DNS setup healthy
Useful URLs and Resources text only
Google Public DNS – https://dns.google
Cloudflare 1.1.1.1 – https://1.1.1.1
OpenDNS – https://www.opendns.com
systemd-resolved – https://www.freedesktop.org/wiki/Software/systemd/resolved
NetworkManager – https://wiki.gnome.org/Projects/NetworkManager
Linux IP utility – https://man7.org/linux/man-pages/man8/ip.8.html
resolv.conf – https://man7.org/linux/man-pages/man5/resolv.conf.5.html
dig command – https://man7.org/linux/man-pages/man1/dig.1.html
nslookup – https://man7.org/linux/man-pages/man1/nslookup.1.html
nmcli DNS – https://developer trajet.example note: illustrative
Quick overview: why DNS matters in Linux
- DNS translates domain names to IP addresses, enabling browser access, email delivery, and API calls.
- If DNS is slow or misconfigured, you’ll see delays, timeouts, or failed connections.
- Linux handles DNS in several layers: /etc/resolv.conf, network manager configurations, and local resolvers like systemd-resolved or dnsmasq.
Statistics you can rely on:
- On average, a DNS lookup adds only a few milliseconds, but poor caching or dodgy servers can push that to hundreds of milliseconds.
- Most Linux desktops now rely on NetworkManager for DNS, while servers might use systemd-resolved, dnsmasq, or direct /etc/resolv.conf edits.
How to check your current DNS servers quickly
Method 1: Check resolv.conf
- Open a terminal and run: cat /etc/resolv.conf
- Look for lines starting with nameserver, for example:
nameserver 1.1.1.1
nameserver 8.8.8.8
Notes:
- Some modern systems generate resolv.conf dynamically, so edits might be overridden by your network manager.
Method 2: Use systemd-resolved status if your distro uses systemd
- Run: systemd-resolve –status
- Look for DNS Servers under the active link e.g., eth0, enp3s0 and the DNS domain.
Method 3: Check NetworkManager desktop users
- If you’re using NetworkManager nmcli, run: nmcli device show
- Scroll to IP4.DNS or DNS entries for the active connection.
Quick test: verify DNS works
- Use dig or nslookup to query a domain, for example:
dig +short example.com
nslookup example.com - If you see an IP address, DNS is responding. If not, you may be hitting a wrong server or a firewall is blocking DNS.
How to set or change DNS servers on Linux
Note: The exact method depends on whether you’re on a desktop environment, server, or container, and which network stack you’re using NetworkManager, systemd-resolved, or classic /etc/resolv.conf.
A. Using NetworkManager most desktop users
- Graphical method GNOME, KDE, etc.
- Open Network settings
- Choose your active connection Wi-Fi or Ethernet
- Go to DNS or IPv4/IPv6 settings
- Add DNS servers e.g., 1.1.1.1; 8.8.8.8
- Save and reconnect
- Command-line method nmcli
-
To set DNS servers for a connection:
nmcli connection modifyipv4.dns “1.1.1.1 8.8.8.8”
nmcli connection modifyipv4.ignore-auto-dns yes
nmcli connection down&& nmcli connection up -
To reset to automatic:
nmcli connection modifyipv4.ignore-auto-dns no How to Generate Rowid in SQL Server A Step by Step Guide 2026
B. Using systemd-resolved common on newer Ubuntu/Dedora
- Set DNS servers
- Create or edit /etc/systemd/resolved.conf
DNS=1.1.1.1 8.8.8.8
Cache=yes
- Restart the service
- sudo systemctl restart systemd-resolved
- Ensure the symlink exists: ls -l /etc/resolv.conf
It should point to /run/systemd/resolve/stub-resolv.conf or /etc/resolv.conf configured by systemd-resolved
- Verify
- systemd-resolve –status
- dig +short @127.0.0.53 example.com
C. Editing /etc/resolv.conf directly less common with modern managers
- Edit with a text editor:
sudo nano /etc/resolv.conf - Add:
nameserver 1.1.1.1
nameserver 8.8.8.8 - Save and test:
dig +short example.com
Caveat: In many systems, /etc/resolv.conf is managed by a service. Manual edits may be overwritten on reboot or network reconnect.
D. Using dnsmasq or local caching resolver
- Install dnsmasq if you want a local DNS caching layer:
sudo apt-get install dnsmasq - Configure dnsmasq to forward to upstream DNS:
echo “server=1.1.1.1” | sudo tee -a /etc/dnsmasq.d/upstream.conf - Start/restart:
sudo systemctl restart dnsmasq - Point your /etc/resolv.conf to localhost:
nameserver 127.0.0.1
E. Docker or container DNS considerations
- Containers may bypass host DNS or use Docker’s embedded DNS.
- Set DNS for a container via docker run –dns 1.1.1.1 or configure /etc/docker/daemon.json:
{
“dns”:
}
Step-by-step guide: switch DNS on a typical desktop Ubuntu with NetworkManager
- Open Settings and navigate to Network
- Choose your active connection Wi-Fi or Wired
- Click on the gear icon for IPv4
- Set Method to Automatic DHCP addresses only if you still want to obtain IPs automatically, then enter DNS servers in the DNS field
- Or switch to Manual and supply DNS servers
- Save, disconnect, and reconnect to apply
- Verify with dig +short example.com or nslookup example.com
Step-by-step guide: change DNS on a server without GUI
- Identify the active interface:
ip addr show - Decide your resolver approach:
- systemd-resolved
- resolv.conf managed by netplan or networkd
- dnsmasq or stub resolver
- Apply DNS in the chosen method:
- systemd-resolved: edit /etc/systemd/resolved.conf, add DNS=1.1.1.1 8.8.8.8
- /etc/resolv.conf: add nameserver lines if not managed by a service
- networkd/netplan: update YAML files, apply netplan apply
- Test:
dig +short google.com
systemd-resolve –status - Ensure persistence:
Reboot or restart the network service:
sudo systemctl restart NetworkManager or sudo systemctl restart systemd-resolved
Best practices for DNS security and performance
- Use at least two DNS servers for redundancy primary and secondary.
- Prefer DoH or DoT if privacy is a concern, depending on environment constraints.
- Enable DNS caching to reduce lookup time for frequently accessed domains.
- Regularly test DNS resolution with real-world domains, not just test addresses.
- Consider geographic DNS providers if your users are regionally concentrated.
- Keep your DNS software up to date to avoid known vulnerabilities.
Common DNS problems and quick fixes
- Problem: DNS server not reachable
- Check network connectivity, verify DNS server IPs, ensure firewall allows UDP/TCP 53
- Problem: Slow DNS responses
- Switch to a fast primary like Cloudflare or Google; enable caching; flush DNS cache
- Problem: Wrong IP returned
- Verify DNS upstreams, clear local cache, check hosts file entries
- Problem: No DNS after VPN
- Check VPN DNS routing and split-tunneling; ensure DNS leaks aren’t happening
DNS troubleshooting checklist minimal steps
- Confirm /etc/resolv.conf or systemd-resolved status shows expected DNS servers
- Run tests with dig and nslookup against known domains
- Check that networkManager or systemd-resolved services are running
- Verify firewall rules don’t block DNS port 53/udp
- Verify that IPv6 DNS if used is properly configured alongside IPv4
- Ensure there are no conflicting entries in hosts file
Performance and reliability tips
- Use at least two resolvers from different providers
- Prefer resolvers with strong privacy and robust uptime
- If you’re in a corporate or campus network, configure DNS filtering or split-horizon DNS as needed
- For home users, a small local caching resolver like dnsmasq can drastically improve response times
Advanced: testing DNS over TLS DoT or DNS over HTTPS DoH
- DoT: Use a client that supports DoT e.g., stubby or systemd-resolved with DoT upstream
- Example: configure stub-resolv to forward to 1.1.1.1 over TLS
- DoH: Use a browser or system that supports DoH for encrypted queries
- Note: DoT/DoH may require additional configuration and firewall allowances
Real-world examples
- Example setup for home network using Cloudflare:
- /etc/resolv.conf contains nameserver 127.0.0.1
- dnsmasq forwards to 1.1.1.1 and 8.8.8.8
- Example enterprise setup:
- DNS servers: 10.0.0.2 internal, 10.0.0.3 internal, and public 1.1.1.1 as fallback
- systemd-resolved caches external DNS and forwards to internal servers in /etc/systemd/resolved.conf
Comparison table: DNS management methods
-
Method: /etc/resolv.conf
Pros: Simple, universal fallback
Cons: Often overwritten by network managers; manual edits can be lost -
Method: NetworkManager
Pros: Centralized control; works well with VPNs
Cons: Desktop-centric; can be confusing on servers -
Method: systemd-resolved
Pros: Integrated with systemd; caching and DNSSEC support
Cons: Can be tricky to configure for advanced topologies -
Method: dnsmasq
Pros: Local caching; flexible forwarding
Cons: Extra service to maintain How To Generate Scripts In SQL Server A Step By Step Guide: Scripting Schema, Data, And Automation 2026
FAQ Section
Frequently Asked Questions
How do I know which DNS server my Linux machine is using?
You can check with cat /etc/resolv.conf, systemd-resolve –status, or nmcli device show, depending on your setup. Look for lines starting with nameserver or DNS entries.
How can I change DNS servers on Ubuntu?
If you use NetworkManager, use the GUI network settings or nmcli. For systemd-resolved setups, edit /etc/systemd/resolved.conf and restart systemd-resolved. For servers without a GUI, edit /etc/resolv.conf or configure netplan appropriately.
What is DNS cache, and should I clear it?
DNS cache stores recent lookups to speed up responses. Clearing the cache can fix stale data or test new settings. Use sudo systemd-resolve –flush-caches or restart the resolver service depending on your stack.
How do I test if DNS is working after changes?
Run dig +short example.com or nslookup example.com. If you get an IP address back, DNS is functioning. Use traceroute or mtr if you suspect network routing issues. How to Get a Discord Server ID The Ultimate Guide 2026
Can I use Google DNS and Cloudflare DNS at the same time?
Yes, you can specify multiple DNS servers. They will be used in order of preference or as fallback. Ensure your resolvers are configured to allow multiple upstreams.
What’s the difference between DoH and DoT?
DoH uses HTTPS to conceal DNS queries inside normal web traffic. DoT uses TLS to encrypt DNS over a dedicated channel. Both improve privacy but require compatible clients and sometimes specific network rules.
My DNS changes don’t persist after reboot. Why?
Many distros use a network manager or systemd-resolved to rewrite /etc/resolv.conf on boot. Edit the appropriate configuration file for your stack or disable auto-generation and set persistent DNS servers.
What is /etc/resolv.conf and why is it important?
It’s a configuration file that lists DNS servers your system uses to resolve domain names. It can be managed by various services; direct edits may be overwritten.
How can I set DNS for Docker containers?
Configure DNS in Docker daemon with daemon.json: {“dns”: }, or specify –dns when running containers. Remember containers can have their own DNS resolution independent from the host. How to generate a database diagram in sql server 2016 step by step guide 2026
What are common DNS mistakes to avoid?
- Mixing IPv4 and IPv6 DNS without proper handling
- Forgetting to set ignore-auto-dns when using manual DNS entries with NetworkManager
- Editing resolv.conf directly on systems that override it at boot
- Relying on a single DNS server without redundancy
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: How to Flush DNS Cache Server 2008 A Comprehensive Guide 2026
- 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
- 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 How to Fix the DNS Server Isn’t Responding Error 2026
- 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.
What you’ll see: How to Find the Primary DNS Server The Ultimate Guide: DNS Addresses, Primary vs Secondary DNS, and Troubleshooting 2026
- 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.
How to view: How to fix dns server and no internet access: DNS troubleshoot, internet connectivity, router settings 2026
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:
sudo systemctl restart systemd-resolved
Notes: How to Find Your Discord Server ID in Seconds: Quick Lookup, Copy ID, and Tips 2026
- 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:
nmcli connection modify "WIFI-Name" ipv6.dns "2001:4860:4860::8888" ipv6.dns-search ""
- 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
- 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 How To Execute A Job In SQL Server Like A Pro A Step By Step Guide 2026
- 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 “
“
- nmcli connection modify “
- 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
# 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 How to Find the Discord Server Code A Complete Guide to Finding Server Codes 2026
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.
How to change DNS servers permanently on Ubuntu 22.04+?
Use NetworkManager: nmcli connection modify “
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 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 Find the DNS Suffix for SMTP Server: DNS Suffix Lookup, SMTP DNS, MX Records, SPF Best Practices 2026
How to set the DNS search domain?
In NetworkManager, use ipv4.dns-search with your domain appended: nmcli connection modify “
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.
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. How to find ip address for minecraft server step by step guide: Quick, Easy Ways to Locate IP, Port, and DNS 2026
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
Bd net vpn apkpure 在 APKPure 获取和使用 VPN 的完整攻略
Nordvpn dedicated ip review 2026: Fast, Secure, And Reliable Dedicated IP Solutions