CompTIA Linux+ (XK0-006)System ManagementHard

A server's network connection is managed by NetworkManager. A technician manually edits /etc/resolv.conf to add 'nameserver 8.8.8.8', but after a reboot the change is lost and the original DNS server returns. Which command should the technician use instead to permanently set the DNS server for the connection named 'eth0'?

  1. Ahostnamectl set-hostname 8.8.8.8
  2. Bss -tulnp | grep dns
  3. Cecho "nameserver 8.8.8.8" >> /etc/hosts
  4. Dnmcli con mod eth0 ipv4.dns "8.8.8.8" && nmcli con up eth0
Show answer & explanation

Correct answer: D. nmcli con mod eth0 ipv4.dns "8.8.8.8" && nmcli con up eth0

When NetworkManager manages a connection, it regenerates /etc/resolv.conf on each reboot, overwriting manual edits, so DNS settings must be configured through nmcli against the connection profile and reactivated with 'nmcli con up' to persist. Editing /etc/hosts only maps static hostnames-to-IPs, hostnamectl sets the system's hostname, and ss only shows socket statistics.

Why the other options are wrong

  • A. Sets the system hostname string, unrelated to DNS resolution.
  • B. Displays listening sockets and processes, does not configure DNS.
  • C. /etc/hosts maps static hostname-to-IP entries, it is not used for DNS server configuration.

nmcli ipv4.dns

NetworkManager command to persistently set a DNS server on a connection profile, avoiding it being overwritten by NetworkManager-managed /etc/resolv.conf.

  • Manual /etc/resolv.conf edits get overwritten by NetworkManager
  • 'nmcli con mod <conn> ipv4.dns <ip>' sets DNS persistently
  • Requires 'nmcli con up <conn>' to apply the change

Memory trick: NetworkManager rewrites resolv.conf every boot — tell nmcli instead.

More System Management questions