Android Enthusiasts Stack Exchange is a question and answer site for enthusiasts and power users of the Android operating system. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've remounted /sys as rw, added one entry to etc/hosts (e.g. and rebooted my device.

After rebooting, if I check etc/hosts, the entry is fine. If I ping, it pings the correct IP address I entered.

But, if I open a web browser (either stock or Dolphin), and browse to, it'll go to the IP address the DNS resolves to.

What's happening?

(My phone is a Nexus One, which is running the custom Cyanogen 7.1 ROM based on android 2.3.7)

On the app 'LAN Droid' I get the edited address (so just fine too. It seems like that it's only the browsers where it behaves wrongly.

share|improve this question

migrated from Jul 10 '12 at 17:59

This question came from our site for professional and enthusiast programmers.

Just curious: what if you do it the other way around, and set a well-know domain (or some advertisement site) to become localhost instead? Does it fail to load that then? And is it really such short domain name like used in your example? (Not-so-fun-fact: Internet Explorer stopped accepting cookies for two-letter domains. Of course, unrelated to your problem, but maybe short domain names have other odd limitations in some browsers? I guess not though.) – Arjan Jul 7 '12 at 9:53
can you do this - ls -l /etc/hosts, possibly permissions/ownership problem? – t0mm13b Jul 9 '12 at 18:17
@t0mm13b "-rw-r--r-- root root" – gcb Jul 18 '12 at 18:35
@t0mm13b you're spot on! In my case it was the permissions. chmod 644 /system/etc/hosts sorted it out – KalenGi Jan 22 '14 at 18:09

This sounds exactly like this, down to ping working but not the browser. His eventual solution is quoted below:

Stupid question, but are you editing the file on the handset or just pushing the file that you posted here? The one you posted is in dos format, so it has extra linefeed characters at the end of the line that could confuse a linux system.

I don't know what you used to modify it, but you might want to check what kind of linefeed/newline characters it's using.

share|improve this answer
edited with vi on the terminal emulator. tried to force ff=unix now and set list to see any DOS line break... even went ahead and run a regexp as if there was any DOS line break, nothing found. – gcb Jul 5 '12 at 18:14

Can you install strace and compare the output running strace on ping with strace on the browser to see why DNS lookups are being handled differently?

Are you sure there isn't persistent caching going on? What's the TTL on your domain records?

Android doesn't appear to use /etc/resolv.conf, but maybe there are some properties that control which apps use /etc/hosts and which go directly to DNS lookup.!topic/android-platform/K2Wr4WaEneI

share|improve this answer
good points. TTL is 1h, the default for the catch all rule i have. The g.groups thread is mostly about the decision of which nameserver to hit during DNS queries, this logic happens after the etc/hosts. i hope. Now i will run the strace (find out how to before) and report back. – gcb Jul 9 '12 at 17:58

If you are creating the hosts file on a windows machine, make sure each line is separated by an LF only (not [CR][LF], only [LF]). You can verify that and create a proper hosts files using notepad++.

share|improve this answer

Try adding, seeing that the browser automatically adds www, as far as I know.

(My school's site for some reason doesn't automatically add www when using a desktop web browser, while it does get added on my Android phone.)

share|improve this answer
not the case... in fact, was a bad choice, i'm adding something like I have control of the real and i can see in the server logs that the browser requested it as i typed exactly. – gcb Jun 24 '12 at 20:49
@gcb Hm, that is interesting. What happens if you try the Google Chrome Beta app? (I guess you meant Chrome on your desktop in your question) – Sijmen Schoon Jun 25 '12 at 11:01
don't have chrome beta installed, but tested on firefox android app now. same thing. it hits the original DNS target not the /system/etc/hosts one. – gcb Jun 29 '12 at 18:00
Adding www before the URI is a bug not a feature. and aren't the same just like and – Richard Borcsik Jul 10 '12 at 19:25
btw, i edited the question so that it's clearer that i'm already using www. i left it out before for simplicity, and created more confusion :) – gcb Jul 18 '12 at 18:36

Not sure if this helps but I had a problem of an ignored hosts file and it was solved by a guy on this thread - the answer is to put a blank new line at the end of the file.

share|improve this answer

I think you need to flush DNS on your Android check this question Android: Flush DNS, especially "go into settings -> applications -> Network Location -> Clear data."

share|improve this answer
don't even have this option on android 2.3.7. But the phone is with this change on etc/hosts for months now. and i reboot it frequently... i hope DNS is not cached for months for any reason. – gcb Jul 5 '12 at 18:09

My suspicion would be that the browser is configured to work through a proxy.

You might be able to tell using netstat -n or looking in the /proc/net/tcp (or better yet, /proc/#browser_pid#/net/tcp) what address it is actually connecting to. If that does not match your website's address its likely you are going through an intermediary.

share|improve this answer

I'd normally say (but this doesn't apply to you, alas):

Just try a reboot if changes go unnoticed because the Dalvik machine instance or the underlying system might have cached a former DNS request.

You could try AdAway to manually add entries to your hosts file (just to cross check if it does the same as you did manually).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.