Case 1: When the device is rooted
This is the simplest use case where we can pull the hosts file of the Android device onto our system and then after modifying it we can push it back to the device. Following ADB commands can be used to achieve this:
- adb devices # to see if the device is connected and responding properly.
Now pull the hosts file from your device to your system using the following command:
- adb pull /system/etc/hosts d:\test\hosts
"test" in the above command is a target folder on your windows machine where the hosts file would be downloaded. Open the saved host file and edit it in any text editor. Save the file. Now the final step would be to upload it back to the device.
- adb push d:\test\hosts /system/etc/ # d:\test is the location where the updated hosts file resides.
That's it. You are done, your hosts file has been updated successfully.
Case 2: When the device is not rooted
Changing the hosts file is not possible when the device is not rooted. So how to get away with this situation? The solution is to route your mobile device's traffic through a system that has the desired hosts file. Here are all the required steps:
Prerequisites: Fiddler or Charles must be installed on your system. These tools would help in setting up proxy on the system.
Steps:
- Set up the proxy on your system. Follow the steps mentioned here to configure proxy using Charles. Steps remain the same if Fiddler is used instead of Charles.
- Modify the host file on your system as per your need. Save the file.
- All set, the proxy has been set and the host file has been modified.
- Open the required URL in your mobile device and it will obey the rules defined in the host file of your system.
This comment has been removed by the author.
ReplyDelete