Wednesday 18 June 2014

How to change host file in an Android device?

Goal

In this post we will see how can we edit host file in an android device.

Prerequisites and Background

You must have a rooted device!! You cannot really alter system files if your device is not rooted. Next you need android SDK. Device of course and data cable. We will be using adb tool that comes with the SDK. You can go through my earlier post on What is Android Debug Bridge (adb)?  You can also go through some helpful posts like Android Partitions and Kernel Explained  and Android Partitions Basic. If you want to root your android device you can go through that post to : How to root your Android device?


Editing the host file

  1. Navigate to the window where you adb tool is located. That would be adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk\platform-tools.
  2. There open the terminal and type adb devices. You should see your device listed there. If you cannot see your device listed here try steps provided here Troubleshooting steps when Eclipse ADT does not recognizing your Android device and Troubleshooting steps when Android device is detected but not recognized by Eclipse ADT.

  3. Next pull the host file using the following command

    adb pull /system/etc/hosts ./



    You should get host file in the current directory.
  4. Change the host file as per the mapping you want.

  5. Push the file back to the device using following command.

    adb push hosts /system/etc/That should push your host file back to system/etc folder. And you are done. Your host file is successfully changed.
  6.  You can cross verify your changes by logging into adb shell and viewing the host file.

  7. For above step you will have to grant adb shell su privileges. It will prompt you on the device.

  8.  Finally you can test your changes by typing test.domain.com in your android browser.  You may have to restart your phone to refresh DNS cache. It wont load because there is no server running with that URL. If you map facebook.com to this URL even facebook will not load.


No comments:

Post a Comment

t> UA-39527780-1 back to top