[GUIDE] How to Change DNS in Android Device (8 methods)

Search This thread

drummond

Member
Aug 6, 2010
5
1
Ottawa, Ontario
OP - Rooted Devices - Method 5 - it's right there, page 1.
There's an app too.
How much time can that waste?
(If it takes too long to go back one page, the OP is quoted just above your post)
:rolleyes:

It's unfortunate the discussion combines unrooted and rooted. Mine is unrooted. FYI I had read page 1 - Wartickler mentions 6.1.x problems and asks what version (no reply). syamsoul said "iptables" works on 6.0.1 - and he didn't reply to my query.
It's also unfortunate that you thought criticism would help answer the question.
FYI the link to Universal Init.d is broken.
 
Last edited:

phanimitra vadlamani

Senior Member
Oct 26, 2016
51
3
Well....im running cm14.1 on my onyx and attempted to change my dns to google's with method 4...yep..i successfully changed those properties and checked whether they r applied or not too in the terminal by grep dns command....but the problem is....when i checked my dns server online...both my dns and reverse dns are not changed...i didn't restart my device...what to do?????????
 

Lusty Rugnuts

Senior Member
Apr 17, 2019
120
29
Here's a great solution... Nebulo DNS-over-HTTPS (DoH) / DNS-over-TLS (DoT).

I use the DoH option, with Quad9 (9.9.9.9) as the DNS server. You can add your own DNS server, if you want, but Quad9 is a non-profit, has no financial incentive to collect and sell your DNS queries, and the legal infrastructure in their locale prohibits doing so anyway. And they're fast.

DoH sends DNS queries out encrypted, over HTTPS, rather than unencrypted via port 53, so your DNS requests can't get hijacked and rerouted to another DNS server, and the network you're on can't see which DNS queries you're making.

Nebulo sets up a VPN server, just like other DNS changer apps, but the others just let you change your DNS servers, whereas Nebulo lets you change your DNS servers and encrypt your DNS queries. Another difference, most of the others are closed-source and have ads (and analytics or tracking), whereas Nebulo is FOSS, no ads, no tracking.
 

caovanthanh203

Senior Member
Mar 5, 2019
105
144
  • Like
Reactions: 64ashg
D

Deleted member 8106930

Guest
Please help me changing DNS permanently with init.d or anything which might help me..

Noob friendly instructions please, for init.d scripts and enabling methods..
 
D

Deleted member 8106930

Guest
I want to change my DNS permanently.
I created script but it's not helping.
Also where to put those scripts in device? I have installed magisk and flashed latest init.d injector.
other than that I'm using redmi note 4 resurrection remix rom 7.0.2 (android 9) and also installed riru core and edExposed.
Can you please check these scripts?

Script-1
Code:
#!/system/bin/sh

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

Script-2
Code:
#!/system/bin/sh
# File without file extension

#IP6TABLES=/system/bin/ip6tables
IPTABLES=/system/bin/iptables

# Maybe need to change $IPTABLES to iptables (if there are troubles applying them)
$IPTABLES -t nat -A OUTPUT -p tcp --dport 53 -j DNAT --to-destination 208.67.222.222:53
$IPTABLES -t nat -A OUTPUT -p udp --dport 53 -j DNAT --to-destination 208.67.222.222:53
 
Last edited by a moderator:

DiamondJohn

Recognized Contributor
Aug 31, 2013
7,382
7,395
Sydney
I want to change my DNS permanently.
I created script but it's not helping.
Also where to put those scripts in device? I have installed magisk and flashed latest init.d injector.
other than that I'm using redmi note 4 resurrection remix rom 7.0.2 (android 9) and also installed riru core and edExposed.
Can you please check these scripts?
...snip...
Firstly, if you have Magisk, then place your scripts in your service.d path; location of that is depending on version.

You may also wish to add logging to your script so that you know it has actually ran.

I am running Oreo, and I found that using the default service providers DNS, by-passed my ad blocking via host file mods.

I found the following worked. I added in a bunch of settings/values into my build prop. I tested it a while back, but it still seems to work for me, but it may also be ROM dependent. The script has a few includes, but should be pretty easy to workout from the naming. eg
Code:
bb=busybox;
https://del.dog/owunorigab.pl

Its not a script to simply drop in and it will work, I have a whole scripting environment set up over owning an android phone for 8 years, with all these includes and logging etc but the meat is there.
 

KZekai

Senior Member
Jan 28, 2020
52
11
Any idea where can I check default DNS settings on Redmi Note7 that runs Android 9? I've checked the default stuff in the OP post but there is no resolv.conf exist not 20-dns.conf and getprob has 0 mentions of DNS

