Is this a recent configuration change? Your debug log show significant activity from 21 clients in the previous 24 hours.
[2019-12-13 19:42:08.262 1280] Imported 341916 queries from the long-term database
[2019-12-13 19:42:08.262 1280] -> Total DNS queries: 341916
[2019-12-13 19:42:08.262 1280] -> Cached DNS queries: 306397
[2019-12-13 19:42:08.262 1280] -> Forwarded DNS queries: 26245
[2019-12-13 19:42:08.262 1280] -> Exactly blocked DNS queries: 9268
[2019-12-13 19:42:08.262 1280] -> Unknown DNS queries: 6
[2019-12-13 19:42:08.262 1280] -> Unique domains: 3172
[2019-12-13 19:42:08.262 1280] -> Unique clients: 21
[2019-12-13 19:42:08.262 1280] -> Known forward destinations: 1
From the PIv4 address of the Pi-Hole, it appears you are running an open resolver. The Pi-Hole host is on a different IP range than the IP for which Pi-Hole is configured.
*** [ DIAGNOSING ]: Networking
[✓] IPv4 address(es) bound to the ens3 interface:
10.0.0.27/24 does not match the IP found in /etc/pihole/setupVars.conf (https://discourse.pi-hole.net/t/use-ipv6-ula-addresses-for-pi-hole/2127)
10.0.0.12/24 does not match the IP found in /etc/pihole/setupVars.conf (https://discourse.pi-hole.net/t/use-ipv6-ula-addresses-for-pi-hole/2127)
If this is the case, you should secure this from external traffic.
Uhm van you perhaps send me a pm on how to secure it more without doing ip filtering ?
Let's get back on topic. How to get it working so I can see an ip instead of localhost for the nginx stream.
Thanks but that is for DNS over HTTPS. He uses a conf file for it but with TLS you will need to have a stream where that command isn't allowed like this:
I had the same issue, when running Pihole on a VPC, as there is proxy in between.
All my android clients were showing up as localhost
What you need is to make NGINX as transparent proxy, so it would forward the source IP to Pihole.
Following are the changes you need to make, in order to get this working.
This code is for Ubuntu 18.04 LTS. Please change syntax accordingly.
# =================================
# =================================
# Enabling NGINX Transparency Proxy
# https://www.nginx.com/blog/ip-transparency-direct-server-return-nginx-plus-transparent-proxy/
# =================================
# =================================
# Edit DNS-Over-TLS server block (e.g. /etc/nginx/streams/dns-over-tls)
# Replace upstream DNS IP with Server Interface IP on which pihole is listening
server [XXXX:XXXX::XXXX]:53; # For IPv6
server X.X.X.X:53; # For IPv4
# Add the NGINX Proxy Bind to your server block
proxy_bind $remote_addr transparent;
# =================================
# Run NGINX as Root, instead of www-data
sed -i 's/www-data/root/' /etc/nginx/nginx.conf
# =================================
# Add IPtables marking rules to tag DNS response packets
# You can use any number to tag the packets within kernal
# For IPv6
ip6tables -t mangle -A OUTPUT -p tcp --sport 53 -j MARK --set-xmark 7
# For IPv4
iptables -t mangle -A OUTPUT -p tcp --sport 53 -j MARK --set-xmark 7
# =================================
# Add IP rules to divert DNS response packets to NGINX
# We need this so NGINX can intercept the DNS response and send over TLS tunnel
# I used table 99, but you could use any number
# For IPv6
ip -6 rule add fwmark 7 lookup 99
ip -6 route add local ::/0 dev lo table 99
# For IPv4
ip rule add fwmark 7 lookup 99
ip route add local 0.0.0.0/0 dev lo table 99
# =================================
# Restart NGINX service
service nginx restart
# =================================
# Save IP6tables & IPtables rules
apt install iptables-persistent -y
ip6tables-save > /etc/iptables/rules.v6
iptables-save > /etc/iptables/rules.v4
# =================================
# Ignore localhost queries (Optional), as I don't care what my VPC is doing.
echo "IGNORE_LOCALHOST=yes" >> /etc/pihole/pihole-FTL.conf
service pihole-FTL restart
# =================================
It does work but 1 issue though. When I have my android phone connected via 4g it works fine. When I connect to my home router via wifi that has it DNS set to the pihole's public IP I get stream timeouts from nginx on my server:
2020/01/03 17:44:46 [error] 7235#7235: *1 upstream timed out (110: Connection timed out) while proxying connection, client: ******, server: 0.0.0.0:853, upstream: "10.0.0.27:53", bytes from/to client:390/0, bytes from/to upstream:0/0
It's hosted on a external free server in the cloud. And I had a typo in my iptables. Fail2ban was set incorrectly and banned everyone. That stuff is still new to me and you can fuck it up easily. Thanks for the help though!