configuring Android 7.1 device to use local DNS server [closed]
I'm trying to get an Android device to use a DNS server on the LAN to resolve a server host name as a local address, but it is not working.
I have somehow tricked(*) the router into passing along the local IP address of the DNS server (192.168.1.99) when it hands out DHCP addresses. From a device running Windows 10 I see this is the case because when I look under networking properties I see it is using the primary and secondary DNS IP addresses I want, and it correctly resolves local servers to local addresses from world visible host names.
(*)Basically, the router wouldn't let me set the DNS servers, the radio box would not select. Inspecting the javascript allowed me to set a breakpoint so I could bypass the logic which apparently only allows the DNS server to be set if you have a static IP address which I don't have (and the radio box to set a static IP can't even be selected anyway!). When I submitted the form it appeared that the change did not take, yet some devices now get the proper DNS server! Update: I found a different router that didn't require any tricks to get it to pass the DNS servers when assigning DHCP addresses, but Android still doesn't use the DNS server it returns!
But on Android it does not work, it resolves the host name to the world visible IP address, suggesting it is not using the DNS server that DHCP is handing out. (And inexplicably, accessing servers via the external IP address stopped working, which was the whole reason for the need to get the host name to resolve to an internal address!)
I'm using Termux to try to troubleshoot the problem, and found that getprop net.dns1
and getprop net.dns2
returned IPv6 addresses, further digging showed these addresses in the router as DNS addresses provided by the ISP. So I figured maybe for some reason the trick I used on the router wasn't working on Android.
So I tried manually configuring the DNS server for the device. Using Settings -> WiFi -> (long press network name) -> Modify network -> IP settings: Static
I have entered the same identical network configuration as the device is obtaining via DHCP, e.g.
IP address: 192.168.1.2
Gateway: 192.16.8.1.1
Network prefix length: 24
DNS 1: 192.168.1.99
DNS 2: 8.8.8.8
But with this manual configuration I am unable to access anything at all on the LAN! For instance, I can't access the local router web page at 192.168.1.1, the browser says it is unreachable. I can't ping the same IP address in Termux, it says "Network is unreachable." If I run ifconfig wlan0
and route
in termux, the output looks identical to the output when I set IP settings to be configured via DHCP. However, getprop net.dns1
still returns the IPv6 address, so now I'm not sure I trust that command is return valid data. Update: Ok, there are actually four DNS addresses: the first two are IPv6 addresses from my ISP which are somehow leaking through, and the last two are the two IPv4 addresses I've set.
This seems to be specific to newer Android versions, an older Android 4.3 device is having no issues (it doesn't even need a static IP configuration to properly resolve host names).
What other things can I try to troubleshoot this problem, and get DNS working properly?
Update: I found this post which refers to a case where:
- There are two DNS servers, a local IPv4 one (192.168.1.230) and an ISP IPv6 one (2a01:e00::1)
- The IPv4 DNS server knows about the local domain, the IPv6 one doesn't.
- Android happens to use the IPv6 DNS server, and so can't resolve the hosts in the local network.
This matches what I am seeing with my configuration. But then the poster claims "This is working as designed" which I have issues with. It then lists four possible workarounds:
- Adding an IPv6 address to the local DNS server and configuring the router to announce that address as IPv6 DNS server, if possible. This won't work, because the router won't let me specify an IPv6 address for DNS.
- Configuring the local names on the router, if possible. I'm not sure what this means. The router itself doesn't provide any DNS capability
- Using a public domain so that the ISP router is able to resolve the internal names. I'm not sure what this means either - how would a public domain be able to refer to an internal IP address???
- Disabling IPv6 DNS (or disabling IPv6) on the router. The router does not provide any method for disabling or otherwise configure anything with regards to IPv6
So I'm still stuck with a system that is effectively DOA because some devices on the network can't see the resources they need in order to function.
Update: I set up a separate DHCP server and disabled the one on the router, but the Android device is STILL getting two IPv6 DNS servers in its list - it seems like there is a delay of a second or two after the DHCP server reported DNS servers appear before the IPv6 ones appear, and they always get inserted in front of the server reported addresses. I have tried bumping up the number of DNS servers reported to try to fill up whatever table Android might have, but even with 32 other DNS servers it still inserts two more at the beginning for a total of 34! How is Android getting these addresses, and how can I force it to knock it off?! This is driving me crazy!
Update: I found an app called "DNS Changer" which appears to fix the issue, although I have some doubts as to whether it can be more than a workaround until a real fix can be found. It appears to create a VPN of some kind, but I would like to know more how it works. Is it routing traffic outside my firewall? To where? I am wondering if it is routing everything out because a speed test to my own server yields about 20% of the average transfer rate compared to if I run the same test with the IP address instead of host name. I've used another app which is reporting about 7 distinct external host names and claiming that the whole transfer passed through each of them. Additionally, this workaround fails if the network goes down!
Update: I also see this issue in a rooted device running Android 5.1 ... I have set a static IP address and DNS pointing to the internal server and have even gone so far as to use setprop
to set every DNS server to the IP address of my internal DNS server... yet in termux when I use nslookup it still insists on using 8.8.8.8 to look up the name. How do I get Android to actually use the DNS server I specify?
Solution 1:
block all other outbound port 53 (DNS) traffic in the router except the DNS you want to use and the android device will use what you assign it in dhcp, seems to add them to the bottom of the list, so this will fail the others and use the ones you wanted, not sure why google did that