android how to configure the host address

    For some reasons, it may be necessary to specify the IP address corresponding to the domain name. Android is a Linux-based system. Similar to Linux, it is set through the hosts file.

     Under Android, /etc is linked to /system/etc. We need to modify /system/etc/hosts to achieve this. But this file is read-only and cannot be directly modified by the shell. It can be modified by connecting to a PC and using adb. Proceed as follows:

1. Obtain root privileges: adb root

2. Set /system to be readable and writable: adb remount

3. Copy the hosts file to the PC: adb pull /system/etc/hosts <file name on the PC>

4. Modify the files on the PC

5. Copy the files on the PC to the mobile phone: adb push <file name on the PC> /system/etc/hosts

If you want to check whether the modification is successful, you can execute adb shell on the PC and run cat /system/etc/hosts; or run cat /system/etc/hosts on the mobile phone.

 

     The solution for the host not taking effect:

     When manually configuring the domain name, it may fail. The reason is that the hosts that have been modified on the Android system are restored to the original state due to the line break. i.e. only 127.0.0.1 localhost. Then enter the adb shell and use echo -e \\n >> /system/etc/hosts to add a newline to the hosts file. Again use echo 192.168.1.94 www.leadding.com >> /system/etc/hosts .
This completely solves the line break problem.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326693593&siteId=291194637