2.3 gingerbread - Why does android ignore my etc/hosts change in the browser?

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

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

But, if I open a web browser (either stock or Dolphin), and browse to x.com, 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.

7 Answers

  1. Ken- Reply


    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.

  2. Kenneth- Reply


    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.

  3. Kenny- Reply


    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. https://groups.google.com/forum/?fromgroups#!topic/android-platform/K2Wr4WaEneI

  4. Kevin- Reply


    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++.

  5. Lance- Reply


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

  6. Larry- Reply


    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.

  7. Laurent- Reply


    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).

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>