Quiz Entry - updated: 2026.07.14
How do you configure hostname and DNS resolution in Linux?
Set the hostname with hostnamectl set-hostname; name resolution is governed by /etc/hosts (local overrides), /etc/resolv.conf (DNS servers), and /etc/nsswitch.conf (lookup order).
Two related but separate things: the machine's own name, and how it resolves other names. hostnamectl manages the former (and writes it persistently). For resolution, three files cooperate — and /etc/nsswitch.conf decides their priority, which usually means "check /etc/hosts first, then ask DNS".
# View current hostname
hostnamectl
# Set static hostname
hostnamectl set-hostname server01.example.com
# Temporary hostname change
hostname newname
DNS resolution files:
| File | Purpose |
|---|---|
/etc/resolv.conf |
Current DNS servers (often managed by NetworkManager) |
/etc/hosts |
Local hostname-to-IP mappings |
/etc/nsswitch.conf |
Order of name resolution sources |
Example /etc/resolv.conf:
search example.com
nameserver 8.8.8.8
nameserver 8.8.4.4
Example /etc/hosts:
127.0.0.1 localhost
192.168.1.10 server01.example.com server01
Tip: NetworkManager overwrites /etc/resolv.conf - use nmcli con mod to set DNS permanently!