Bind names to IPs so hostnames resolve reliably across boots and network changes. 16.11.2025 | reading time: 3 min A hostname is only useful when the system can resolve it; this guide shows how to make name-to-IP mappings persistent on Linux so services, scripts and humans keep talking to the right machine. Hands-on Example Add a persistent local mapping by editing the hosts file and verify resolution; here is a minimal, repeatable session: ```bash sudo sh -c 'echo "10.0.0.50 web.internal" >> /etc/hosts' getent hosts web.internal 10.0.0.50 web.internal ping -c1 web.internal PING web.internal (10.0.0.50) 56(84) bytes of data. 64 bytes from 10.0.0.50: icmp_seq=1 ttl=64 time=0.123 ms ``` This writes the mapping to `/etc/hosts`, which the Name Service Switch consults before DNS on most systems, and the `getent` and `ping` calls demonstrate the mapping is used immediately. Why the hosts file often wins Resolution order is controlled by `/etc/nsswitch.conf`; if `hosts:` lists `files` first, `/etc/hosts` takes precedence over DNS; check with `grep "^hosts" /etc/nsswitch.conf` and inspect system resolvers like `systemd-resolved` which may run a local stub resolver at 127.0.0.53; if DHCP or NetworkManager alters resolver settings, prefer `/etc/hosts` for local overrides because it survives network updates. Troubles to watch and quick fixes Some environments cache lookups or use mDNS; if a change seem not to apply, restart or flush the relevant cache: ```bash sudo systemctl restart nscd || true sudo resolvectl flush-caches || sudo systemd-resolve --flush-caches getent hosts web.internal ``` Also remember containers and chroots have their own `/etc/hosts`, and mDNS names end in `.local` and are served by Avahi rather than the hosts file. Advanced options and alternatives For centralized control use an internal DNS server or DNS conditional forwarding; for ephemeral VMs use cloud-init or NM connection extras to write `/etc/hosts`; systemd provides drop-in configs and `hostnamectl` manages the system identity but not name-to-IP mappings, so choose the method that matches the scale and orchestration model. Final word and next steps A single line in `/etc/hosts` can prevent hours of debugging; practice the examples on a lab machine, then study NSS order, systemd-resolved and mDNS to cover edge cases — and consider formalizing skills with courses and certificates like CompTIA Linux+ or LPIC-1; bitsandbytes.academy offers intensive exam preparation to get there. Join Bits & Bytes Academy First class LINUX exam preparation. network infrastructure troubleshooting