
In this article, we will review how to change DNS settings using nmcli. In RHEL7 and CentOS7, modifying the ifcfg scripts or /etc/resolv.conf files directly
Improve Linux network performance by diagnosing and fixing slow DNS resolution. Learn step-by-step troubleshooting, CLI commands, and configuration fixes to speed up DNS lookups on any Linux distribution.
Slow DNS resolution can make even the fastest Linux system feel sluggish. When domain lookups stall, websites load slowly, package managers hang on “resolving,” and SSH hosts take too long to connect. Fortunately, DNS issues are usually easy to diagnose and fix once you understand where to look.
This guide walks through practical, verifiable steps to identify the root cause of slow DNS resolution on Linux and apply effective fixes. Whether you’re a new Linux user or an advanced administrator, this tutorial provides clear explanations, examples, and troubleshooting procedures that apply across major distributions.
DNS lookups involve multiple layers. A slowdown often occurs because one or more of the following is misconfigured or underperforming:
|
|
|
|
|
|
|
Identifying the correct point of failure saves time, so the next section explains how to run fast and accurate diagnostics.
Use the following workflow when troubleshooting.
🟡 Step 1: Check Current DNS Settings |
Run:
cat /etc/resolv.conf
You should see one or more nameserver entries. If the file points to:
|
|
|
Misconfigured files, duplicates, or unreachable DNS entries will cause delays.
🟡 Step 2: Test DNS Lookup Speed Directly |
Perform a raw lookup using dig:
dig google.com
Here’s a sample output:
; <<>> DiG 9.16.23-RH <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 13546
;; flags: qr rd ra; QUERY: 1, ANSWER: 6, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1232
; COOKIE: 25d604f1ee76980901000000691d459e6cef5c6b23188c06 (good)
;; QUESTION SECTION:
;google.com. IN A
;; ANSWER SECTION:
google.com. 300 IN A 142.251.167.100
google.com. 300 IN A 142.251.167.102
google.com. 300 IN A 142.251.167.113
google.com. 300 IN A 142.251.167.139
google.com. 300 IN A 142.251.167.101
google.com. 300 IN A 142.251.167.138
;; Query time: 8 msec
;; SERVER: 192.168.1.9#53(192.168.1.9)
;; WHEN: Tue Nov 18 23:20:46 EST 2025
;; MSG SIZE rcvd: 163
Focus on:
|
|
|
Typical response times should be <50 ms on wired connections and <100 ms on Wi-Fi. To test how long resolution takes from the command line itself:
time getent hosts google.com
If dig is fast but getent is slow, system libraries or NSS modules may be the culprit.
🟡 Step 3: Query Alternative DNS Servers to Compare |
If you suspect your DNS server is slow:
dig @1.1.1.1 google.com
dig @8.8.8.8 google.com
dig @9.9.9.9 google.com
If these return faster results, your default resolver may be overloaded or unreachable.
🟡 Step 4: Check Network Connectivity & MTU |
Test basic connectivity:
ping -c 4 1.1.1.1
ping -c 4 8.8.8.8
If pinging DNS servers is slow or inconsistent, your network—not DNS—is the root cause. Sometimes MTU problems cause DNS requests to fail silently. Check MTU:
ip link show
To test an MTU path:
ping -M do -s 1400 8.8.8.8
Reduce size if you get fragmentation errors.
🟡 Step 5: Identify Conflicts Between DNS Services |
Common Linux DNS managers include:
|
|
|
|
|
Simultaneous services can slow lookups. Check active listeners:
sudo lsof -i :53
If multiple services show up, you may have a conflict.
🟡 Step 6: Check for IPv6-Related Delays |
Some networks handle IPv6 poorly. Test DNS over IPv6:
dig AAAA google.com
If it is significantly slower than IPv4 queries, consider adjusting IPv6 settings.
| Symptom | Likely Cause | Quick Test | Possible Fix |
|---|---|---|---|
Slow dig queries | Slow upstream DNS | Query @1.1.1.1 | Change DNS server |
Slow browser/SSH but fast dig | NSS or caching issue | time getent hosts | Reset systemd-resolved |
| Delays only with VPN | DNS override conflict | Check /etc/resolv.conf after VPN | Modify VPN DNS settings |
| IPv6 delays | Bad IPv6 routing | dig AAAA | Disable or fix IPv6 |
| Intermittent timeouts | Network/MTU | ping -M do | Adjust MTU |
Once you identify the issue, apply the fix that matches your situation. Below are reliable remedies to common scenarios.
🛠️ Fix 1: Use Faster DNS Resolvers |
Many systems rely on slow ISP DNS servers. Replacing them with fast, secure alternatives can dramatically improve performance. Popular resolvers:
| Provider | IPv4 | IPv6 | Notes |
|---|---|---|---|
| Cloudflare | 1.1.1.1 / 1.0.0.1 | 2606:4700:4700::1111 | Fastest in most regions |
| Google DNS | 8.8.8.8 / 8.8.4.4 | 2001:4860:4860::8888 | Highly reliable |
| Quad9 | 9.9.9.9 | 2620:fe::fe | Security-focused |
🟡 Update DNS using NetworkManager |
nm-connection-editor
Set DNS under “IPv4 Settings” and “IPv6 Settings.” Or from CLI:
nmcli connection modify "Wired connection 1" ipv4.dns "1.1.1.1 8.8.8.8"
nmcli connection down "Wired connection 1" && nmcli connection up "Wired connection 1"
💡Tip: Always set multiple DNS servers for redundancy. |
🛠️ Fix 2: Rebuild or Regenerate /etc/resolv.conf |
If /etc/resolv.conf becomes corrupted, slow or failed lookups are common. Check whether it’s a symlink:
ls -l /etc/resolv.conf
🟡 If systemd-resolved manages it |
Regenerate:
sudo systemctl restart systemd-resolved
🟡 To temporarily create a manual resolv.conf |
sudo bash -c 'printf "nameserver 1.1.1.1\nnameserver 8.8.8.8\n" > /etc/resolv.conf'
This method should not be used long-term if your system uses a resolver manager.
🛠️ Fix 3: Clear and Reset Systemd-Resolved Cache |
Many modern Linux distributions use systemd-resolved for DNS caching and fallback logic. If the cache becomes stale or the service gets stuck, DNS queries slow down. Reset it:
sudo systemd-resolve --flush-caches
sudo systemctl restart systemd-resolved
Check status:
systemd-resolve --statistics
If restarts resolve the issue temporarily, consider switching to a different DNS service.
🛠️ Fix 4: Disable Unneeded DNS Services (dnsmasq, resolvconf, bind9) |
Conflicting DNS services cause slowdowns. To disable dnsmasq:
sudo systemctl stop dnsmasq
sudo systemctl disable dnsmasq
To disable resolvconf:
sudo systemctl disable resolvconf
To disable bind9 (if installed unintentionally):
sudo systemctl disable --now bind9
After disabling conflicting services, restart NetworkManager:
sudo systemctl restart NetworkManager
🛠️ Fix 5: Address IPv6 Timeouts |
Some networks respond slowly to IPv6 DNS queries. If AAA queries lag significantly, consider adjusting IPv6 settings.
🟡 Option A: Prefer IPv4 for DNS |
Add to /etc/gai.conf:
precedence ::ffff:0:0/96 100
This prioritizes IPv4 but keeps IPv6 enabled.
🟡 Option B: Temporarily disable IPv6 |
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1
To re-enable:
sudo sysctl -w net.ipv6.conf.all.disable_ipv6=0
Only disable IPv6 if you’re certain the network cannot handle it properly.
🛠️ Fix 6: Resolve VPN-Related DNS Slowdowns |
VPNs often override DNS settings with slow resolvers located far away.
🟡 Check active DNS after connecting |
cat /etc/resolv.conf
If VPN DNS is slow, try:
|
|
|
For OpenVPN:
sudo sed -i 's/^dhcp-option DNS/#dhcp-option DNS/' /etc/openvpn/*.conf
🛠️ Fix 7: Tune nsswitch.conf for Faster Resolution |
The Name Service Switch (NSS) configuration file influences how hostname lookups occur. Poor ordering leads to noticeable delays. View file:
cat /etc/nsswitch.conf
Typical default (good):
hosts: files dns myhostname
Problematic example:
hosts: mdns4_minimal [NOTFOUND=return] dns files myhostname
If mDNS causes delays, change to:
hosts: files dns myhostname
Apply changes:
sudo systemctl restart systemd-resolved
🛠️ Fix 8: Improve DNS Caching and Performance |
Linux systems vary in DNS caching behavior. If you experience repeated delays for the same domain names, you may benefit from a dedicated caching resolver like dnsmasq or unbound.
🟡 Example: Install and enable dnsmasq |
sudo apt install dnsmasq
sudo systemctl enable --now dnsmasq
Modify /etc/resolv.conf to point to localhost:
nameserver 127.0.0.1
This provides fast, local DNS caching.
🛠️ Fix 9: Resolve Firewall or Security Tool Interference |
Ensure port 53 is not being blocked. Check UFW:
sudo ufw status
Open DNS ports if needed:
sudo ufw allow out 53
sudo ufw allow in 53
For firewalld:
sudo firewall-cmd --add-service=dns --permanent
sudo firewall-cmd --reload
Security tools like Fail2Ban, SELinux, or AppArmor may also require rule adjustments in rare cases.
After applying changes, validate improvements:
🟡 Test repeated lookups (caching check) |
dig google.com
dig google.com
dig google.com
Second and third queries should be nearly instant (close to 0 ms) if caching is active.
🟡 Test application-level resolution |
time getent hosts github.com
🟡 Benchmark DNS servers |
Install and run dnsperf:
sudo apt install dnsperf
dnsperf -s 1.1.1.1 -d /usr/share/dnsperf/example_queries
🟡 Measure browser DNS performance |
Enable DNS timing in Firefox:
|
|
|
A noticeable improvement validates your configuration changes.
Following a few routine habits helps avoid future slowdowns:
|
|
|
|
|
|
|
These practices keep DNS stable across reboots, network switching, and complex workflows.
Slow DNS resolution on Linux can disrupt browsing, package updates, SSH access, and everyday workflows. Fortunately, most issues stem from a few predictable causes: slow upstream resolvers, conflicting services, IPv6 misconfiguration, or caching failures. By following a structured diagnostic approach—checking resolv.conf, running dig comparisons, identifying conflicts, and adjusting DNS settings—you can quickly restore fast and reliable name resolution.
Linux provides powerful tools for debugging DNS, and small adjustments such as using faster DNS servers or tuning nsswitch.conf can dramatically improve performance. Whether you’re optimizing a workstation or maintaining a server fleet, keeping DNS healthy ensures smoother, faster network operations.
Did you find this article helpful? Your feedback is invaluable to us! Feel free to share this post with those who may benefit, and let us know your thoughts in the comments section below.

In this article, we will review how to change DNS settings using nmcli. In RHEL7 and CentOS7, modifying the ifcfg scripts or /etc/resolv.conf files directly

Learn how to set up a local DNS server on CentOS 9 using BIND, with detailed instructions, CLI examples, and best practices for managing DNS

Learn how to set up VLANs using nmcli on RHEL 9 with this step-by-step guide. Includes CLI examples, troubleshooting tips, and best practices for configuring
