hostname does not resolve on LAN

4

1

I’m on Mac OS X 10.7.5. Got some kind of voodoo with my hostname. I frequently run web servers (PHP/Java) but suddenly these decided to stop playing nicely. This machine always had DHCP, which never was a problem. This machine is named blah, which I just checked using system prefs, both in network and sharing sections. Everything is set the same. And my router (Asus RT-N66U) sees it ok, as confirmed by its clients list (to see all machines connected on my LAN).

An example of the problem. Ping on blah itself:

    # ~: ping blah
    ping: cannot resolve blah: Unknown host

Further, ping on another machine (named other):

    other: ping blah
    PING blah (192.168.1.236): 56 data bytes
    64 bytes from 192.168.1.236: icmp_seq=0 ttl=64 time=2.223 ms
    64 bytes from 192.168.1.236: icmp_seq=1 ttl=64 time=1.390 ms
    ...

So, blah cannot see itself but other can? But then, I start a php cli web server. http://blah launches fine on blah but on other http://blah returns failed to connect to server. So, WTF!?! lol!! I'm running out of hair to pull out here...

In essence, I'd like to have:

  • DHCP on blah, my servers+dev machine. Preferrably, since blah is a laptop which I often travel with and want no trouble connecting on other networks.
  • Other machines on LAN be able to http://blah and it'll resolve. Without having to add anything on these LAN clients, preferrably. And without typing IP addresses in URLs.

I don't know what else to try, but this seems to be some kind of DNS issue. Perhaps the router is the cause?


Well bummer... No one wants to try and help me resolve this? I really need this to be able to test the web apps I build on this dev machine. I just tried again, and it fails with two other machines connected on the LAN. This is a showstopper, especially as web dev is my professional background, I REALLY need to get this solved! I'm starting to think this might be a router issue. I can't (or did not find how) to configure my router to resolve blah correctly. The (sad) solution might be to just replace the damn router.


Ok, its been a few months and still an ongoing issue. I finally pinpointed the root of all evil today on my LAN. Basically, it all works if I make the whole stack (webserver + clients) use a specific IP. So, I guess this clearly points to an issue with name resolution. Also, I first tried to set my server with static IP, but then there's no way to tell my router (an Asus RT-N66U) that blah should resolve to the chosen IP. So essentially, I guess it's fair to assume that the router does not resolve the name of my webserver. But interestingly, this only happens for the web server. Otherwise, other services resolve that name just fine (for example, ping, vnc, remote desktop, file sharing). So perhaps there's an extra bit I should configure on the webserver (php apache, xampp). Suggestions, anyone? Sadly, there's no way to add the static route in my router's DNS (blah = 192......), a few others I've seen complain about similar issues. Perhaps I should just bite the bullet and buy another one? One thing for sure, it certainly seems like a missing "must-have" feature for a web dev's router.

Perhaps, as a workaround, I could use another router (older one, but reliable) as the DHCP server + DNS, paired with this one (configured as a switch)? That old router is 10/100, whereas the Asus is gigabit. But I guess that could be a decent "hack", for now. Or, perhaps set that router on a separate wifi and switch networks when I need to do some dev work.


Bump!

deryb

Posted 2015-03-18T15:02:32.747

Reputation: 513

if you set it back to what it was, does it work again? – Russell Uhl – 2015-03-18T17:02:08.953

Ok I "hacked" a partial solution. Added my hostname to /etc/hosts. Ping works locally, but then I still get host unresolved when calling from LAN. And still annoying cause this used to work fine without adding this entry... – deryb – 2015-03-18T17:06:49.123

you updated the hostname but didn't tell anyone about it. If your servers have a static ip (which they probably should) configure your router/whatever with the updated hostname – Russell Uhl – 2015-03-18T17:07:43.537

No my dev machine (and servers) had DHCP and all worked well, so I'd rather stick that way. I used static IPs many times in the past, so I know the drill. Besides I prefer to have a humanly readable hostname instead of 192.168.x.x... I never had to configure anything on my router before and it worked just fine. And @Russell, yea I just tried. Still does not work. – deryb – 2015-03-18T18:47:48.137

I don't understand the issue you had with static IPs...you set the ip, then set the hostname in your router's DNS, and point the hostname to the IP. In any case, that's all of my ideas, sorry – Russell Uhl – 2015-03-18T19:46:15.103

1Thanks. Well for starters I don't really know my router much and doing all these changes is a bit too much for my taste. Unexpected new issues will arise likely. I will try and find a less drastic approach for now which would ideally mean just altering the config on my mac. – deryb – 2015-03-19T00:40:17.167

One related thing I don't grasp: if I set my webserver to listen to blah, then load up a web page but instead using the Ip adress, (on same computer, 192.168.1.236) it fails to load. But it works if I use localhost or 127.0.0.1. – deryb – 2015-06-26T18:45:17.163

Answers

1

Mac OS X has three different ideas about the machine’s name; ComputerName, HostName, and LocalHostName. You can see what these are using scutil, like so:

hubble ~ % scutil --get ComputerName
hubble
hubble ~ % scutil --get HostName
hubble
hubble ~ % scutil --get LocalHostName
hubble

ComputerName is the user-friendly name used by the GUI (in Sharing Preferences, for example) and all the macs in your LAN will see this name.

HostName is what command line utilities see (such as ssh) and if you change /etc/hosts idea of what your IP should be called, you'll likely change this name.

LocalHostName is what Bonjour uses, and again, the macs on your LAN running Bonjour services will see this name.

Mac OS X defaults to having all three of these names the same. Something changed one of this (probably HostName), and you should check what they are and set them all the same using the --set option.

Fred

Posted 2015-03-18T15:02:32.747

Reputation: 1 205

Thanks for trying guys! I just tried all 3 (scutil --set HostName blah), commands seem to run correclty. But then ping still returns Unknown host. Today I rebooted twice to rule out unlikely running state issues but that fixed nothing either. – deryb – 2015-03-19T01:04:09.600