Configure hosts File in Android

Alright, today I would like to work a sample web site and browse it not only from my Android Emulator but also from my Android G1 device. Since I did not make the web site public yet, I need to play with "hosts" file in order to direct specific url to my specific intranet IP on Android browser.

The steps that I follow to accomplish my goal are provided below;

For Android Emulator;
1. From the terminal invoke the adb command with remount option otherwise you will get "failed to copy 'hosts' to '/system/etc/hosts': Read-only file system".

adb remount

2. In the terminal pull the default hosts file from /system/etc/hosts or /etc/hosts which is the symlink of the file not only for backup purpose but also to get the file to modify.

adb pull /system/etc/hosts /home/player/hostBackup/

3. Get a copy of the the hosts file in your computer and modify it according to your needs.

4. Now we can push the file directly to the emulator.

adb push /home/player/hostBackup/hosts /system/etc/

5. That's it, if you wish you can check it out from you shell.

adb -e shell
# cat /system/etc/hosts

For Android G1 physical device;
1. In the device scenario, you need to start root accessed adb.

adb root

2. After gaining the root access successfully, just follow the steps 1-5 in for emulator section.

This procedure is working on both Windows and Linux with Android SDK 1.5_r2, just change the file paths for Windows version and it's all done.

Happy coding...


Unknown said…
thnks for your information i done all the steps then seen the host file it was updated but from the android browser still i was not able to access virtual host which i created.????
sacoskun said…
Hello Rahul,

If you modified the correct hosts file, the browser should follow the directions in the hosts file. Make sure you are running the same instance of the emulator which you changed the hosts file of.

This comment has been removed by the author.
Anonymous said…
Same as Tushneem... ugh. This is annoying. And the "Terminal Emulator" app seems pretty much useless to me.
Unknown said…
This comment has been removed by the author.
Unknown said…
thanks for your information. i am using mac 10.6 and trying to follow mentioned instructions. i succesfully pulled the host file and edited according to need but while pushing back i am getting error
"failed to copy '/Users/Mac2/Desktop/hosts2' to '/system/etc/hosts': Out of memory".

how to resolve this issue??
sacoskun said…
Hello Rahul,

I haven't tested this on Mac but it works on both Linux and Windows.

Anonymous said…
I tested it on KUbuntu and also have problem with "'/system/etc/hosts': Out of memory".
Also tried to perform cat >> hosts after doing remount and device is full.
jackace said…
I am not sure if solution is required anymore, but the trick is use -partition-size 128 (or more) while launching emulator( you can also pass this parameter in eclipse as default parameter) and follow the above mentioned steps.
Android said…
Doctor Web releases its new anti-virus product for mobile devices Dr.Web for Android. While popularity of Android is growing steadily, the experience shows that a growing interest in a certain operating system comes along with the increasing number of malicious programs designed to infect it. The release of Dr.Web for Androlid is a logical step towards expanding the Dr.Web product line aiming to provide protection from cyber-threats for all popular operating systems including mobile platforms.
Generic Cialis said…

Nice post, I would like to request you to one more post about that ****

Keep it up
Unknown said…
Hello.I am sorry, but you forgot to say that need to change the IP address to in the hosts file.
I am thoroughly convinced in this said post. I am currently searching for ways in which I could enhance my knowledge in this said topic you have posted here. It does help me a lot knowing that you have shared this information here freely. I love the way the people here interact and shared their opinions too. I would love to track your future posts pertaining to the said topic we are able to read.
ゾフラン said…
Hi there,
Really nice job,There are many people searching about that now they will find enough sources by your tips.
Also looking forward for more tips about that
Anonymous said…
I did this and verified the hosts file is updated on my N1 - however, it doesn't seem to use the IP addresses of the hosts I have added to this file. Is there some trick to flush the DNS cache or how to get the new host IP addresses to resolve?
Unknown said…
the modify will be invalid when reboot the emulator, can this be resolved?
Anonymous said…
i done all the steps then seen the host file it was updated but from the android browser still i was not able to access virtual host which i created. I can check the host file entry by using Cat commant and it displays me updated host entry. Also i am using the same instance of android.
Thats a great post and i have been looking for this host file in adroid and how to configure it.
Seo Services said…
Nice post, I would like to request you to one more post about that

Popular posts from this blog

Space Character Problem on IE 6, 7, and 8

Does Netflix work on iOS 5 Beta 4?

AWS encryption chart (SSE-S3 vs SSE-KMS vs SSE-C)