Introduction to resolvectl
I’ve seen DNS leaks compromise network privacy time and again, so I’m always on the lookout for ways to tighten up my DNS configuration. As a Linux user, you’re likely familiar with the importance of DNS resolution for accessing websites and services. resolvectl is a powerful tool that comes with systemd, and it’s been a game-changer for managing DNS resolution on my systems.
What is resolvectl?
resolvectl is a command-line utility that allows you to control and configure DNS resolution on your system. It’s part of the systemd suite, which is widely used on modern Linux distributions. With resolvectl, you can set DNS servers, query DNS records, and troubleshoot DNS issues - all from the comfort of your terminal.
Installing and Configuring resolvectl
Most modern Linux distributions come with systemd installed by default, so you likely already have resolvectl at your disposal. If you’re using a distribution that doesn’t use systemd, you may need to install it manually or use an alternative DNS management tool. Don’t bother with the latter, though - resolvectl is well worth the effort of setting up systemd.
To configure resolvectl, you’ll need to edit the /etc/systemd/resolved.conf file. This file controls the behavior of the systemd-resolved service, which manages DNS resolution on your system. I usually start with a simple configuration, setting my DNS servers to use a public DNS service like Cloudflare’s. For example:
[Resolve]
DNS=1.1.1.1 1.0.0.1
Once you’ve edited the file, you can restart the systemd-resolved service to apply the changes:
sudo systemctl restart systemd-resolved
This is where people usually get burned - forgetting to restart the service after making changes to the configuration file.
Using resolvectl to Fix DNS Leaks
DNS leaks can be a real problem, especially if you’re using a DHCP connection. Your system may be sending DNS queries to your ISP’s DNS servers instead of the ones you’ve configured. The real trick is to use resolvectl to set your DNS servers explicitly. You can use the status command to check your current DNS settings:
resolvectl status
This will show you your current DNS servers, as well as any other DNS-related settings. If you’re using a DHCP connection, you may see that your DNS servers are being overridden by your ISP’s DNS servers. To fix this, you can use the set-dns command to set your DNS servers explicitly:
resolvectl set-dns 1.1.1.1 1.0.0.1
In practice, this is usually enough to fix DNS leaks and ensure that your DNS queries are being sent to the right servers.
Troubleshooting DNS Issues with resolvectl
resolvectl also provides a number of troubleshooting tools to help you diagnose and fix DNS issues. For example, you can use the query command to test DNS resolution for a specific domain:
resolvectl query example.com
This will show you the DNS records for the example.com domain, including the IP addresses associated with the domain. You can also use the flush-caches command to flush your DNS cache, which can help resolve issues with stale or incorrect DNS records:
resolvectl flush-caches
Don’t underestimate the power of flushing your DNS cache - it’s often the simplest way to resolve DNS issues.
Security Considerations
When using resolvectl to configure your DNS settings, it’s essential to consider the security implications of your choices. Using a public DNS service like Cloudflare’s can provide additional security features, such as DNS-over-HTTPS (DoH) and DNS-over-TLS (DoT), which can help protect your DNS traffic from interception and eavesdropping. However, it’s also important to be aware of the potential risks of using a public DNS service, such as the possibility of DNS hijacking or manipulation. To mitigate these risks, you can use a combination of DNS services and configure your system to use multiple DNS servers, such as:
[Resolve]
DNS=1.1.1.1 1.0.0.1 8.8.8.8 8.8.4.4
This will set your DNS servers to use a combination of Cloudflare’s public DNS service and Google’s public DNS service, providing an additional layer of redundancy and security.
Additional Resources
If you’re interested in learning more about resolvectl and DNS configuration, you can check out the following resources:
- freedesktop.org: This website provides detailed documentation on
systemd-resolvedandresolvectl, including configuration options and troubleshooting tips. - github.com/systemd/systemd: This is the official GitHub repository for the systemd project, which includes the source code for
systemd-resolvedandresolvectl.
See also
- Troubleshooting Disk Usage Issues with btrfs Snapshots and systemd Timers
- Resolving Dependency Conflicts with apt-pin on Debian-Based Systems
- Using resolvectl to Debug Stubborn DNS Resolution Issues on Linux
- Using systemd-resolved to Tame DNS Lookup Surprises on Multi-Homed Linux Machines
- Recovering from a Botched Package Upgrade with apt and snapshotting