This post is a continuation to my previous post on “[How to] Change DNS Server on Android phones?”. The earlier post was about changing the DNS Server when you are connected using WiFi. For a 3G connection, a different set of properties needs to be changed and the way we change them is also little different.
Method-1 [Manual]
- 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 command “getprop | grep dns” to know all the dns properties being used. This command requires BusyBox. Please install it if you have not done it earlier.
- ‘rmnet0’ is the interface name for the 3G connection. net.rmnet0.dns1 and net.rmnet0.dns2 are the properties to be changed to point to OpenDNS server. Since, these properties are changed after the connection is established, net.dns1 and net.dns2 also have to be changed.
- Execute these commands as root user: setprop net.rmnet0.dns1 208.67.222.222. setprop net.rmnet0.dns2 208.67.220.220. setprop net.dns1 208.67.222.222. setprop net.dns2 208.67.220.220
- Done. You can test if the settings are proper by visiting http://welcome.opendns.com. Remember, the settings will be applicable only for the current session.
Method-2 [Semi-Automated]
- If you don’t want to take the pain of connecting your device to laptop and then changing the settings, try out this method. It uses a wrapper script which executes on your phone.
- Download and install Scripting Layer for Android (SL4A). This has interpreters for executing your shell script (in fact, lots of other scripting languages also) from your phone.
- Download the wrapper script I have written from here. This wraps all the commands needed for changing the DNS server in a shell script.
- Move the script to /sdcard/sl4a/scripts/. (adb push change-dns.sh /sdcard/sl4a/scripts/.)
- For easy access, add the scripts folder to your home screen. Long press on the home screen > Folders > Scripts. Open the scripts folder and you should see the script (“change-dns.sh”) which you have copied in the above step. All the above steps are needed to be done just once.
- Click on the script to launch it. Grant the Super user permission when asked for. You just have to run this script whenever you are connecting to your mobile network.
If you know of any hook to fully-automate the process, please share it by commenting on this post.
-- Varun
Method 2 does not work for me.
ReplyDeleteI dowloaded and installed SL4a
I run it, I created script file inside it, named it change-dns.sh
I can run this script but no effort.
Jako,
ReplyDeleteIs your device rooted?? Root privileges are required for executing the script. Did you get any message to authorize the execution of the script?
Varun
No, it's not rooted (because method 1 told to root it, not method 2)
ReplyDeleteBut I understad that this is needed for method 2 too...
OK, but Universal Androot does not support my HTC Desire.
So I found workaround - I created VPN connection to my workplace so now my phone uses workplace DNS, not 3G ISP DNS any more. That's OK for me.
Yup, both the methods need root access.
ReplyDeleteVPN solution works. Cool.
Haven't tried on CDMA. Try out the same technique and let me know if this works. Thanks.
ReplyDeleteThanks Varun! Both methods worked on my galaxy pop.
ReplyDeleteI think the property names might be different for different phones. And for method 1, you can execute the commands directly from the phone if you have Terminal Emulator installed.
Work great for my galaxy tab using method 2
ReplyDeleteThank you
The free "Set DNS" from the market is handy.
ReplyDeleteIt autodetects changes in the network status and sets the DNS to configured values.
Using that with the local caching DNS server: 'dnsmasq' running on localhost with the 'all-servers' option.
Killer combination.