It seems to be forwarding the packets now, but yeah, they all seem to come from the router instead of the device in pihole logs. My pihole is on 192.168.1.2 and the router on 192.168.1.1/24
iptables-save -c | grep -i -e dnshi -e pi -e mac
:dnshijack - [0:0]
[6:360] -A dnshijack -j DNAT --to-destination 192.168.1.2
[0:0] -A postrouting_lan_rule -d 192.168.1.2/32 -p tcp -m tcp --dport 53 -m comment --comment "!fw3: DNS Pi-hole MASQUERADE" -j MASQUERADE
[6:360] -A postrouting_lan_rule -d 192.168.1.2/32 -p udp -m udp --dport 53 -m comment --comment "!fw3: DNS Pi-hole MASQUERADE" -j MASQUERADE
[60:4475] -A prerouting_lan_rule -p udp -m mac --mac-source 00:11:22:33:44:55 -m udp --dport 53 -j ACCEPT
[0:0] -A prerouting_lan_rule -p tcp -m mac --mac-source 00:11:22:33:44:55 -m tcp --dport 53 -j ACCEPT
[6:360] -A prerouting_lan_rule -p udp -m udp --dport 53 -j dnshijack
[0:0] -A prerouting_lan_rule -p tcp -m tcp --dport 53 -j dnshijack
[0:0] -A zone_wan_input -p icmp -m icmp --icmp-type 8 -m comment --comment "!fw3: Allow-Ping" -j ACCEPT
This is the result of the postrouting rule. If you don't add it they Pihole will reply directly to the lan host, which will reject it because it is waiting an answer from googledns, not the pihole.
One way to avoid that is to move the pihole to a different interface/network. Then you could omit the postrouting rule.
Will this retain the originating IP address (in pihole logs), and work "transparently", in the sense the devices think that 8.8.8.8 replied? Will I be able to do this through the UI?
When you remove the masquerading rule, Pi-hole will be able to see the client source IP.
If you want to see the original destination, enable firewall logging.
To redirect hardcoded DNS and see what devices have hardcoded DNS (PiHole shows the device instead of the router), I must
Setup the PiHole on a separate "LAN alias" (I'm sorry, is the snippet below the right way to set this up? Is it the same as a VLAN? Update: I don't think so, but do correct me if I'm wrong )
Use the above firewall rule, but remove the masquerade rule.
I want to know how this works, given I'm pretty new to this, and am still learning, what books would you suggest? A simple explanation of why the setup described here would be appreciated too!
I wouldn't suggest any particular book, just find some online documentation explaining iptables. The rest is combined networking knowledge and some experience with asymmetric routing.