Taming Split DNS Chaos with systemd-resolved and Local Hostname Resolution

Introduction to Split DNS Chaos

I’ve seen this go wrong when working with multiple networks or self-hosted services: split DNS configurations can become a real headache. Luckily, many Linux distributions have started adopting systemd-resolved as the default DNS resolver, which makes managing split DNS scenarios much simpler. In this article, I’ll walk you through how to use systemd-resolved for local hostname resolution and taming that split DNS chaos.

Understanding systemd-resolved

The real trick is understanding how systemd-resolved works. It’s a systemd component that provides DNS resolution and caching, and it can be configured to use multiple DNS servers and handle split DNS scenarios with ease. To check if systemd-resolved is enabled on your system, run the following command:

systemctl status systemd-resolved

If it’s not enabled, don’t bother with trying to start it manually - just use the following commands to start and enable it:

sudo systemctl start systemd-resolved
sudo systemctl enable systemd-resolved

Configuring Local Hostname Resolution

In practice, configuring local hostname resolution is pretty straightforward. You can create a hosts file in the /etc/ directory, which contains mappings of hostnames to IP addresses. For example, to resolve example.local to 192.168.1.100, add the following line to the /etc/hosts file:

192.168.1.100 example.local

Alternatively, you can use systemd-resolved to configure local hostname resolution by creating a hosts file in the /etc/systemd/resolved.conf.d/ directory. This is where people usually get burned, as the configuration can get messy if you’re not careful.

Handling Split DNS Scenarios

I usually start with a simple configuration when handling split DNS scenarios. You can configure systemd-resolved to use multiple DNS servers, which is useful when you need to use a local DNS server for certain domains and a public DNS server for all other domains. To do this, create a resolved.conf file in the /etc/systemd/ directory with the following contents:

[Resolve]
DNS=192.168.1.1 8.8.8.8
Domains=example.local

In this example, 192.168.1.1 is the local DNS server, and 8.8.8.8 is the public DNS server. The Domains parameter specifies that the local DNS server should be used for example.local. For more information on systemd-resolved configuration, I recommend checking out the systemd.io website.

Troubleshooting Tips

When troubleshooting DNS issues with systemd-resolved, the resolvectl command is your friend. You can use it to query the DNS resolver, which can help you figure out what’s going on. For example, to query the IP address of example.local, run the following command:

resolvectl query example.local

This command will display the IP address of example.local as resolved by systemd-resolved.


See also