工作,学习,生活,这里将会有一些记录. 备用域名:http://meisw.wdlinux.cn 注册 | 登陆

Android下修改hosts文件

由于某些原因,可能需要指定域名对应的IP地址。Android是基于Linux的系统,与Linux类似,通过hosts文件来设置。

在Android下,/etc是link到/system/etc的,我们需要修改/system/etc/hosts来实现。但是这个文件是只读,不能通过shell直接修改。可以通过连接到PC上使用adb来修改。步骤如下:

1、获得root权限:adb root

2、设置/system为可读写:adb remount

3、将hosts文件复制到PC:adb pull /system/etc/hosts <PC机上文件名>

4、修改PC机上文件

5、将PC机上文件复制到手机:adb push <PC机上文件名> /system/etc/hosts

如果要查看是否修改成功,可以在PC上执行adb shell,运行cat /system/etc/hosts;或者在手机上运行cat /system/etc/hosts。

在Android 1.6系统中,hosts文件格式有一点与PC机Linux不同:不能在一行中一个IP对应多个域名,比如:

127.0.0.1      host1.example.com host2.example.com host3.example.com

在大多PC机Linux系统是合法的,但不能在Android 1.6上起作用,需要拆成每个域名一行才能使用:

127.0.0.1      host1.example.com

127.0.0.1      host2.example.com

127.0.0.1      host3.example.com

 

« 上一篇 | 下一篇 »

Trackbacks

点击获得Trackback地址,Encode: UTF-8

发表评论

评论内容 (必填):