How Resolv.conf Defines Nameservers in Linux

This article explains how the /etc/resolv.conf file configures Domain Name System (DNS) nameservers in the Linux operating system. It covers the core syntax, how the system resolver processes nameserver entries, the behavior of failover mechanisms, and the impact of modern network managers on this configuration file.

The Role of /etc/resolv.conf

In Linux, human-readable hostnames (such as example.com) are translated into IP addresses by a set of routines in the standard C library known as the resolver. The /etc/resolv.conf file acts as the central configuration file for this resolver, explicitly defining which DNS servers the operating system should query.

The nameserver Directive

The primary mechanism for specifying a DNS server is the nameserver directive followed by the IPv4 or IPv6 address of the target server:

nameserver 8.8.8.8
nameserver 1.1.1.1
nameserver 2001:4860:4860::8888

Each nameserver line tells the resolver where to send DNS queries. The resolver evaluates these entries based on strict rules:

Supporting Directives

While nameserver specifies the target IPs, additional directives alter how queries are routed to those servers:

Modern Implementations: Dynamic Management

In modern Linux distributions, /etc/resolv.conf is rarely edited by hand. Services such as NetworkManager, systemd-resolved, or DHCP clients dynamically generate this file based on active network interfaces.

When using systemd-resolved, /etc/resolv.conf is frequently a symbolic link pointing to /run/systemd/resolve/stub-resolv.conf. In this scenario, the file points to a local stub listener:

nameserver 127.0.0.53

In this architecture, the standard resolver sends queries to the local loopback address (127.0.0.53), and the systemd-resolved daemon takes over the responsibility of routing those queries to the actual upstream nameservers defined per network link.