Domain Name System / Server is the one which takes care of translating the human readable domain names into machine understandable IP addresses. If you are not able to access a particular set of websites either from your laptop / phone, DNS server could be a reason for it. It happened to me recently that only few pages were getting loaded properly on my Nexus One. To fix the problem, one has to change the network configurations to use some of the popular DNS servers like Open DNS or Google’s public DNS. On Android phones, changing the DNS server is easy if you are using the static IP. You can do it from Settings > Wireless & network settings > Wi-Fi settings > Advanced (from menu) > check the ‘Use static IP’ option. After that, you will be able to change the DNS servers. However, when you are using dynamic IP (which will be the case most likely), the process is not straight forward. DNS server details will be taken from the DHCP server which assigns the IP.
Here are the steps to be followed to change the DNS servers:
- Your device should be rooted. Check out these instructions to root your device with a single-click.
- Download and install the latest Android SDK from here. This comes up with all the tools needed for development and testing of your application. Make sure the driver ‘ADB interface’ is installed on your machine. In most of the cases, the driver will be installed directly once you plug-in the device.
- Connect your Android device to your PC on debug mode. Enable USB debugging on your phone. Settings > Applications > Development > USB debugging.
- On your laptop, open a command prompt and enter “adb shell”.
- Use the commands “getprop dhcp.eth0.dns1” and “getprop dhcp.eth0.dns2” to know the DNS servers currently being used. There are applications like ‘ipconfig’ which will give you the same details.
- To change the DNS servers, use the command “setprop <property name>”. “setprop dhcp.eth0.dns1 208.67.222.222” “setprop dhcp.eth0.dns1 208.67.222.222”. This command has to be executed as root user.
- Remember, the above step will change the DNS servers only for the current session. You will have to repeat it when you are re-connecting to the network. Read through the next section to know about how to change the DNS server automatically when you re-connect to a network.
Changing the DNS servers automatically
- Android system chooses the DNS servers using the script located at “/system/etc/dhcpcd/dhcpcd-hooks/20-dns.conf”
- By default, /system partition is mounted as read-only. Need to re-mount the same in read-write mode. Follow the instructions here to do this.
- Take a backup of the script. Download the modified version of the script from here. The modified script has two additional lines which will override the DNS server changes. The modified script uses the Google’s public DNS.
- Changes will be applied after restarting the connection / device.
Update: To change the DNS server of 3G connection, check out this article.
-- Varun
It does only work on wifi. How can we change the dns on 3g/gprs connection?
ReplyDeleteI really like this. I learned about it from this Post on Android Enthusiast. I am trying to find a way to password protect or lock the OpenDNS settings in for content filtering and monitoring. This would be perfect for churches, businesses, un-trusting spouses peace-of-mind, and concerned parents. Do you think this could be possible? Is an app-based solution even pheasable?
ReplyDelete@Mike: There is no way of password protecting the OpenDNS settings. However, you can unroot your device after done with changing the desired DNS settings.
ReplyDeleteThere are no direct apps available in the market for content filtering. However, if you are using Verizon network, Verizon provides support for content filtering. Check this out -- http://parentalcontrolcenter.com/content-filtering-for-android-devices
Some other useful references for content filterings:
- Try out OpenDNS FamilyShield http://www.opendns.com/familyshield/
- Try out OpenDNSBasic https://www.opendns.com/dashboard
- Use AppBrain (http://www.appbrain.com/) instead of Android Market.
Root your device. Apply these settings and then Unroot it to lock these settings.
-- Varun
@Mike: You may want to try out this as well -- http://www.xda-developers.com/android/android-firewall-control-app-network-access/
ReplyDelete-- Varun
@cem Wrote a separate post on changing the DNS server of 3G conenction. Check it out here -- http://blog.varunkumar.me/2010/09/how-to-change-dns-server-of-3g.html
ReplyDeleteHope this helps.
-- Varun
Thanks. My home internet provider (Cablemás de Cuernavaca) has non-responding primary and secondary nameservers (the thrid DNS does work, but it seems my Android doesn't use it, although it sets de dhcp.eth0.dns3 property). Your post was very helpful, but somehow manually fixing the DNS's didn't solve my problem; the script did.I don't understand why. I have a backflip MB300 with android 2.1
ReplyDeleteI had to modify the script a bit for my two CyanogenMod devices, they must use a different interface for the wifi. This should work more generally:
ReplyDeleteset_dns_props()
{
case "${new_domain_name_servers}" in
"") return 0;;
esac
count=1
for i in 1 2 3 4; do
setprop dhcp.${interface}.dns${i} ""
done
count=1
for dnsaddr in ${new_domain_name_servers}; do
setprop dhcp.${interface}.dns${count} ${dnsaddr}
count=$(($count + 1))
done
setprop dhcp.${interface}.dns1 8.8.8.8
setprop dhcp.${interface}.dns2 8.8.8.4
}
unset_dns_props()
{
for i in 1 2 3 4; do
setprop dhcp.${interface}.dns${i} ""
done
}
case "${reason}" in
BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) set_dns_props;;
EXPIRE|FAIL|IPV4LL|RELEASE|STOP) unset_dns_props;;
esac
Will this work in my motorola defy +...? Its not rooted...and i'm using aircel net...
ReplyDeletedns2 is wrong, google dns are 8.8.8.8 and 8.8.4.4
ReplyDeletedns2 STILL seems to be wrong - there's no response from 8.8.8.4, and I have always used 8.8.4.4
ReplyDelete