I dont even want to change anything yet just to see defaults because I'm having some weird DNS info in Chrome that should not be there.
 

rodken

Senior Member
Jan 11, 2010
2,498
1,175

wxf26055

New member
Aug 9, 2018
1
0
system will hot restart

The iptables works, when I switch to a secondary sim card, the system will hot restart.
It seems like the following command
killall system_server

Happens on Mi Mix2s Android 10
 
Last edited:

Top Liked Posts

  • There are no posts matching your filters.
  • 86
    Here is a compilation of different ways to change/set the DNS Server in Android Devices

    In this thread, I'll be setting the DNS Servers to 8.8.88 & 8.8.4.4 (Google DNS).
    You can use any DNS server of your wish.

    FOR NON-ROOTED DEVICES:


    Method 1: (by changing WiFi Settings)

    Note: For some devices, this will work only if you can set a static IP.

    1. Go Settings->WiFi
    2. Long press the Network you're connected to, and tap 'Modify Network'.
    3. Check 'Advanced'. (may not be required in some phones)
    Switch the IP settings from DHCP to Static.
    Add required DNS servers to the entries for DNS 1 and DNS 2.
    4. Click 'Save'
    (Don't worry about the editing the IP address as the Android device may fill in the IP address it has acquired through DHCP.)

    attachment.php


    Method 2: (Easiest Method using app)

    You could just use any app like:
    1. Engelsiz : DNS Changer
    2. DNS Changer (NO ROOT)
    3. DNS Changer (no root 3G/WiFi)
    4. DNSet
    5. DNS Changer
    (or any other app in Play Store.)
    (Some apps may require root access)


    FOR ROOTED DEVICES:

    Easiest way:
    The best apps I would recommend to do this automatically are:
    1. Override DNS (Root)
    2. Set DNS
    3. DNS + DNSCrypt Manager
    4. DNS Forwarder

    Method 3: (by editing DNS config)

    1. Open the file 20-dns.conf from /etc/dhcpcd/dhcpcd-hooks/ using a Text Editor (I use ES File Explorer)
    2. Add this line to the beggining & reboot device:
    Code:
    new_domain_name_servers="8.8.8.8 8.8.4.4 $new_domain_name_servers"
    So, finally the script finally looks something like this:
    Code:
    ##THIS CAN VARY slightly FOR DIFFERENT ROM BUILDS
    # Set net.<iface>.dnsN properties that contain the
    # DNS server addresses given by the DHCP server.
    
    [B]new_domain_name_servers="[I]8.8.8.8[/I] [I]8.8.4.4[/I] $new_domain_name_servers"[/B]
    
    if [[ $interface == p2p* ]]
        then
        intf=p2p
        else
        intf=$interface
    fi
    
    set_dns_props()
    {
        case "${new_domain_name_servers}" in
        "")   return 0;;
        esac
    
        count=1
        for i in 1 2 3 4; do
            setprop dhcp.${intf}.dns${i} ""
        done
    
        count=1
        for dnsaddr in ${new_domain_name_servers}; do
            setprop dhcp.${intf}.dns${count} ${dnsaddr}
            count=$(($count + 1))
        done
    
        separator=" "
        if [ -z "$new_domain_name" ]; then
           separator=""
        else
            if [ -z "$new_domain_search" ]; then
                separator=""
            fi
        fi
        setprop dhcp.${interface}.domain "${new_domain_name}$separator${new_domain_search}"
    }
    
    unset_dns_props()
    {
        for i in 1 2 3 4; do
            setprop dhcp.${intf}.dns${i} ""
        done
    
        setprop dhcp.${interface}.domain ""
    }
    
    case "${reason}" in
    BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT)       set_dns_props;;
    EXPIRE|FAIL|IPV4LL|RELEASE|STOP)                unset_dns_props;;
    esac

    This is a permanent change. (& sets only for WiFi)
    Remove that added line to undo the changes.
    (Source: http://xdaforums.com/showpost.php?p=51650282&postcount=7 )


    Method 4: (by changing DNS properties using Terminal Emulator)

    Note: This may not work in Android 4.4 and above devices.

    1. Open Terminal Emulator and type:
    Code:
    getprop | grep dns
    attachment.php

    2. Note down all the properties related to dns1, dns2.
    These are the properties you need to set to change the DNS Server.
    Use the following commands in Terminal Emulator to set them (using setprop):
    Code:
    su
    setprop dhcp.wlan0.dns1 8.8.8.8
    setprop dhcp.wlan0.dns2 8.8.4.4
    setprop net.dns1 8.8.8.8
    setprop net.dns2 8.8.4.4
    Other optional properties for mobile networks (may vary with devices) (rmnet0 for 3G I guess)
    Code:
    setprop net.ppp0.dns1 8.8.8.8
    setprop net.ppp0.dns2 8.8.4.4
    setprop net.rmnet0.dns1 8.8.8.8
    setprop net.rmnet0.dns2 8.8.4.4
    setprop net.pdpbr1.dns1 8.8.8.8
    setprop net.pdpbr1.dns2 8.8.4.4
    Setting DNS for very older devices:
    Code:
    setprop ro.kernel.android.ndns 2
    setprop dhcp.eth0.dns1 8.8.8.8
    setprop dhcp.eth0.dns2 8.8.4.4
    (You may similarly set dns3 & dns4, but that's not necessary)

    These properties get reset to the original values upon reboot..
    So, to keep these changes permanent, add the required commands to init.d
    (Source: https://github.com/ukanth/afwall/wiki/DNS#changing-default-dns )


    Method 5: (by using iptables command)

    1. Open Terminal Emulator and type the following:
    Code:
    su
    iptables -t nat -A OUTPUT -p tcp --dport 53 -j DNAT --to-destination 8.8.8.8:53
    iptables -t nat -A OUTPUT -p udp --dport 53 -j DNAT --to-destination 8.8.8.8:53
    iptables -t nat -D OUTPUT -p tcp --dport 53 -j DNAT --to-destination 8.8.8.8:53 || true
    iptables -t nat -D OUTPUT -p udp --dport 53 -j DNAT --to-destination 8.8.8.8:53 || true
    iptables -t nat -I OUTPUT -p tcp --dport 53 -j DNAT --to-destination 8.8.8.8:53
    iptables -t nat -I OUTPUT -p udp --dport 53 -j DNAT --to-destination 8.8.8.8:53
    (you may also use this as AFWall+ Custom Script)

    For more detailed info and better understanding, click here.

    These properties get reset to the original values upon reboot..
    So, to keep these changes permanent, add the required commands to init.d


    Method 6: (by editing resolv.conf)

    Note:
    I think this method works only for old devices. Nothing wrong in trying :)

    1. Open resolv.conf from /system/etc/ using a Text Editor (I use ES File Explorer)
    (If there's no such file, create it and try.)
    2. Modify the nameservers in the file to your desired DNS servers.
    The file finally looks like this:
    Code:
    nameserver 8.8.8.8
    nameserver 8.8.4.4

    This change is permanent..
    So, it's better to backup the original resolv.conf before editing.
    (Source: https://butterflydroid.wordpress.com/2011/10/19/how-to-set-dns-server-on-android-phone/ )


    Method 7: (by using ndc resolver command)


    1. Open Terminal Emulator and type the following:
    Code:
    su
    ndc resolver flushif [SIZE="1"][I]## to flush old DNS servers[/I][/SIZE]
    ndc resolver flushdefaultif [SIZE="1"][I]## to flush resolver[/I][/SIZE]
    ndc resolver setifdns <iface> <domains> <dns1> <dns2> ... [SIZE="1"][I]## Add the new servers[/I][/SIZE]
    ndc resolver setdefaultif [SIZE="1"][I]## Set as the default device[/I][/SIZE]

    This may vary for different Android Versions, so check this also..

    These properties get reset to the original values upon reboot..
    So, to keep these changes permanent, add the required commands to init.d


    Method 8: (by using DNSCrypt command)


    Hit the 'Thanks!' button if you found this helpful.
    Leave a reply if you need any help :)
    Do leave a reply if any of these methods worked on your device...
    2
    @GokulNC

    How to change the DNS ADDRESS with help of creating dumpy VPN service without help of any application .

    With help of application -
    U list out in non - root app list
    Like
    https://play.google.com/store/apps/details?id=com.burakgon.dnschanger
    That app use dumpy vpn for dns change

    But
    why we app ??

    Please try to discover the configuration of vpn..
    2
    The article needs updating. It's unclear what methods work in Android 8 or 9.
    1
    please tell me how to add init.d. I don't know.:confused::confused:

    This might help:
    [GUIDE] How to use init.d scripts

    Or try this app: Universal Init.d
    1
    Great list...

    Now how about you tell us which versions of Android these work on?

    Since Android 6.1.x you can only change the DNS for tethered devices and nothing else. Everything else is ignored, no matter what you set or which app you use.