19

I've remounted /sys as rw, added one entry to etc/hosts (e.g. 10.0.0.1 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)

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

4
  • 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
    Commented Jul 7, 2012 at 9:53
  • 2
    can you do this - ls -l /etc/hosts, possibly permissions/ownership problem?
    – t0mm13b
    Commented Jul 9, 2012 at 18:17
  • @t0mm13b "-rw-r--r-- root root"
    – gcb
    Commented Jul 18, 2012 at 18:35
  • @t0mm13b you're spot on! In my case it was the permissions. chmod 644 /system/etc/hosts sorted it out
    – KalenGi
    Commented Jan 22, 2014 at 18:09

7 Answers 7

6

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.

1
  • 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
    Commented Jul 5, 2012 at 18:14
4

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.

2

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

1
  • 1
    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
    Commented Jul 9, 2012 at 17:58
2

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

0

I think you need to flush DNS on your Android check this question https://stackoverflow.com/questions/2101762/android-flush-dns, especially "go into settings -> applications -> Network Location -> Clear data."

1
  • 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
    Commented Jul 5, 2012 at 18:09
0

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.

-2

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .