Wireguard can't access DNS server on host

So I just configured the wireguard image and I got it running. I can access all my local IP’s and stuff but there is one thing I can’t figure out.
The DNS won’t work if I set it to my hosts internal IP.
I have pretty much everything running in containers, from nginx, mariadb, pi-hole etc.
I use pi-hole as my internal DNS but if I make my wireguard client use my internal IP as DNS it wont work.
The thing is that I can access all nginx on the same IP and all other services that are running inside containers.

I can even specify it to use my routers DNS and it will work. But when I try to use the host IP (which looks up DNS just fine internally) it stops working. I just get a timeout.

I can’t figure out why the DNS won’t work if I use the host IP ( but it will work if I use any other DNS server, including my routers (

It would make more sense if I could access at all, but all other services work except DNS.

Does anyone have any clues to what could be wrong here?

My compose file below:

version: "2.1"
    image: linuxserver/wireguard
    container_name: wireguard
      - NET_ADMIN
      - SYS_MODULE
      - PUID=1000
      - PGID=1000
      - TZ=Europe/Stockholm
      - SERVERURL=wg.domain.com #optional
      - SERVERPORT=51820 #optional
      - PEERS=1 #optional
      - PEERDNS=auto #optional
      - INTERNAL_SUBNET= #optional
      - /etc/wireguard:/config
      - /lib/modules:/lib/modules
      - 51820:51820/udp
      - net.ipv4.conf.all.src_valid_mark=1
    restart: unless-stopped

Client config below:

PrivateKey = <private key here>
ListenPort = 51820
Address =

PublicKey = <public key here>
AllowedIPs =,, ::/1, 8000::/1
Endpoint = wg.domain.com:51820

Server config below:

Address =
ListenPort = 51820
PrivateKey = <private key here>
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -A FORWARD -o %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -D FORWARD -o %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE

PublicKey = <public key here>
AllowedIPs =

The reason I want to use pi-hole as DNS over wireguard is because I have local dns entries in pi-hole which points to my local IPs.

I’m confused about this part. What does the host ip have anything to do with this?

Is pihole running as a container on the host?

Is the wireguard host set up to use pihole as it’s dns? Because when you set dns to auto, it uses whatever dns the wireguard container and its host is set up to use.

Yes pi-hole is running as a container on the host, as are the other containers I mentioned.
Lets start with the wireguard container. If I set it to use for example the dns will work (from inside the container).
If I set it to use (the host) dns won’t work. If I do a dns query I just get a timeout.

Let’s say I have the wireguard container use, as it works, and I set the wireguard client (my computer) to the same, all DNS querys will work. If I change the client to I will get a timeout on evey DNS query.

From the client when connected to wireguard I can ping, I can reach it over http and https, mariadb, influxdb, mqtt etc. but Not DNS for some reason. I can even access pi-hole over the web ui but not anything that is going to port 53 for some weird reason.

I can’t really figure out why only DNS querys won’t work and everything else will.

ah I just installed dnsutils on the container so I could try out dig for troubleshooting.
This is what I got:

root@a520d6f73159:/# dig internal.domain.com @
;; reply from unexpected source:, expected
;; reply from unexpected source:, expected

If I set the wireguard container to use pi-holes container IP ( I get a correct DNS response.
I will look in to this tonight.

I found someone with the same problem regarding the DNS on stackoverflow

The issue is iptables UDP nat for DNS server. You’re querying the host IP while it’s the docker bridge network’s response.

To fix it is to either run the container with --net=host or use the container IP of the DNS container in resolv.conf

Is there another way to do this since using --net=host breaks access to internet (might be able to fix with iptables, I don’t know?) and the IP of the DNS container might change when I run up/down etc.