Network
Linux Networking & DNS — interfaces, routes, and name resolution
Read a Linux host's network state with iproute2 — interfaces, routes, ARP — then follow a name through the modern resolver stack (nsswitch → /etc/hosts → systemd-resolved → /etc/resolv.conf) so you fix the right layer when it breaks.
Quick reference — reach for these first
ip -br addrOne line per interface: name, admin state (UP/DOWN), and IPv4/IPv6 addresses. The fast 'what am I?' view.ip routeThe main routing table. The 'default via GW dev DEV' line is your gateway; no default line = no off-subnet traffic.resolvectl statusPer-link DNS servers and search domains as systemd-resolved sees them — the real resolver config, not just /etc/resolv.conf.getent hosts HOSTResolves a name through nsswitch exactly as applications do (files + DNS). Empty output = resolution failed.ss -tulpnListening TCP/UDP sockets with the owning process. Confirms what is bound to which address:port.How a name resolves on modern Linux
Text equivalent: Left to right: an application calls getaddrinfo, which consults the hosts: line of /etc/nsswitch.conf. From there three sources are tried in order: files reads static entries in /etc/hosts; resolve (highlighted) asks systemd-resolved at the stub address 127.0.0.53 and is what resolvectl status inspects; dns reads nameserver lines from /etc/resolv.conf. Sources are tried in the listed order and the first that returns an address wins. getent hosts follows this whole chain, while dig skips straight to DNS.
Common tasks
Task · Command · What to check
| Task | Command | What to check |
|---|---|---|
| List interfaces + link state | ip -br link | State UP and flag LOWER_UP = carrier/cable present. DOWN = admin-down; NO-CARRIER = no link. |
| Show addresses per interface | ip -br addr | Expected IPv4/IPv6 on the right DEV. No inet line = interface has no address (DHCP failed or not configured). |
| Bring an interface up | sudo ip link set DEV up | Re-run ip -br link; state should flip to UP. (Not persistent across reboot.) |
| Show the routing table | ip route | A 'default via GW dev DEV' line exists, plus a directly-connected subnet route for your LAN. |
| Which route to a destination | ip route get 1.1.1.1 | Prints the chosen src address, gateway and dev. 'unreachable' = no matching route. |
| Show the ARP / neighbor table | ip neigh | MAC per on-link IP with a state: REACHABLE/STALE good; FAILED/INCOMPLETE = no L2 answer (wrong subnet or host down). |
| Resolve a name like an app does | getent hosts HOST | Returns IP + name via nsswitch. Empty/exit 2 = name resolution failed, even if the network is fine. |
| Query DNS directly (bypass nsswitch) | dig +short HOST | Asks the servers in /etc/resolv.conf. An answer here but not from getent points at /etc/hosts or nsswitch, not DNS. |
| Inspect the active resolver | resolvectl status | Each link lists its DNS Servers and search domain. Empty 'DNS Servers' = nothing to ask. |
| Check nsswitch resolution order | grep '^hosts:' /etc/nsswitch.conf | Typically 'files resolve [!UNAVAIL=return] dns' or 'files dns'. Sources are tried left to right. |
| See the nameserver file | cat /etc/resolv.conf | nameserver lines. '127.0.0.53' means queries go to the systemd-resolved stub, not straight to an upstream. |
| Show NetworkManager view of a link | nmcli dev show DEV | IP4.ADDRESS, IP4.GATEWAY, IP4.DNS and GENERAL.STATE in one place; good for 'is NM managing this?'. |
| List listening ports + process | ss -tulpn | Service is bound to 0.0.0.0/:: (all) vs 127.0.0.1 (local-only) on the port you expect. |
| Show firewall rules | sudo nft list ruleset # or: sudo ufw status | Confirms whether the port/chain is accepted or dropped before you blame the app. |
A host can ping by IP but not by name
DNS BREAK
ping -c1 1.1.1.1 && ping -c1 HOST
# 1.1.1.1: 1 received, 0% loss · ping: HOST: Name or service not knowngetent hosts HOST
# (no output, exit status 2 → resolution failed)resolvectl status
# Link 2 (eth0)
# DNS Servers: (none) ← nothing to querycat /etc/resolv.conf
# nameserver 127.0.0.53 (stub; resolved itself has no upstream)sudo resolvectl dns eth0 1.1.1.1 1.0.0.1
# (set per-link DNS; resolvectl status now shows DNS Servers: 1.1.1.1 1.0.0.1)getent hosts HOST && ping -c1 HOST
# 203.0.113.10 HOST → 1 received, 0% lossTroubleshooting — symptom → first check → next check
| Symptom | First check | Establishes | Next check |
|---|---|---|---|
| Can ping by IP, not by name | getent hosts HOST (returns nothing) | Connectivity is fine; name resolution is broken | Inspect resolvectl status / /etc/resolv.conf and point the link at a working DNS server |
| "connect: Network is unreachable" | ip route (no 'default via' line) | No default gateway, so off-subnet traffic has nowhere to go | sudo ip route add default via GW dev DEV (persist in NM/networkd) |
| "No route to host" | ip route get IP; ip neigh | Gateway/ARP not resolving or destination is off your subnet with no route | Check DEV is UP, netmask is right, and the gateway is on your subnet |
| DNS not resolving (SERVFAIL / timeout) | resolvectl query HOST; dig @SERVER HOST | Resolver unreachable or misconfigured vs the record genuinely missing | Set a reachable nameserver; verify the 127.0.0.53 stub (systemd-resolved) is running |
| /etc/resolv.conf keeps getting overwritten | ls -l /etc/resolv.conf | It's a symlink managed by systemd-resolved or NetworkManager | Edit resolved.conf or the NM connection — not the file; it is regenerated |
| Interface DOWN / has no IP | ip -br addr; ip -br link | NIC is admin-down, has no carrier, or DHCP never assigned an address | ip link set DEV up, then renew the lease via nmcli/networkd/dhclient |
| Name resolves and route exists | getent hosts HOST && ip route get IP | Resolution and L3 path are both healthy end-to-end | Record this as your baseline before the next change |
References
- ip(8) — iproute2 (addr, link, route, neigh)man7.org
- resolvectl / systemd-resolved manualfreedesktop.org
- nsswitch.conf(5) — name service switchman7.org
- resolv.conf(5) — resolver configurationman7.org
- nftables wiki — firewall ruleswiki.nftables.org
Modern Linux with iproute2 (ip, ss) and systemd (resolvectl, getent). Many desktops run NetworkManager (nmcli); servers may use systemd-networkd or ifupdown. Hosts without systemd-resolved edit /etc/resolv.conf directly instead of going through the 127.0.0.53 stub. nftables is the current firewall framework; iptables-nft and ufw are common front-ends. dig/host need dnsutils / bind-utils installed. HOST, DEV, GW, SERVER in CAPS are placeholders — substitute your own.