• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Mods Cannot edit hosts file [Root only]

flemmo

Newbie
May 12, 2010
13
3
Hi folks,

I'm developing a new version of a live website in WordPress with domain mapping so that the URL is like-for-like with the live site. On a PC, I just change my host file to point to the WordPress IP address.

I now need to test the WordPress site on a phone.
I have an old HTC Desire with Android 2.3.4 (rooted) that I'm trying to use, so need to add the WordPress IP to the host file.

Using ADB, I've managed to retrieve the hosts file from the phone, edit it and place it back on the phone using:

Code:
adb remount
adb pull /system/etc/hosts /hosts 

[edited host file]
adb push /hosts /system/etc/hosts

To double-check that the hosts file really has updated, I've deleted hosts from my computer, then pulled it again from my phone. Opening it up in Notepad++ I can see that it does contain the new entry.

The strange thing is, if I open a web browser to www.mysite.com, it still goes to the live website, not the WordPress server. I've verified this using PingTools - the returned IP address is that of the live server.

I'm guessing I need to flush the DNS but it seems the only way to do this is a reboot. But upon reboot, the new entry in the hosts file is gone and we're back to only "127.0.0.1 localhost", so I'm now at a loss.

Any thoughts on where to go from here?
 
I've fixed the problem. For some reason, there needs to be a line feed after the last entry in the host file.
To do this, open the host file in Notepad++ and go the view menu > Show symbol > Show characters. Copy the LF character at the end of "127.0.0.1 localhost" and paste it to the end of each line if it doesn't already have the LF character at the end.

Android refreshes its DNS every 10 minutes, so it's then just a matter of waiting.
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones