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

Search This thread

GokulNC

Senior Member
Jan 10, 2015
827
1,397
Chennai
github.com
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://forum.xda-developers.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...
 
Last edited:

hattricknz

New member
Sep 13, 2016
1
0
method1

great list tks. re method 1, in my experience you have to give an ip address as otherwise you can't save the settings, which then turns out you have to give the device a static ip at your router.
 

Wartickler

Senior Member
Nov 4, 2009
170
353
Tallahassee, FL
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.
 
  • Like
Reactions: drummond

tanfidzularus

Senior Member
Sep 24, 2013
122
9
Help please,
Do u guys think dns changer app still needed if dns already change through build prop( kernel adiutor)? Or mod app like fly on mod?

Feels like its redundant
 

vargapirot

Senior Member
Nov 15, 2015
160
19
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://forum.xda-developers.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...
I am trying to use method #3 but I dont have dhcpcd folder ... What to do? My device is rooted and in es manager root explore is checked...
 

Attachments

  • Screenshot_20180130-193403.jpg
    Screenshot_20180130-193403.jpg
    236.6 KB · Views: 985

bloede

New member
Feb 14, 2018
1
0
Nice guide, if you have a Raspberry Pi install Pi-Hole on it, then set your home ip as DNS server on your phone/tablet and you'll have have adblocker on your phone/tablet.:good::good:
 
Last edited:

Boolian

Senior Member
May 29, 2015
289
185
Glasgow
This thread has no other occurrence of "iptables" - would you mind including a reference.
I'm wasting far too much time reading solutions that don't work on CM13 - Android 6.0.1.
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:
 

Top Liked Posts

  • There are no posts matching your filters.
  • 78
    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://forum.xda-developers.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.
Our Apps
Get our official app!
The best way to access XDA on your phone
Nav Gestures
Add swipe gestures to any Android
One Handed Mode
Eases uses one hand with your phone