Use at your peril, this kinda works but you will need to find a way to have systemd load this with the network, otherwise you'll have to manually start resolved and any other services that depend on name resolution. It's a gimicky trick at best.
I needed to run a simple dns server and didn't want to mess with bind, I was using dnsmasq but it broke when I upgraded ubuntu 24.04, it is a known bug (#2055012) but it doesn't look like they're going to address it anytime soon. I was able to find a work around with systemd-resolved. I want to be able to resolve for my own fake domain within my network (e.g. whatever.blah) - this was driven by some services and apps I was running behind haproxy which needs proper fqdn to work for me:
- /etc/hosts # normal etc hosts syntax
- /etc/haproxy/haproxy.conf # normal haproxy config using face domain name
- /etc/systemd/resolved.conf Make sure that these are not configured in the file already for anything else, by default they're commented out so I just added this block to the end of the file in the [Resolve] section.
DNSStubListener=yes # this causes resolved to listen on tcp/udp in the DNSStubListenerExtra configured ip.
DNSStubListenerExtra=192.168.1.2 # this is the private IP of the my home server
ReadEtcHosts=yes
Domains=igdy.io # this is equivalent to search domain
# these FallbackDNS are for cloudflare, google, and quad9 respectively
FallbackDNS=1.1.1.1 8.8.8.8 9.9.9.9 2606:4700:4700::1111 2606:4700:4700::1001 2001:4860:4860::8888 2001:4860:4860::8844 2620:fe::fe 2620:fe::9
- add the IP of the machine where you configured systemd-resolved to your home router DHCP configuration as the primary DNS server.
- update only one hosts file to serve your home network
- should work nicely with docker
I haven't run into any issues yet.