19

Developer here prototyping a mobile app, somewhat new to mobile:

  • I have a simple HTTP service running (currently) on my main laptop with machine name latitude.
  • Another laptop named vaio sharing the same WiFi network can access that service via http://latitude:8080 -- in other words, it can easily resolve the (current) IP 192.168.x.y (or whatever dynamic IP it has at that moment) of latitude somehow.
  • Now my HTC Android phones, connected to the same WiFi network, can reach the IP address of latitude so opening in its browser http://192.168.x.y:8080 works.
  • But I'd like to use the machine name here, too, like when I access the HTTP service from vaio, simply by typing http://latitude:8080 and have the phone resolve the current dynamic IP of latitude. This doesn't work, only get the standard browser error page: "Webpage not available".

Is there some DNS setting in Android I need to tweak? Haven't found anything from playing around with Settings, and a question like this is notoriously hard to google, too...

The One V has Android 4.0, and the One M7 has Android 4.2 in case that makes a difference.

(Note, this should work even when the Android is not USB-connected to my computers and is not acting as a WiFi Hotspot -- obviously, since it's consuming my main WiFi network anyway).

4

Regardless whether you're connected to your local network via WiFi and DHCP is in use, Android always seems to override its DNS entries using Google's servers. It's somewhat hidden, but easy to change – provided you have your own DNS running (a lot of routers offer that already).

To do so, go to your list of WiFi networks in Settings, long-press your WiFi's entry, select to edit it. Activate Advanced Settings. Now you can edit the DNS entries. Simply replace the first entry with your own DNS server's IP, and leave the second entry (DNS 2) untouched for fall-back.

Now, if your own DNS can resolve your local network's machines, you should be able to use their hostnames to reach out to them. No root and no editing the hosts file necessary (thought that might be an alternative, if you've got no own DNS service running). Works excellent here with me and my network ;)

  • Thanks! Here's the weird thing, when I do this then my router (gateway) is already also entered as DNS1 (and Google's or 8.8.4.4 as DNS2). Well I'm going with these defaults and apply them, NetBIOS and SMB are enabled on the Windows machine, but still no name resolution... – metaleap Aug 28 '13 at 11:52
  • 2
    I have no plans with Windows. In my case, it's a Linux based environment, and the router (AVM Fritz!Box) has a name server running. Works smoothly. – Izzy Aug 28 '13 at 16:07
  • This should at most (if even) apply only to old versions of Android. My first dns is my local one while the fallback is google's 8.8.8.8. Looked it up with getprop | grep -i dns See also android.stackexchange.com/a/32278/15713 – ce4 Oct 29 '13 at 22:24
  • Firefox acts different and doesn't show this behaviour, I guess it's Chrome's omnibox ( combined search / URI input box) that does this – ce4 Oct 29 '13 at 22:39
  • Firefox doesn't use its own DNS servers (at least I would wonder if). All software usually asks the system for that information, so the browser should not matter here. @ce4: Yes, that's how I configured it manually on my device: same fallback, but the primary I had to manually change from 4.4.4.4 to my local DNS server. I know that my DHCP server sends that information, but did not see a single Android device honoring that. – Izzy Oct 29 '13 at 23:36
1

When I want a machine name instead of an IP I edit the HOSTS file. Try adding the devices and their IP addresses there. A google search for the hosts file for your operating system should be easy.

  • 1
    Editing HOSTS is only useful if the IP address of the laptop always stays static / the same. This won't be the case as I'm working on the go, different WiFi networks, dynamic IP addresses. Also editing HOSTS requires a rooted Android but I need it to stay unrooted and largely untweaked to test under "normal consumer phone" conditions.. – metaleap Aug 28 '13 at 11:54
0

Add two lines at the end of your device's hosts file (/etc/hosts) file with ES Explorer (needs a rooted device).

Template:

your_host_machine's_IP_address  domain_name   

Example of domain_name can be localhost.

Example:

::1  domain_name 

It works fine when typing localhost in URL bar instead of IP address.

  • I corrected \etc\hosts to /etc/hosts and made some changes in the formatting. I tried not to change the intent but make it look better. Let me know if I messed up somewhere. – Firelord Feb 12 '16 at 5:48
0

In my case, on Windows 10, temporarily turning off windows firewall made surfing to http://latitude:8080 possible.

For the longer term I created a rule to let these sort of connections through the firewall ...

  • {Windows} > Start > "Firewall" > Windows Defender Firewall with Advance Security. Inbound Rules > New Rule ...

    • General
      • Name: TCP web connections from LAN
      • Allow the connection if it is secure ...
      • Choose: "Allow the connection if it is authenticated and integrity-protected"
    • Protocols And Ports
      • Protocol Type: TCP
      • Local Port: 80, 880
    • Advanced
      • Specify profiles to whcih this rule applies: Private
  • {Android}. Test with Firefox or Chrome, not Dolphin

protected by Community Mar 7 at 14:27

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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