LoginSignup
64
57

More than 5 years have passed since last update.

Android端末のhostsを書き換える方法

Posted at

サーバー載せ替え時の検証などでAndroidのhostsを書き換えたい時のメモです。adbを使える環境になってる前提で書きます。ちなみにiPhoneだと端末からできるんですけどね。。。

と言ってもやることは簡単で、hostsファイルをpullして書き換えて、pushするだけです。

1. hostsファイルを取ってくる

以下のコマンドで、hostsファイルをローカルに取ってきます。

$ adb pull /system/etc/hosts 任意のディレクトリ

何もいじってなければ、localhostだけが記述されているはずです。

127.0.0.1 localhost

2. hostsファイルに追記する

取ってきたhostsファイルに追記します。

127.0.0.1 localhost
0.0.0.0 任意のドメイン

3. hostsファイルを上書きしてpush

以下のコマンドで、書き換えたhostsファイルを上書きします。

$ adb push pullしたディレクトリ/hosts /system/etc/hosts

この時、以下のような書き込み権限のエラーが出るかもしれません。

failed to copy 'hosts' to '/system/etc/hosts': Read-only file system

管理者権限でマウントする必要があるので、以下のコマンドでマウントします。こちらのStackOverFlowを参考に。

$ adb shell
$ su
$ mount -o rw,remount -t yaffs2 /dev/block/mtdblock3 /system

マウントしたら、pushできるはずです。

64
57
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
64
57