Using resolvectl to Diagnose and Resolve Stubborn DNS Issues on Linux

Introduction to resolvectl

I’ve seen my fair share of DNS issues on Linux, and one tool that’s always helped me resolve them is resolvectl. This command-line utility, part of the systemd suite, provides a comprehensive way to query and configure DNS settings on your system. In this article, I’ll share some practical examples of how to use resolvectl to diagnose and fix stubborn DNS issues.

Understanding DNS Resolution

Before diving into resolvectl, it’s essential to understand how DNS resolution works on Linux. The DNS (Domain Name System) is responsible for translating human-readable domain names into IP addresses that computers can understand. On Linux systems, DNS resolution is typically handled by a resolver, which queries DNS servers to resolve domain names. The resolver configuration is usually defined in /etc/resolv.conf, but with systemd, resolvectl offers a more integrated and dynamic way to manage DNS settings.

Basic Usage of resolvectl

To get started with resolvectl, I usually start with the status command to view the current DNS configuration:

resolvectl status

This command will display information about the current DNS servers, DNSSEC validation, and other resolver settings. Don’t bother with manually parsing /etc/resolv.conf - resolvectl status gives you a much clearer picture of your DNS setup.

Diagnosing DNS Issues

When encountering DNS issues, resolvectl provides several commands to help diagnose the problem. For example, you can use the query command to test DNS resolution for a specific domain:

resolvectl query example.com

This command will display the DNS records for the specified domain, including the IP addresses associated with it. The real trick is to use resolvectl query to test DNS resolution for a specific domain, rather than relying on external tools like dig or host.

Configuring DNS Settings

resolvectl also provides a way to configure DNS settings dynamically. For example, you can use the dns command to set the DNS servers for a specific interface:

resolvectl dns enp0s3 1.1.1.1 8.8.8.8

This command sets the DNS servers for the enp0s3 interface to 1.1.1.1 and 8.8.8.8. In practice, this can be a lot more convenient than editing /etc/resolv.conf manually.

DNS Over TLS (DoT) and DNS Over HTTPS (DoH)

In recent years, there’s been a growing interest in securing DNS traffic using protocols like DNS Over TLS (DoT) and DNS Over HTTPS (DoH). resolvectl supports both DoT and DoH, allowing you to configure secure DNS connections. To enable DoT, you can use the dns-over-tls command:

resolvectl dns-over-tls enp0s3 1.1.1.1

Similarly, to enable DoH, you can use the dns-over-https command:

resolvectl dns-over-https enp0s3 1.1.1.1

For more information on DoT and DoH, you can visit the systemd.io website, which provides detailed documentation on the subject.

Troubleshooting Tips

When troubleshooting DNS issues with resolvectl, it’s essential to keep in mind a few tips:

  • Always verify the DNS configuration using resolvectl status before making changes.
  • Use the query command to test DNS resolution for specific domains.
  • Check the system logs for any error messages related to DNS resolution.
  • Consider using tools like tcpdump or wireshark to capture and analyze DNS traffic. This is where people usually get burned - not checking the system logs or using the right tools to diagnose the issue.

Further Reading

If you’re interested in learning more about resolvectl and systemd, I recommend checking out the freedesktop.org website, which provides detailed documentation on systemd and its components, including resolvectl.


See also