dns - OS X not resolving hostnames for SSH/HTTP

07
2014-07
  • Bug

    I have a Debian server named neptune, with a static IP of 192.168.1.10 which provides SMB, Intranet and SSH services. On my Windows computer it resolves fine, yet on my Mac it appears under "Shared" with its hostname and I am able to use it. However, I can't use the hostname to SSH into it, nor can I go to it by hostname in my browser. I've tried restarting my Mac and renewing its IP address, but it's not been successful.

  • Answers
  • Vinícius Ferrão

    You're lacking basic skills on networks. To connect to something with it's name you need a DNS Server and registered IP addresses in this DNS Server.

    What you're seeing is nothing more than a mess of protocols broadcasting in your network with different names and domain names.

    In common sense, perhaps you're missing the local domain. Yep. Try to connect to the hostname you like with an ending .local; for example: if your hostname is machine try ssh to machine.local.

    Why I think that's the problem? Because you said that you have a Debian Server with SMB and extra services, so it might have Avahi installed, and Avahi commonly broadcast a .local domain. For more info take a look over here: http://avahi.org/wiki/AvahiAndUnicastDotLocal

    EDIT: Since you're running a DNS server you must populate your DNS with records from your network. I don't know what DNS domain zone you've defined but you must put a record in this way, considering you're running BIND:

    192.168.1.10        IN        A        neptune
    

    After this double check if all your machines are using your DNS Server. In the Windows and OS X machines it's located on the Network Preferences. Just put your DNS Server as primary and another one, commonly from your ISP, as a failover DNS.

    Then you should try to connect to neptune.yourdomain.com and see if you get the expected results.

    If not, start the debugging processes with nslookup and dig tools. One common thing that happens in failing DNS resolution is bad caches, this happens a lot on OS X machines, even in my machine this happens. So I'm constantly issuing this command on the terminal to cleanup the caches:

    sudo killall mDNSResponder
    

    Let's see if your problem is solved now.

  • Robbie Mckennie

    As far as I know, this is normal behaviour. If you want to make it work, you could set up your own DNS server, or add an entry to your hosts file. The latter option is the easiest, all you need to do is add the following to /private/etc/hosts.

    192.168.1.10  neptune
    

    You should be able to edit it with the command sudo nano /private/etc/hosts


  • Related Question

    virtualbox - Sudo can't resolve hostname
  • Juve
    $ curl http://google.de  # DNS resolution works fine
    ...
    $ sudo curl http://google.de
    curl: (6) Couldn't resolve host 'google.de'
    
    $ echo $http_proxy
    http://proxy:8080
    
    $ cat /etc/hosts
    127.0.0.1   localhost.localdomain localhost
    127.0.1.1   debian
    # ip6-stuff below
    
    $ hostname
    debian
    

    I am using Debian squeeze (LXDE) inside VirtualBox and can do admin stuff via a real root console or via su root. I added my user to the sudoers group and can do stuff like editing via sudo, e.g., sudo vim /etc/hosts. I'd like to use sudo instead of su root.

    Why are curl (and other tools like aptitude) not able to resolve the hostnames, but when using them as normal user or plain root everything works fine?

    Edit: Here is the solution (Thx to Paul):

    $ sudo visudo
    # add this line
    Defaults        env_keep = "http_proxy https_proxy ftp_proxy"
    # above this line
    Defaults        env_reset
    

  • Related Answers
  • Paul

    When you are running sudo, you are running a new shell as root, in which the command is executed. Only the environment variables in the /etc/sudoers file are copied into the new shell.

    To get around this for one command you can do

    sudo env http_proxy=$http_proxy curl http://google.de
    

    Or you can edit /etc/sudoers (use visudo!) and add

    Defaults     env_keep = http_proxy
    

    This will pass the variable through automatically.