Introduction to resolvectl
I’ve seen many Linux users struggle with DNS configuration and troubleshooting. Editing configuration files like /etc/resolv.conf or /etc/hosts can be a real pain, and it’s easy to make mistakes. That’s why I’m a big fan of resolvectl, a command-line utility provided by systemd. It’s made managing DNS settings a whole lot simpler. In this article, I’ll show you how to use resolvectl to simplify DNS configuration and troubleshooting on Linux.
Installing and Configuring resolvectl
Before we dive in, let’s make sure resolvectl is installed and configured on your system. Since it’s part of the systemd package, you likely already have it installed if you’re running a modern Linux distribution like Ubuntu, Debian, or Arch Linux. You can verify this by running:
resolvectl --version
If resolvectl is not installed, don’t bother with manual compilation - just install it using your package manager. On Debian-based systems, you can run:
sudo apt-get install systemd-resolved
On Arch Linux, use:
sudo pacman -S systemd-resolved
Basic Usage of resolvectl
The real trick is to use resolvectl to query and configure DNS settings in a straightforward way. To start, let’s use resolvectl to query the current DNS configuration:
resolvectl status
This command displays the current DNS settings, including the DNS servers, search domains, and DNSSEC validation status. In practice, this is a great way to get a quick overview of your DNS setup.
Configuring DNS Servers
To configure DNS servers using resolvectl, you can use the resolvectl dns command. For example, to set the DNS servers to Google’s public DNS servers, you can run:
resolvectl dns google 8.8.8.8 8.8.4.4
Just replace google with the name of your network interface. This is where people usually get burned - make sure you’re configuring the correct interface.
Configuring Search Domains
Search domains are used to resolve hostnames without fully qualified domain names (FQDNs). To configure search domains using resolvectl, you can use the resolvectl domain command. For example:
resolvectl domain example.com
This sets the search domain to example.com. I usually start with a simple example like this to test my configuration.
Troubleshooting DNS Issues
resolvectl also provides a powerful tool for troubleshooting DNS issues. To query a DNS server, you can use the resolvectl query command. For example:
resolvectl query example.com
This command queries the DNS server for the IP address of example.com. If you’re having DNS issues, this is a great way to isolate the problem.
Security Considerations
When configuring DNS settings, it’s essential to consider security. One important aspect is DNSSEC validation, which ensures that DNS responses are authentic and have not been tampered with. To enable DNSSEC validation using resolvectl, you can run:
resolvectl dnssec yes
This command enables DNSSEC validation for all DNS queries. Don’t bother with manual configuration files - resolvectl makes it easy to secure your DNS setup.
Additional Tips and Tricks
Here are some additional tips and tricks for using resolvectl:
- To clear the DNS cache, you can run
resolvectl flush-caches. - To display the DNS cache, you can run
resolvectl cache. - To configure DNS settings for a specific network interface, you can use the
resolvectl -ioption. For example:resolvectl -i eth0 dns 8.8.8.8.
For more information on resolvectl and its usage, you can refer to the systemd documentation.
See also
- Recovering from a Failed Boot with a Broken Initramfs: When Your Linux System Won't Start
- Taming sudo: Tricks for Restricting and Logging Administrative Access
- Using jq to Parse and Analyze Linux Log Files in Real Time
- Taming Noisy systemd Logs with Journalctl Filters and Log Level Adjustments
- Taming Shared Directory Chaos with Setgid and Sticky Bits