November 12, 20241 yr I wanted to avoid relying on Docker to run my Bind9 server, so I found a way to use the `dnsmasq` that `virsh` manages. This allows me to configure DNS in a more integrated way without Docker. I haven't tested if it survives reboots, but you can always add these changes to a userscript to run on boot. Without further ado... How to Set Up Wildcard DNS with `dnsmasq` I wanted `*.local.co` DNS requests to resolve to my server at `192.168.1.3` (replace with your relevant IP). Here’s how I configured it: 1. Edit the Network Configuration with `virsh` To configure `dnsmasq` to handle `*.local.co`, start by editing your `libvirt` network config: ```bash virsh net-edit default ``` 2. Add Custom `dnsmasq` Options Inside the `<network>` XML configuration, add the `dnsmasq:options` block with the wildcard DNS entry. Also, make sure to include the `dnsmasq` namespace declaration at the top of the `<network>` element: ```xml <network xmlns:dnsmasq="http://libvirt.org/schemas/network/dnsmasq/1.0"> ... some other stuff.... <dns> <forwarder addr='8.8.4.4'/> <forwarder addr='1.1.1.1'/> </dns> <dnsmasq:options> <dnsmasq:option value='address=/.local.co/192.168.1.3'/> <dnsmasq:option value='listen-address=192.168.1.3'/> <dnsmasq:option value='listen-address=192.168.122.1'/> </dnsmasq:options> </network> ``` - Namespace: The `xmlns:dnsmasq="http://libvirt.org/schemas/network/dnsmasq/1.0"` declaration tells `libvirt` to interpret the `dnsmasq` options correctly. - dns: to make sure you can point your router to the server and have other addresses resolved via another DNS - listen-address: make sure to have it listen to both the virtual address but also on the host ip address. You can check what the virtual address is by running `lsof -i :53 | grep dnsmasq` - dnsmasq:option: The `address=/.local.co/192.168.1.3` option resolves all `*.local.co` requests to `192.168.1.3`. 3. Restart the Network After saving the changes, restart the `default` network to apply them: ```bash virsh net-destroy default virsh net-start default ``` 4. Test Your Configuration Run a quick test to ensure the DNS resolution works as expected: ```bash nslookup test.local.co 192.168.1.3 ``` And that’s it! Now, `dnsmasq` on `virsh` should be configured to handle `*.local.co` requests. If it doesn’t persist through reboots, you can set up a userscript to reapply these settings at startup.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.