I'm running a Raspberry Pi and I'm trying to get Pi-hole working. I'm running the container from Podman from a newly created pi-hole user (non root). I published the ports as follows:
- 127.0.0.1:5053:53/tcp
- 127.0.0.1:5053:53/udp
- 127.0.0.1:8080:80
The web dashboard (port 80 in the container) is available on the host on port 8080 and I setup accessing it via Nginx: This is working perfectly already. I specifically make the 53 port available via port 5053 on the host because the pi-hole user can't bind to sub 1024 ports (non root). My plan is to configure ufw to forward packets from host port 53 to 127.0.0.1:5053 but I can't seem to get this setup working.
Currently I can resolve names from within the container and from the host using port 5053 but I get connection refused on the ufw forwarded port:
# Working
> podman exec pi-hole nslookup pi-hole.net 127.0.0.1
Server: 127.0.0.1
Address: 127.0.0.1#53
Non-authoritative answer:
Name: pi-hole.net
Address: 3.18.136.52
Working
> nslookup -port=5053 pi-hole.net 127.0.0.1
Server: 127.0.0.1
Address: 127.0.0.1#5053
Non-authoritative answer:
Name: pi-hole.net
Address: 3.18.136.52
Not working
> nslookup pi-hole.net 127.0.0.1
;; communications error to 127.0.0.1#53: connection refused
;; communications error to 127.0.0.1#53: connection refused
;; communications error to 127.0.0.1#53: connection refused
;; no servers could be reached
I setup ufw following this guide. I also whitelisted ports in ufw, see this output:
> sudo ufw status
Status: active
To Action From
22/tcp ALLOW Anywhere
443/tcp ALLOW Anywhere
53/udp ALLOW Anywhere
53/tcp ALLOW Anywhere
5053 ALLOW Anywhere
22/tcp (v6) ALLOW Anywhere (v6)
443/tcp (v6) ALLOW Anywhere (v6)
53/udp (v6) ALLOW Anywhere (v6)
53/tcp (v6) ALLOW Anywhere (v6)
5053 (v6) ALLOW Anywhere (v6)
I setup the nat rule in /etc/ufw/before.rules like this:
...
*nat
:PREROUTING ACCEPT [0:0]
-A PREROUTING -p tcp --dport 53 -j DNAT --to-destination 127.0.0.1:5053
-A PREROUTING -p udp --dport 53 -j DNAT --to-destination 127.0.0.1:5053
COMMIT
...
I also tried the following things:
- I made sure
net/ipv4/ip_forward=1is present in /etc/ufw/sysctl.conf. - I made sure
net.ipv4.ip_forward=1is present in /etc/sysctl.conf. - I made sure
DEFAULT_FORWARD_POLICY="ACCEPT"is present in /etc/default/ufw.