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?

  • 1
    Related: android.stackexchange.com/a/71615/44325, though the command doesn't seem to work on Lollipop, but the app claimed to work on Lollipop. Perhaps you could give it a try. – Andrew T. Jun 22 '15 at 5:58
  • @AndrewT. I read the post you said before ask this question. Thanks all the same. The method is only for android 4.X, and author didn't open his code. I want to find a method not an app. P.S. Thank you for editing my question. – Gino Jun 22 '15 at 7:33
  • @Gino I'm the author of Override DNS and I updated the app to work on Lollipop, too. I've not found a way to get the netId value from the CLI. I'm getting it through a Java method. – MaxChinni Jun 25 '15 at 14:47
  • @Gino Did you try this: android.stackexchange.com/a/68866/112458 – Gokul NC Jan 5 '16 at 5:50
  • How to configure DNS properly? – Irfan Latif Dec 25 '19 at 22:16

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 ""

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

  • 1
    This is not working in my Lollipop device :/ BTW, what is dnsdomain ? – Gokul NC Jan 5 '16 at 5: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 5 '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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.