25

(My phone is rooted and runs Android 5.1)

How can one change the DNS addresses of mobile data (and persistently, if possible) without the requirement of an app?

2
17

I did not find a way to reliably do it without an app.

I often use OpenDNS Family Shield, but sometimes it blocks me to visit some particular hacking site and then I need to quickly and easily change the DNS servers.

I used to use Set DNS but it stopped to work in Android 4.3 and further, so I created Override DNS, a new app which mimics Set DNS' behaviour, but it's updated to work even in Lollipop. It has some other nice feature like a PIN protection ad a Wi-Fi SSID filter, too.

The only way I can see to do it without an app is something like an iptables rule to redirect any traffic going to udp/53 to some other ip. A similar procedure is shown in a XDA thread.

I paste here the iptables rules for completeness (I did not tested them)

$IPTABLES -t nat -D OUTPUT -p tcp --dport 53 -j DNAT --to-destination 208.67.222.222:53 || true
$IPTABLES -t nat -D OUTPUT -p udp --dport 53 -j DNAT --to-destination 208.67.222.222:53 || true
$IPTABLES -t nat -I OUTPUT -p tcp --dport 53 -j DNAT --to-destination 208.67.222.222:53
$IPTABLES -t nat -I OUTPUT -p udp --dport 53 -j DNAT --to-destination 208.67.222.222:53

Everything directed from the Android device to any IP, port UDP and TCP 53 is redirected to 208.67.222.222 which is one of OpenDNS' DNS server.

These commands should be placed in a script which is run at every device boot. That functionality depends on your specific ROM. I don't know if something similar can be done in a stock ROM without using an app. Override DNS solves this problem, too.

3
  • I attempt to use these settings but I get "Bad IP Address" error. I am attempting to use the Google DNS 8.8.8.8 and 8.8.4.4
    – Kristopher
    Apr 5 '16 at 20:38
  • Many apps claim to give the same capability without root. Is there some "catch" to those apps? Apr 13 '18 at 14:48
  • @mac9416 I'm not aware of any particular behaviour related to those apps (they all create a faux local VPN), but the original question was about achieving it without any specific app, so I think we're going OT.
    – MaxChinni
    Apr 13 '18 at 21:43
9

Starting with Android 9 Pie it is possible to change DNS globally, provided they support TLS. Just go in

Settings → Network & internet → Advanced → Private DNS

5
  • 1
    I have Redmi Note 9 Pro Max running android 10. When I enter IP in Private DNS provider hostname, it disables save button as soon as I enter first character after 3rd dot. Is it that IPs are not allowed? I'm trying to enter 208.67.222.222 or 208.67.220.220
    – IsmailS
    Dec 1 '20 at 18:41
  • Is there any domain instead which points to these Open DNS IPs?
    – IsmailS
    Dec 1 '20 at 18:47
  • 1
    This does indeed work in 2021. For Cloudflare you need to add 1dot1dot1dot1.cloudflare-dns.com blog.cloudflare.com/…
    – Mint
    Aug 10 '21 at 2:19
  • 1
    @IsmailS : To get hostname for IP address you can use dig -x 208.67.222.222 or dnschecker.org/reverse-dns.php Oct 27 '21 at 9:40
  • Some network providers in some countries seem to block resolution of these private DNS servers so private DNS feature does not always work.
    – Asu
    Dec 25 '21 at 10:02
3

This info is from 2014. But it might still work. I am not in the position to test it at the moment, but since you are rooted. You could try adding the dns settings to the build.prop file and see if it sticks. Adding the following to the build.prop file should add google as your DNS server.

net.rmnet0.dns1=8.8.8.8
net.rmnet0.dns2=8.8.4.4
net.dns1=8.8.8.8
net.dns2=8.8.4.4

Taken from this post on the Nexus 5 forums over on XDA. That post can be found here. Item number 21 is the DNS settings.

1
  • I tried this for fun on my Lenovo P2 running Android 7.0 and it did not work Aug 6 '19 at 13:55
1

That's not possible without an app, it has to be with an app. Second, you need root access in able to change 1G/2G/3G/4G DNS.

4
  • "That's not possible without an app, it has to be with an app" -- any good reason?
    – Firelord
    Aug 2 '15 at 22:15
  • 2
    Cuz android does not support it by default so that's why you need a special app to mess with it
    – user119443
    Aug 2 '15 at 22:16
  • 3
    Android does support build.prop editing, you just need a file manager with root access.
    – Dan Brown
    Aug 3 '15 at 0:21
  • @DanB +1, Was about to comment on this saying that. See my answer for the build.prop method. If interested.
    – jer3my
    Aug 3 '15 at 0:26

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.