2

Ok, this is a constantly asked question, how to change mobile network DNS. But in different Android version, you will get different method. So this is the reason I ask this.

I have already known a method for Android 4 and below. Now, I want to know how to change mobile network DNS on Android 5.0 Lollipop and up.

A clue:

ndc resolver setnetdns <netId> <domains> <dns1> <dns2>

Someone said I should use this command to change mobile network DNS in Lollipop and up, but what is netId? Where can I find this value? Could you give me an example?

I am not C/C++ programer, but I try to read relative source code, found netid will be transform to unsigned long type by strtoul function. So I guess netid should be a hexadecimal string. I try using netcfg output value, but it doesn't work.

Could you give me more explanation about this method? How to use it? Or is there any other effective method to change mobile network DNS in Lollipop and up?

Andrew T.
  • 15,988
  • 10
  • 74
  • 123
Gino
  • 121
  • 1
  • 4

1 Answers1

1

I don't use Lollipop on my phone anymore. However since your question is about Lollipop and up, and I use Marshmallow, I can confirm that:

ndc resolver setnetdns devname dnsdomain dns1 dns2

works. It appears that you do not need to know the network ID anymore in Marshmallow, and you only need the device name.

So for example:

ndc resolver setnetdns rndis0 "" 8.8.8.8 8.8.4.4

will set the DNS for the rndis0 interface to Google's public DNS servers.

Léo Lam
  • 313
  • 4
  • 11
  • 1
    This is not working in my Lollipop device :/ BTW, what is dnsdomain ? – Gokul NC Jan 05 '16 at 05:45
  • Ah, that's too bad. I guess they changed the code some time after Lollipop so you don't need to know the netId anymore, only the devname. Not completely sure, but I think dnsdomain is the search domain. For example if you have it set to "lan" and you type "my-home-pc", the system will try to resolve "my-home-pc.lan". – Léo Lam Jan 05 '16 at 20:02
  • 1
    @LéoLam are you sure you don't need the netId anymore? I've a Nexus 5 with Android 6.0.1 and it's not working for me. With the netId, no problem. I tried only on a Wi-Fi network, I'll do some further research. – MaxChinni Apr 29 '16 at 21:17
  • hmm, that's really weird. Are you running 6.0.1 stock or CM13? I'm currently using CM13, and it worked without netId when I last tried it (in January). Looking at the source code for 6.0.0, the second argument (the one just after setnetdns) is passed to stringToNetId, but I'm not familiar enough with the Android source code and C++ to tell what it does precisely. – Léo Lam Apr 29 '16 at 22:46