30

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

metaleap
  • 401
  • 1
  • 4
  • 5

4 Answers4

7

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

Izzy
  • 91,166
  • 73
  • 343
  • 943
  • 1
    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 http://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
  • Update: See my comment here, it looks like I have to partially withdraw my statement as described behaviour might be specific to Android versions or manufacturers. Just cross-checked on my newer 4.1.1 devices, and my DNS is used correctly there; though I must admit I've lost track on which ones I might have configured that manually. But as both still were set to DHCP (and the change requires to use static), these are more liky not tampered with. – Izzy Oct 29 '13 at 23:48
  • CM7.2 also honours the settings received via DHCP (only for the GSM radio interface (rmnet1) it sets Google's DNS servers (probably to overcome shitty provider DNS servers): [net.dns1]: [192.168.x.x] \n [net.dns2]: [8.8.4.4] \n [net.rmnet0.dns1]: [8.8.8.8] \n [net.rmnet0.dns2]: [8.8.4.4] \n [dhcp.tiwlan0.dns1]: [192.168.x.x] \n [dhcp.tiwlan0.dns2]: [] – ce4 Oct 30 '13 at 08:34
  • When I use a static IP address under Android 7.1, my LAN is suddenly unreachable (despite using identical network settings to what DHCP was providing)! – Michael Dec 26 '16 at 20:14
  • Izzy, thanks for your answer. Since it's 7 years old, I can't find those settings in Android anymore. I'm wondering if you know how to answer https://android.stackexchange.com/q/230644/22600 Thanks for your thoughts! – Ryan Oct 29 '20 at 18:40
  • @Ryan they are still in the same place: Settings › Network › WiFi – and by tap-and-holding a name you can open a menu that allows you to change the AP's settings. It might look like, when opening "advanced" settings, the details are gone, but try to scroll there, they just hide :) Oh: and the "edit" button is only available for the network you're connected to it seems. Just checked and verified on Android 7+8. – Izzy Oct 29 '20 at 23:53
  • @Izzy Thanks. On Android 11, if I long-press a wifi network name, I only see options "Disconnect" and "Forget". If I click the gear icon, I see Advanced, but none of the data / options in there seems helpful. – Ryan Oct 30 '20 at 01:22
  • I cannot help with that, I don't have any Android-11 device here. But maybe one of the WiFi config apps or DNS Tools can help you out? – Izzy Oct 30 '20 at 17:54
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.

Shadow
  • 136
  • 1
  • 8
  • 3
    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.

Firelord
  • 25,084
  • 20
  • 124
  • 286
  • 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 05: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

John Bentley
  • 101
  • 1