Sitemap
Linux Root Room

Linux Root Room

Bash programming on https://www.youtube.com/@linuxrootroom

Why is /etc/resolv.conf Configured to Use 127.0.0.53 on Linux

4 min readAug 18, 2024

--

The resolve.conf file can point to a local IP address like 127.0.0.53 because it is often used in systems that employ a local caching DNS resolver, such as systemd-resolved.

I wrote this article on my Tumblr page and I am republishing it here on Medium.

https://linuxadminhacks.tumblr.com/

Local Caching Resolver

The IP 127.0.0.53 refers to a local resolver that runs on your machine. This is commonly seen in systems using systemd-resolved, which provides a DNS resolver service that caches DNS queries, improving performance and reducing the load on external DNS servers.

In modern Linux systems, /etc/resolv.conf often points to 127.0.0.53 instead of a traditional DNS resolver IP address. This is because of a change in how DNS resolution is handled on Linux systems.

In the past, /etc/resolv.conf would typically contain the IP addresses of one or more DNS resolvers, usually provided by your ISP or network administrator. However, with the introduction of systemd and its systemd-resolved service, the way DNS resolution works has changed.

systemd-resolved is a local DNS resolver that runs on your system and acts as a caching DNS resolver. It listens on the loopback interface (127.0.0.53) and forwards DNS queries to upstream resolvers, such as those provided by your ISP or configured in /etc/resolv.conf.

When you look at /etc/resolv.conf, you’ll see that it points to 127.0.0.53, which is the IP address of the systemd-resolved service. This means that your system is using the local systemd-resolved service as its DNS resolver, rather than a traditional external DNS resolver.

Configuration in resolv.conf

When the system is configured to use systemd-resolved, the /etc/resolv.conf file is usually a symbolic link to the resolver configuration file created by systemd (often found at /run/systemd/resolve/stub-resolv.conf). In this configuration, 127.0.0.53 is set as the nameserver.

Press enter or click to view image in full size

For more information read this link on stackover flow

Here are some benefits of this approach

  1. Caching: systemd-resolved caches DNS responses, which can improve performance by reducing the number of DNS queries sent over the network.
  2. Local resolution: systemd-resolved can resolve local hostnames and IP addresses without needing to contact an external DNS resolver.
  3. Flexibility: systemd-resolved can be configured to use multiple upstream resolvers, including DNS over TLS (DoT) and DNS over HTTPS (DoH).

If you need to configure your system to use a specific DNS resolver, you can still do so by editing /etc/resolv.conf or using the resolvectl command. However, keep in mind that systemd-resolved will still be used as the local resolver, and your changes will be forwarded to the upstream resolvers.

Is the DNS setting in /etc/resolv.conf temporary?

In modern Linux systems that use systemd-resolved, the /etc/resolv.conf file is indeed temporary and dynamically generated.

Get Linux Root Room’s stories in your inbox

Join Medium for free to get updates from this writer.

When systemd-resolved is started, it generates a temporary /etc/resolv.conf file that points to the local resolver at 127.0.0.53. This file is usually a symbolic link to a file in the /run/systemd/resolve/ directory, which is a temporary file system that is recreated on each boot.

The contents of /etc/resolv.conf are generated based on the configuration of systemd-resolved, which can be influenced by various factors, such as:

  1. Network configuration: When you connect to a network, the network manager (e.g., NetworkManager) may provide DNS resolver information, which is then used to generate /etc/resolv.conf.
  2. systemd-resolved configuration: You can configure systemd-resolved using the resolvectl command or by editing the /etc/systemd/resolved.conf file.
  3. DNS settings: If you have manually configured DNS settings, such as DNS over TLS (DoT) or DNS over HTTPS (DoH), these settings will be reflected in /etc/resolv.conf.

Because /etc/resolv.conf is dynamically generated, any manual changes you make to this file will be lost when the system is restarted or when the network configuration changes. If you need to make persistent changes to your DNS configuration, you should use the resolvectl command or edit the /etc/systemd/resolved.conf file instead.

To illustrate this, you can try running the following command:

sudo resolvectl status

In the figure below, I have set my DNS settings to two famous Google DNS addresses, namely 8.8.8.8 and 8.8.4.4, which I have taught in the video at the end of this post.

Press enter or click to view image in full size

This will show you the current DNS configuration, including the contents of /etc/resolv.conf. If you then edit /etc/resolv.conf manually and run the command again, you’ll see that your changes have been lost.

So, to summarize: /etc/resolv.conf is a temporary file that is dynamically generated by systemd-resolved, and any manual changes to this file will not be persistent.

--

--