Restore outbound connectivity on a Linux VM that can reach its gateway but cannot reach the internet. Diagnose in order: addressing, local reachability, routing to public IPs, then DNS, and fix the missing default route and broken systemd-resolved configuration.
You SSH into a Linux VM (
net-ops-127
) after an app deploy. The node can reach the local gateway (
192.168.56.1
) but cannot reach the internet. Your job is to restore
outbound connectivity and ensure DNS works again.
Interface is
eth0
and the gateway should be
192.168.56.1
. Validate public IP reachability before chasing DNS, then
repair systemd-resolved using
resolvectl
with
1.1.1.1
and
8.8.8.8
.
eth0
.
resolvectl
to inspect and repair DNS server configuration.
ping 1.1.1.1
) before hostname tests.
default via ...
).
ip route add
.
resolvectl
.
getent hosts
.
eth0
.
ip -4 addr show eth0
You want a valid
inet
address and the expected prefix (for example
/24
) before you proceed.
ping -c 2 192.168.56.1
This confirms local L2/L3 connectivity. If this fails, fix the local network first (interface state, IP/subnet, L2 path, firewall).
ping -c 2 1.1.1.1
If this fails while the gateway ping succeeds, the problem is usually routing (often a missing default route) or an upstream policy/NAT issue.
ip route
You should see a line starting with
default via ...
. If it is missing, the host has no path to networks outside
its local subnet.
sudo ip route add default via 192.168.56.1 dev eth0
This restores routing immediately, but may not persist across reboot depending on how networking is managed (NetworkManager, systemd-networkd, distro config files). The incident goal is restore first, then make it persistent through the correct manager.
ip route
Confirm you now see
default via 192.168.56.1 dev eth0
.
ping -c 2 1.1.1.1
Public IP tests should work before you move on to DNS.
ping -c 1 example.com
If you see a name resolution error, DNS is misconfigured (or blocked) even though routing is now correct.
resolvectl status
Look at DNS servers assigned to
eth0
. In this lab, a bad resolver is configured and needs to be
replaced with known-good servers.
eth0
.
sudo resolvectl dns eth0 1.1.1.1 8.8.8.8
This updates link-scoped DNS configuration for
eth0
.
getent
.
getent hosts example.com
getent
confirms NSS resolution is working. This is a clean
validation step before you rely on application behavior.
ping -c 1 example.com
If this works, outbound connectivity is restored and DNS is functioning.
Check interface state, IP/prefix, and local path. Confirm
the correct interface name with
ip link
and verify subnet settings.
Upstream NAT may be missing, an egress firewall may block
ICMP, or the VM network may be isolated. In real systems,
validate the path with
traceroute
and review policy.
Confirm systemd-resolved is running, confirm the DNS servers
appear under the correct link, then retest with
resolvectl query example.com
. Also consider firewall rules for UDP/TCP 53.
ip route add
is runtime state. For persistence, set the default route in
the network manager used by the system.
This lab modifies runtime networking state. If you need to revert the changes, remove the default route and restore the prior link-scoped DNS configuration.
sudo ip route del default via 192.168.56.1 dev eth0
sudo resolvectl revert eth0
ip route
resolvectl status
The default route and DNS configuration reflect the intended state, and your reachability tests match expectations for the environment.
ip -4 addr show <if>
: Confirms IPv4 address and prefix on an interface.
-4
: Limits output to IPv4 addresses.
ip route
: Displays the routing table (including the default route).
ip route add default via <gw> dev <if>
: Adds a default route for outbound traffic.
default
: Route used when no more specific route matches.
via <gw>
: Sets the next-hop gateway.
dev <if>
: Sets the egress interface.
ping -c <n> <target>
: Tests reachability to an IP or hostname.
-c <n>
: Sends a fixed number of probes.
resolvectl status
: Shows systemd-resolved status and per-link DNS servers.
resolvectl dns <if> <dns1> <dns2>
: Sets DNS servers for a specific link.
dns
: Updates link-scoped DNS server assignment.
resolvectl revert <if>
: Reverts link-scoped resolver settings to the prior state.
getent hosts <name>
: Validates NSS hostname resolution for a target name.