FORUMS
Remove All Ads from XDA

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

763 posts
Thanks Meter: 858
 
Post Reply Email Thread
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.)

Google DNS


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.

new_domain_name_servers="8.8.8.8 8.8.4.4 $new_domain_name_servers"

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/show...82&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
Terminal: getprop | grep dns
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/wik...ng-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...android-phone/ )


Method 7: (by using ndc resolver command)


1. Open Terminal Emulator and type the following:
Code:
su
ndc resolver flushif ## to flush old DNS servers
ndc resolver flushdefaultif ## to flush resolver
ndc resolver setifdns <iface> <domains> <dns1> <dns2> ... ## Add the new servers
ndc resolver setdefaultif ## Set as the default device
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...
Attached Thumbnails
Click image for larger version

Name:	getprop dns.png
Views:	4692
Size:	76.5 KB
ID:	3580970   Click image for larger version

Name:	Google DNS.jpg
Views:	4766
Size:	15.2 KB
ID:	3581709  
The Following 19 Users Say Thank You to GokulNC For This Useful Post: [ View ] Gift GokulNC Ad-Free
 
 
28th February 2016, 06:19 AM |#2  
Elanza_48's Avatar
Senior Member
Flag kolkata
Thanks Meter: 106
 
More
please tell me how to add init.d. I don't know.
28th February 2016, 02:31 PM |#3  
GokulNC's Avatar
OP Senior Member
Flag Chennai
Thanks Meter: 858
 
Donate to Me
More
Quote:
Originally Posted by rajarshi kundu

please tell me how to add init.d. I don't know.

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

Or try this app: Universal Init.d
13th September 2016, 09:45 PM |#4  
Junior Member
Thanks Meter: 0
 
More
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.
1st December 2016, 03:53 PM |#5  
Wartickler's Avatar
Senior Member
Flag Tallahassee, FL
Thanks Meter: 334
 
More
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.
15th December 2016, 03:21 AM |#6  
Junior Member
Thanks Meter: 1
 
More
Quote:
Originally Posted by Wartickler

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.

DNS + DNSCrypt Manager (root) worked for me in Android 7.1.1
9th April 2017, 07:27 AM |#7  
Junior Member
Thanks Meter: 0
 
More
Fast what is the fastest downloader for Android phone as cell phones and tablets also how do you use the DNS changer
Post Reply Subscribe to Thread

Tags
change dns, dns, dns settings, modify dns, set dns

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes