改变查看批改安卓手机的DNS

改变查看修改安卓手机的DNS

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.

getprop | grep dns - Listing the properties with dns

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.
OpenDNS test page SL4A scripts folder

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.

版权声明:本文为博主原创文章,未经博主允许不得转载。