jtp10181
Senior Member
I am guessing other people have this problem as well. I have setup PiHole or AdguardHome on a separate server and using the router as DHCP. The first issue is that the router will force the routers IP as the IPv6 DNS server over DHCP and there is no option to change it on the LAN side only. I prefer to leave the WAN DNS as auto configure so I can quickly revert to that if needed, and also so the router itself can always access DNS as soon as its online. I also want the clients to talk to the DNS directly and not through the router so that I get better stats and logging on the interface.
To solve that first issue I had used a dnsmasq.postconf to replace the [::] with the IPv6 address of the DNS server. This works but then the clients will make the request over IPv6 which makes it hard to keep track of who is who, especially when the hostnames are less reliable on IPv6 and many devices will use multiple IPv6 addresses.
I came up with an idea to replace [::] instead with a mapped IPv4 address in place of the IPv6. With this all the clients connect to the DNS over IPv4. They can still get AAAA records over IPv4, there is really no reason to use IPv6 internally inside my small home LAN. I think I want to make a small script (to share of course) that would automate this setting based on what is filled in on the GUI for the IPv4 DNS on the WAN page. A set it and forget it type of thing so I don't have to edit the script if anything changes. But before I work on it, is there any problem anyone can think of with doing this?
Here is the relevant parts of my final dnsmasq.conf looks like after my manual postconf right now.
Here is how it shows up on my windows PC (no idea why it always shows the IPv6 twice).
Well, no one said I was crazy for putting in the mapped IPv4 address so I made a little script to automate it based off the IPv4 settings. There might be a more elegant way to do this, but this is what I came up with. This could be put directly into the dnsmasq.postconf or into its own file and executed from the postconf
To solve that first issue I had used a dnsmasq.postconf to replace the [::] with the IPv6 address of the DNS server. This works but then the clients will make the request over IPv6 which makes it hard to keep track of who is who, especially when the hostnames are less reliable on IPv6 and many devices will use multiple IPv6 addresses.
I came up with an idea to replace [::] instead with a mapped IPv4 address in place of the IPv6. With this all the clients connect to the DNS over IPv4. They can still get AAAA records over IPv4, there is really no reason to use IPv6 internally inside my small home LAN. I think I want to make a small script (to share of course) that would automate this setting based on what is filled in on the GUI for the IPv4 DNS on the WAN page. A set it and forget it type of thing so I don't have to edit the script if anything changes. But before I work on it, is there any problem anyone can think of with doing this?
Here is the relevant parts of my final dnsmasq.conf looks like after my manual postconf right now.
Code:
dhcp-option=lan,6,192.168.1.8
dhcp-option=lan,option6:23,[::ffff:192.168.1.8]
Here is how it shows up on my windows PC (no idea why it always shows the IPv6 twice).
Well, no one said I was crazy for putting in the mapped IPv4 address so I made a little script to automate it based off the IPv4 settings. There might be a more elegant way to do this, but this is what I came up with. This could be put directly into the dnsmasq.postconf or into its own file and executed from the postconf
Bash:
#!/bin/sh
CONFIG=$1
source /usr/sbin/helper.sh
#Get IP list from LAN DHCP IPv4 DNS Config (cannot have more than 2 + router)
IPLIST=$( sed -nr 's/^dhcp-option=lan,6(,.+?)$/\1/p' $CONFIG )
IP1=$( echo "$IPLIST" | cut -d',' -f2 )
IP2=$( echo "$IPLIST" | cut -d',' -f3 )
IP3=$( echo "$IPLIST" | cut -d',' -f4 )
#Convert to mapped IPv6 format if not blank
[ -n "$IP1" ] && IP1=[::ffff:${IP1}]
[ -n "$IP2" ] && IP2=,[::ffff:${IP2}]
[ -n "$IP3" ] && IP3=,[::ffff:${IP3}]
#Join back to single string to inject into config
IPLIST=${IP1}${IP2}${IP3}
#Inject into config file
pc_replace "dhcp-option=lan,option6:23,[::]" "dhcp-option=lan,option6:23,${IPLIST}" $CONFIG
Last edited: