configuring Android 7.1 device to use local DNS server

5

3

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?

Michael

Posted 2016-12-26T19:49:38.387

Reputation: 2 242

2I have this same issue. Super frustrating. – g33kz0r – 2017-03-05T03:44:04.120

You might be able to solve the problem by disabling IPV6 on your Android device (I assume this requires its rooted, and issuing a command like echo 1 > /proc/sys/net/ipv6/conf/wlan/disable_ipv6" on startup (or something equivalent) – davidgo – 2017-06-09T07:15:34.233

Answers

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

JS168

Posted 2016-12-26T19:49:38.387

Reputation: 11

0

Since Android 6.1.x, you only can change the DNS for a tethered device and nothing else. Everything else gets ignored, no matter what you set, or which app you're use

from DNS problems.

(where Android 6.1.x, I think, is Android 6.0.x)

Gling

Posted 2016-12-26T19:49:38.387

Reputation: 1

0

Here is a solution that I found to work on Android 5.1. Refer to this article for more info [https://developer.mozilla.org/en-US/docs/Archive/B2G_OS/Developing_Firefox_OS/Customizing_DNS][1]

adb pull /system/etc/dhcpcd/dhcpcd-hooks/20-dns.conf 20-dns.conf

Change the lines 22-26 to what you need. On my device I deleted lines 22-26 and changed lines 17-20 to:

count=1
    for i in 1 2 3 4; do
        setprop dhcp.${intf}.dns${i} ""
    done

to

count=1
    for i in 1 2 3 4; do
        setprop dhcp.${intf}.dns${i} "192.168.7.8"
    done

Change that IP to whatever you need

After you changed the file unmount the system and overwrite the default file with the one you just changed:

adb shell shell mount -o rw,remount /system
adb push /yourpath/20_dns.conf /system/etc/dhcpcd/dhcpcd-hooks/20-dns.conf
adb shell chmod 644 /system/etc/dhcpcd/dhcpcd-hooks/20-dns.conf
adb shell mount -o ro,remount /system

I found that remounting might not be like it's here so run adb shell mount to see all the mount points and find the right one on your device

After remounting reboot. Check if it works by going into the device's shell through adb and run tcpdump udp port 53 to see the

iulisiio

Posted 2016-12-26T19:49:38.387

Reputation: 1

0

I am having the same issue. It is hard to believe that such a bug exists in Android and doesn't get fixed.

You can work around it by manually setting the DNS resolvers from the command line. The problem is that this requires root.

For instance

ncd resolve setifdns wlan0 8.8.8.8 4.4.4.4

I found DNSman to support this method so you don't have to type it every time you reboot or modify the partitions. It is an open source app available in F-Droid that requires root.

I hope it helps.

nachoparker

Posted 2016-12-26T19:49:38.387

Reputation: 131

The command is nds – Sourav Ghosh – 2018-08-18T05:14:52.637

Actually it's ndc... – Sam Protsenko – 2018-08-30T13:47:25.647

0

I found a working solution. This app https://play.google.com/store/apps/details?id=com.frostnerd.dnschanger that is "opensource" (only quoted) https://git.frostnerd.com/PublicAndroidApps/DnsChanger creates a VPN connection to the device to redirect all the DNS requests.

I do not like it to much because it is hosted on a in-house Gitlab where everything can be done and undone.

Looking on how to create adhoc openvpn tunnels to achieve the same.

Alex

Posted 2016-12-26T19:49:38.387

Reputation: 111

-2

  1. Open wireless modem setting by entering 192.168.1.1 on a browser address bar, or another IP if you has modified it.
  2. Disable IPv6 DHCP setting and change setting to eui 64

hooman

Posted 2016-12-26T19:49:38.387

Reputation: 1

2Welcome to Super User. Please explain how doing this will solve the OP's problem. – I say Reinstate Monica – 2017-07-21T16:56:59.447