Wireguard with DNS in Docker
Summary
In this guide, I'll show you how I set up a Wireguard server and a DNS server on the same host in my HomeLab. Many users face issues using a local DNS server with Wireguard. I'll explain how to configure Wireguard to access local devices and use a local DNS server like AdGuard Home, with both running in Docker on the same machine.
Guide
For my HomeLab, I attempted to set up a WireGuard server and DNS server on the same host, but it was not working. While using a DNS server like 1.1.1.1
worked, my local DNS server at 192.168.x.x
did not. In this article, I will show you how to configure WireGuard to access all your local devices and use a local DNS server like AdGuard Home. The prerequisite is running both the DNS server and WireGuard server in Docker on the same machine. I use AdGuard Home for the DNS server and wg-easy for the WireGuard server, but this setup should work for any DNS server and WireGuard server.
Configuring the DNS Container
Before setting up WireGuard, we need to tweak the DNS server. Both the DNS container and WireGuard must be on the same Docker network. First, create a network with:
We use the subnet
172.22.0.0/16
here. This could be any subnet, but we need to set a subnet to assign an IPV4 address to our container.
Next, connect the DNS container to this network by defining the network in your docker-compose
file:
Then, add the following to your DNS service configuration:
Recreate your container with:
Configuring WireGuard
Now, set up the wg-easy container.
Create a new directory, like this:
Then, create a docker-compose.yaml
file with the following content:
Recreate your container with:
For information on configuring clients and more details, refer to the official documentation: https://github.com/wg-easy/wg-easy/blob/master/README.md.