
:root {
–text: #1f2933;
–muted: #52606d;
–bg: #ffffff;
–bg-alt: #f5f7fa;
–border: #e4e7eb;
–accent: #0b6bcb;
–accent-dark: #084f96;
–code-bg: #0f172a;
–code-header: #1e293b;
–code-text: #e2e8f0;
–code-comment: #7c8ba1;
–inline-code-bg: #eef2f7;
–inline-code-text: #c2255c;
–note-bg: #eaf4ff;
–note-border: #0b6bcb;
–warn-bg: #fff8e6;
–warn-border: #e8a400;
–ok: #18794e;
–fail: #c92a2a;
–radius: 8px;
–mono: “JetBrains Mono”, “Fira Code”, “SFMono-Regular”, Consolas, “Liberation Mono”, Menlo, monospace;
–sans: -apple-system, BlinkMacSystemFont, “Segoe UI”, Roboto, “Helvetica Neue”, Arial, sans-serif;
}
* { box-sizing: border-box; }
body {
margin: 0;
font-family: var(–sans);
font-size: 17px;
line-height: 1.7;
color: var(–text);
background: var(–bg);
}
.kb-article {
max-width: 880px;
margin: 0 auto;
padding: 48px 24px 80px;
}
h2 {
font-size: 2.1rem;
line-height: 1.25;
margin: 0 0 12px;
letter-spacing: -0.01em;
}
.kb-meta {
color: var(–muted);
font-size: 0.92rem;
margin-bottom: 32px;
padding-bottom: 20px;
border-bottom: 1px solid var(–border);
}
.kb-meta span + span::before { content: “·”; margin: 0 8px; }
h3 {
font-size: 1.5rem;
margin: 56px 0 16px;
padding-top: 8px;
scroll-margin-top: 20px;
}
h4 {
font-size: 1.15rem;
margin: 32px 0 10px;
scroll-margin-top: 20px;
}
p { margin: 0 0 16px; }
a { color: var(–accent); text-decoration: none; }
a:hover { color: var(–accent-dark); text-decoration: underline; }
ul, ol { padding-left: 24px; margin: 0 0 16px; }
li { margin-bottom: 6px; }
hr { border: 0; border-top: 1px solid var(–border); margin: 48px 0; }
/* Inline code */
code {
font-family: var(–mono);
font-size: 0.86em;
background: var(–inline-code-bg);
color: var(–inline-code-text);
padding: 2px 6px;
border-radius: 4px;
word-break: break-word;
}
/* Code blocks */
.code-block {
margin: 16px 0 24px;
border-radius: var(–radius);
overflow: hidden;
background: var(–code-bg);
box-shadow: 0 1px 3px rgba(15, 23, 42, 0.15);
}
.code-header {
display: flex;
justify-content: space-between;
align-items: center;
background: var(–code-header);
padding: 6px 12px 6px 16px;
font-family: var(–mono);
font-size: 0.75rem;
color: #94a3b8;
text-transform: uppercase;
letter-spacing: 0.06em;
}
.copy-btn {
font-family: var(–sans);
font-size: 0.75rem;
text-transform: none;
letter-spacing: 0;
background: transparent;
color: #cbd5e1;
border: 1px solid #334155;
border-radius: 5px;
padding: 3px 10px;
cursor: pointer;
transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.copy-btn:hover { background: #334155; color: #fff; }
.copy-btn.copied { border-color: #22c55e; color: #86efac; }
pre {
margin: 0;
padding: 16px 18px;
overflow-x: auto;
font-family: var(–mono);
font-size: 0.86rem;
line-height: 1.6;
color: var(–code-text);
tab-size: 2;
}
pre code {
background: none;
color: inherit;
padding: 0;
font-size: inherit;
word-break: normal;
}
pre .c { color: var(–code-comment); font-style: italic; }
pre .p { color: #38bdf8; user-select: none; }
/* Callouts */
.callout {
border-left: 4px solid var(–note-border);
background: var(–note-bg);
padding: 14px 18px;
border-radius: 0 var(–radius) var(–radius) 0;
margin: 20px 0 24px;
font-size: 0.95rem;
}
.callout p:last-child, .callout .code-block:last-child { margin-bottom: 0; }
.callout strong:first-child { display: inline-block; margin-right: 4px; }
.callout.warn { border-left-color: var(–warn-border); background: var(–warn-bg); }
See Also: Complete Identity and Access Management Deployment on Ubuntu VPS
/* Tables */
.table-wrap { overflow-x: auto; margin: 16px 0 24px; }
table {
width: 100%;
border-collapse: collapse;
font-size: 0.93rem;
}
th, td {
text-align: left;
padding: 10px 14px;
border-bottom: 1px solid var(–border);
vertical-align: top;
}
th {
background: var(–bg-alt);
font-weight: 600;
border-bottom: 2px solid var(–border);
}
tr:hover td { background: #fafbfc; }
/* TOC */
.toc {
background: var(–bg-alt);
border: 1px solid var(–border);
border-radius: var(–radius);
padding: 20px 24px;
margin: 0 0 32px;
}
.toc-title {
font-weight: 700;
font-size: 0.85rem;
text-transform: uppercase;
letter-spacing: 0.06em;
color: var(–muted);
margin-bottom: 10px;
}
.toc ol { margin: 0; columns: 2; column-gap: 32px; }
.toc li { break-inside: avoid; font-size: 0.95rem; }
@media (max-width: 640px) {
.toc ol { columns: 1; }
h2 { font-size: 1.7rem; }
body { font-size: 16px; }
}
.ok { color: var(–ok); font-weight: 600; }
.fail { color: var(–fail); font-weight: 600; }
.summary-list li { margin-bottom: 8px; }
.back-top {
display: inline-block;
font-size: 0.85rem;
margin-top: 8px;
}
This article provides a guide demonstrating how to resolve “Temporary Failure in Name Resolution” on Ubuntu VPS.
Overview
The error Temporary failure in name resolution means your server tried to turn a hostname (such as archive.ubuntu.com or google.com) into an IP address and got no answer. The error comes from the system resolver library (getaddrinfo() returning EAI_AGAIN). Common places you will see it:
ping: google.com: Temporary failure in name resolution
Err:1 http://archive.ubuntu.com/ubuntu noble InRelease Temporary failure resolving 'archive.ubuntu.com'
curl: (6) Could not resolve host: example.com
In most cases the network itself is working and only DNS is broken. The usual causes on an Ubuntu VPS are:
- A missing, broken, or overwritten
/etc/resolv.conf systemd-resolvedis stopped, failed, or has no upstream DNS servers- No nameservers are defined in Netplan, or cloud-init has overwritten them
- A firewall is blocking outbound port 53 (UDP/TCP)
- The upstream resolver is down or unreachable
- Clock drift is causing DNSSEC validation to fail
- On container-based VPS platforms (OpenVZ/Virtuozzo/LXC), the host node is managing DNS
Before you start: Some steps change network configuration. Make sure you can reach your VPS out-of-band (VNC, serial console, or the provider’s web console) in case an SSH session drops.
See Also: 🚀 How to Deploy OPNsense on a Rad Web Hosting VPS
Compare Ubuntu VPS Plans
How to Resolve “Temporary Failure in Name Resolution” on Ubuntu VPS
To resolve “Temporary Failure in Name Resolution” on Ubuntu VPS, follow the steps below:
-
Confirm It’s DNS and Not Network Connectivity
Ping a public IP address directly. This skips DNS completely:
ping -c 4 1.1.1.1
Then ping a hostname:
ping -c 4 google.com
Result Meaning IP works, hostname fails DNS problem. Continue with this guide. Both fail Network/routing problem. Check the interface, gateway, and provider network first. Both work The problem is intermittent or specific to one application (see Step 10). If the IP ping fails, check the interface and default route:
ip -br addr ip route show default
You should see an interface in the
UPstate with an IP assigned, plus adefault via <gateway>route. If either is missing, fix connectivity before touching DNS. -
Inspect
/etc/resolv.confls -l /etc/resolv.conf cat /etc/resolv.conf
On a standard Ubuntu install,
/etc/resolv.confis a symlink to the systemd-resolved stub file:/etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf
The contents should include:
nameserver 127.0.0.53 options edns0 trust-ad
127.0.0.53is the local systemd-resolved stub listener. It forwards queries to the real upstream DNS servers.Problems to look for:
- The file is missing or empty. The resolver has nothing to query.
- It’s a regular file instead of a symlink. Something (a script, a control panel, or a manual edit) has replaced it.
- It points to a nameserver that is no longer reachable, such as an old provider resolver.
- The symlink is broken (shown in red by
ls, orcatreports “No such file or directory”).
Restore the correct symlink
sudo ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
If the command fails with
Operation not permitted, the file may be marked immutable:lsattr /etc/resolv.conf
If the output includes an
iflag, remove it first:sudo chattr -i /etc/resolv.conf sudo ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
-
Check the systemd-resolved Service
systemctl status systemd-resolved
If it is inactive or failed, enable and start it:
sudo systemctl enable --now systemd-resolved
Then check which upstream DNS servers it is actually using:
resolvectl status
Look under your primary interface (for example
eth0,ens3, orenp1s0) for:Current DNS Server: 1.1.1.1 DNS Servers: 1.1.1.1 8.8.8.8Most common root cause: If no DNS servers are listed under the interface or in the
Globalsection, systemd-resolved has nowhere to forward queries. Fix it in Step 4 or Step 5.See Also: Deploy FreeIPA on VPS
Restart the service and flush its cache:
sudo systemctl restart systemd-resolved sudo resolvectl flush-caches
Test resolution through systemd-resolved directly:
resolvectl query google.com
Check for port 53 conflicts
If systemd-resolved fails to start, another service may already be bound to port 53 (common with dnsmasq, BIND, Unbound, Pi-hole, or AdGuard):
sudo ss -lntup | grep ':53 '
If another resolver is meant to handle DNS, point
/etc/resolv.confat it, or disable the systemd-resolved stub listener (see Step 5). Don’t let both compete for the port. -
Set DNS Servers Permanently with Netplan (Recommended)
On most VPS deployments, the network configuration lives in
/etc/netplan/. List the files:ls -l /etc/netplan/
Typical filenames include
50-cloud-init.yaml,01-netcfg.yaml, or00-installer-config.yaml.Edit the file:
sudo nano /etc/netplan/50-cloud-init.yaml
Example: static IP configuration
network: version: 2 ethernets: eth0: addresses: - 203.0.113.10/24 routes: - to: default via: 203.0.113.1 nameservers: addresses: - 1.1.1.1 - 8.8.8.8 - 2606:4700:4700::1111Example: DHCP with custom DNS (ignoring DHCP-provided DNS)
network: version: 2 ethernets: eth0: dhcp4: true dhcp4-overrides: use-dns: false nameservers: addresses: - 1.1.1.1 - 8.8.8.8Note: Replace
eth0with your real interface name fromip -br addr. YAML is indentation-sensitive, so use spaces, not tabs.Fix the file permissions (Netplan warns if the file is world-readable):
sudo chmod 600 /etc/netplan/*.yaml
Validate and apply safely:
sudo netplan generate sudo netplan try
netplan tryapplies the configuration and automatically rolls back after 120 seconds unless you press Enter to confirm. This keeps a bad config from locking you out of a remote VPS. Once you’ve confirmed SSH still works, accept it, or run:sudo netplan apply
Verify:
resolvectl status ping -c 4 google.com
Stop cloud-init from overwriting your changes
If the file is named
50-cloud-init.yaml, cloud-init may regenerate it on reboot and discard your edits. To stop cloud-init from managing networking:echo 'network: {config: disabled}' | sudo tee /etc/cloud/cloud.cfg.d/99-disable-network-config.cfgAfter this, your Netplan file is the authoritative source and survives reboots.
-
Set Global DNS in
resolved.conf(Alternative / Fallback)If you don’t want to touch Netplan, or you want global fallback resolvers that apply no matter what the interface config says, use a systemd-resolved drop-in:
sudo mkdir -p /etc/systemd/resolved.conf.d sudo nano /etc/systemd/resolved.conf.d/dns.conf
[Resolve] DNS=1.1.1.1 8.8.8.8 2606:4700:4700::1111 FallbackDNS=9.9.9.9 1.0.0.1
Apply:
sudo systemctl restart systemd-resolved resolvectl status
A drop-in file is better than editing
/etc/systemd/resolved.confdirectly, because package upgrades won’t overwrite it.Optional: disable the stub listener
If you’re running your own resolver on port 53, or an application can’t use
127.0.0.53(some older software and certain container setups), add:See Also: Deploy OWASP Amass on Debian VPS
DNSStubListener=no
Then point
/etc/resolv.confat the non-stub file, which lists the real upstream servers:sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf sudo systemctl restart systemd-resolved
-
Emergency Temporary Fix
If you need DNS working right now, for example to run
aptor download a package, write a nameserver straight into/etc/resolv.conf:sudo rm -f /etc/resolv.conf echo "nameserver 1.1.1.1" | sudo tee /etc/resolv.conf echo "nameserver 8.8.8.8" | sudo tee -a /etc/resolv.conf
-
Check Firewall Rules for Port 53
DNS uses UDP 53, and falls back to TCP 53 for large responses. If outbound traffic on port 53 is blocked, resolution fails even with a correct configuration.
UFW
sudo ufw status verbose
UFW allows outbound traffic by default. If the policy shows
deny (outgoing), explicitly allow DNS:sudo ufw allow out 53/udp sudo ufw allow out 53/tcp
iptables
sudo iptables -L OUTPUT -n -v --line-numbers
Look for
DROPorREJECTrules matchingdpt:53, or a defaultOUTPUTpolicy ofDROP. To allow DNS:sudo iptables -I OUTPUT -p udp --dport 53 -j ACCEPT sudo iptables -I OUTPUT -p tcp --dport 53 -j ACCEPT
Persist with
netfilter-persistent saveif you useiptables-persistent.nftables
sudo nft list ruleset | grep -i -E 'output|53'
Provider-level firewall
Check your hosting control panel for a cloud firewall or security group. These apply before traffic reaches the VPS and won’t show up in local rules.
Quick port-53 reachability test
This test bypasses the local resolver and queries an upstream server directly:
dig @1.1.1.1 google.com +short
If that works but
dig google.comdoesn’t, the problem is local (systemd-resolved orresolv.conf). If both fail, something is blocking port 53, or the network itself is down.Can’t install
dig?apt installneeds DNS to work. Use the temporary fix from Step 6 first, or test with tools that ship by default:getent hosts google.com resolvectl query google.com
Install
diglater withsudo apt install bind9-dnsutils(ordnsutilson older releases). -
Verify
/etc/nsswitch.confThe Name Service Switch decides the order in which the system checks sources for hostnames:
See Also: How to Migrate Your Website from A2 Hosting to Rad Web Hosting
grep '^hosts:' /etc/nsswitch.conf
Expected output on Ubuntu Server:
hosts: files dns
If
dnsis missing from the line, the system never queries DNS at all. Make sure the line contains at leastfiles dns. -
Fix Local Hostname Resolution (
/etc/hosts)A related error is:
sudo: unable to resolve host myvps: Temporary failure in name resolution
This means the server’s own hostname isn’t listed in
/etc/hosts. Check both:hostname cat /etc/hosts
Make sure
/etc/hostscontains:127.0.0.1 localhost 127.0.1.1 myvps.example.com myvps
Replace
myvpswith the output ofhostname. If you use an FQDN, list it first.On cloud images,
/etc/hostsmay be regenerated from a template. To make your changes stick, either setmanage_etc_hosts: falsein/etc/cloud/cloud.cfg, or edit/etc/cloud/templates/hosts.debian.tmplinstead. -
Less Common Causes
Clock drift breaking DNSSEC
If DNSSEC validation is enabled and the system clock is far off, signature validation fails and lookups return
SERVFAIL:timedatectl
If
System clock synchronized: no, or the time is clearly wrong:sudo timedatectl set-ntp true
Note: NTP sync by hostname also needs DNS. If DNS is completely down, set the time manually first (
sudo date -s "2026-12-02 12:00:00"), fix DNS, then enable NTP.To rule DNSSEC out while troubleshooting, add
DNSSEC=noto your resolved drop-in from Step 5 and restart systemd-resolved.IPv6-only or broken IPv6 resolvers
If the only configured resolvers are IPv6 addresses but the VPS has no working IPv6 route, every query times out. Check with:
ping -6 -c 3 2606:4700:4700::1111
If IPv6 doesn’t work, make sure at least one IPv4 resolver is configured.
Container-based VPS (OpenVZ / Virtuozzo / LXC)
On container virtualization,
/etc/resolv.confis often written by the host node and replaced on every container restart. Local Netplan or systemd-resolved changes may be ignored. In this case:- Set the DNS servers from your hosting control panel, which updates the container config.
- Or contact your provider to set the nameservers at the node level.
Check your virtualization type:
systemd-detect-virt
Output of
openvzorlxcconfirms a container.kvmmeans full virtualization, where Steps 1–9 apply normally.Docker containers can’t resolve
If the host resolves fine but containers fail, Docker may be copying
127.0.0.53into containers, where it isn’t reachable. Set explicit DNS for the Docker daemon:sudo nano /etc/docker/daemon.json
{ "dns": ["1.1.1.1", "8.8.8.8"] }sudo systemctl restart docker
Upstream resolver outage
If the configured resolvers are reachable but return nothing, the provider’s resolver may be down. Switch temporarily to a public resolver to confirm:
See Also: How to Install DNSControl on Ubuntu VPS to Manage PowerDNS
Provider IPv4 IPv6 Cloudflare 1.1.1.1,1.0.0.12606:4700:4700::1111Google 8.8.8.8,8.8.4.42001:4860:4860::8888Quad9 9.9.9.9,149.112.112.1122620:fe::feConfiguring resolvers from two different providers protects you against a single provider’s outage.
Troubleshooting Reference Table
| Symptom | Likely cause | Fix |
|---|---|---|
| IP ping works, hostname fails | DNS misconfiguration | Steps 2–5 |
/etc/resolv.conf missing or broken symlink | File deleted or overwritten | Step 2 |
resolvectl status shows no DNS servers | No nameservers in Netplan / DHCP | Step 4 or 5 |
systemd-resolved won’t start | Port 53 conflict | Step 3 |
| Fix works, then breaks after reboot | cloud-init or host node overwriting config | Step 4 (cloud-init) / Step 10 (containers) |
dig @1.1.1.1 fails too | Firewall blocking port 53, or no network | Steps 1, 7 |
sudo: unable to resolve host | Hostname missing from /etc/hosts | Step 9 |
SERVFAIL on valid domains | DNSSEC + clock drift | Step 10 |
| Host resolves, Docker containers don’t | Stub resolver unreachable from containers | Step 10 |
One-Shot Diagnostic Script
Save this as dns-diag.sh and run it with sudo bash dns-diag.sh to collect everything above in one pass:
#!/usr/bin/env bash
# dns-diag.sh - Diagnose "Temporary failure in name resolution" on Ubuntu
set -u
TEST_HOST="google.com"
TEST_IP="1.1.1.1"
hr() { printf '\n==== %s ====\n' "$1"; }
hr "Virtualization"
systemd-detect-virt 2>/dev/null || echo "unknown"
hr "Interfaces / default route"
ip -br addr
ip route show default || echo "NO DEFAULT ROUTE"
hr "Raw connectivity (${TEST_IP})"
if ping -c 2 -W 2 "$TEST_IP" >/dev/null 2>&1; then
echo "OK: network reachable"
else
echo "FAIL: cannot reach ${TEST_IP} - this is a network issue, not DNS"
fi
hr "/etc/resolv.conf"
ls -l /etc/resolv.conf
lsattr /etc/resolv.conf 2>/dev/null
cat /etc/resolv.conf 2>/dev/null || echo "MISSING or BROKEN SYMLINK"
hr "systemd-resolved"
systemctl is-active systemd-resolved
resolvectl status 2>/dev/null | grep -E 'Link|Current DNS|DNS Servers|DNSSEC'
hr "Port 53 listeners"
ss -lntup 2>/dev/null | grep ':53 ' || echo "none"
hr "nsswitch hosts line"
grep '^hosts:' /etc/nsswitch.conf
hr "Hostname / /etc/hosts"
echo "hostname: $(hostname)"
grep -E "127\.0\.1\.1|$(hostname)" /etc/hosts || echo "WARN: hostname not in /etc/hosts"
hr "Clock"
timedatectl | grep -E 'Local time|synchronized'
hr "Firewall"
command -v ufw >/dev/null && ufw status verbose | grep -E 'Status|Default'
iptables -S OUTPUT 2>/dev/null | grep -E 'DROP|REJECT|-P OUTPUT' || true
hr "Resolution tests"
echo -n "getent (system resolver): "
getent hosts "$TEST_HOST" >/dev/null && echo OK || echo FAIL
echo -n "resolvectl query: "
resolvectl query "$TEST_HOST" >/dev/null 2>&1 && echo OK || echo FAIL
if command -v dig >/dev/null; then
echo -n "dig @1.1.1.1 (direct): "
[ -n "$(dig +short +time=2 @1.1.1.1 "$TEST_HOST")" ] && echo OK || echo FAIL
fi Reading the results:
See Also: How to Install Pleroma on Ubuntu VPS (5 Minute Quick-Start Guide)
getentFAIL +dig @1.1.1.1OK: the local resolver config is the problem (Steps 2–5).- Both FAIL while the raw ping is OK: port 53 is blocked (Step 7).
- Raw ping FAIL: it’s a network issue, not DNS.
Summary
- Confirm the problem is DNS by pinging an IP and then a hostname.
- Restore
/etc/resolv.confas a symlink tostub-resolv.conf. - Make sure
systemd-resolvedis running and has upstream servers. - Define nameservers permanently in Netplan, and disable cloud-init network management if needed.
- Add global fallback DNS through a
resolved.conf.ddrop-in. - Verify the firewall allows outbound UDP/TCP 53.
- Check
/etc/hosts,nsswitch.conf, clock sync, and container/Docker cases.
For most VPS instances, the fix is Step 4 (nameservers in Netplan) plus Step 2 (restoring the symlink).
Conclusion
You now know how to resolve “Temporary Failure in Name Resolution” on Ubuntu VPS.
Compare Ubuntu VPS Plans
(function () {
// Add header bar with language label + copy button to every code block
document.querySelectorAll(‘.code-block’).forEach(function (block) {
var lang = block.getAttribute(‘data-lang’) || ‘code’;
var header = document.createElement(‘div’);
header.className = ‘code-header’;
var label = document.createElement(‘span’);
label.textContent = lang;
var btn = document.createElement(‘button’);
btn.className = ‘copy-btn’;
btn.type = ‘button’;
btn.textContent = ‘Copy’;
btn.addEventListener(‘click’, function () {
var text = block.querySelector(‘code’).innerText;
var done = function () {
btn.textContent = ‘Copied’;
btn.classList.add(‘copied’);
setTimeout(function () {
btn.textContent = ‘Copy’;
btn.classList.remove(‘copied’);
}, 1600);
};
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(text).then(done).catch(fallback);
} else {
fallback();
}
function fallback() {
var ta = document.createElement(‘textarea’);
ta.value = text;
ta.style.position = ‘fixed’;
ta.style.opacity = ‘0’;
document.body.appendChild(ta);
ta.select();
try { document.execCommand(‘copy’); done(); } catch (e) {}
document.body.removeChild(ta);
}
});
header.appendChild(label);
header.appendChild(btn);
block.insertBefore(header, block.firstChild);
See Also: 6 Ways to Customize the VPS Panel With Your Branding – Cloud Admin Guide
// Dim full-line comments in bash/ini/yaml blocks
if ([‘bash’, ‘ini’, ‘yaml’].indexOf(lang) !== -1) {
var code = block.querySelector(‘code’);
code.innerHTML = code.innerHTML
.split(‘\n’)
.map(function (line) {
return /^\s*#/.test(line) ? ‘‘ + line + ‘‘ : line;
})
.join(‘\n’);
}
});
})();









