Adding "local" to the DNS Search Domains has no effect

I have a Mac Mini (Yosemite) on my local network and it's not running a DNS server at all. When I want to access it over SSH from a Terminal on my Macbook Air (Yosemite), I can type:

$ ssh myserver.local

And that works fine.

But I wanted to avoid having to type the ".local" domain every time, so I added the "local" domain to the Search Domains list in Network Settings (for my Wi-Fi adapter which is the one currently in use in my MBA).

If I then try:

$ ssh myserver

that doesn't work (Could not resolve hostname).

Any idea why?


Solution 1:

Hostname resolution in Mac OS X (since ~10.3) has roughly spoken - i exclude various cache mechanisms - the following operating sequence:

  1. 'Files' (e.g. /etc/hosts) ->
  2. mDNS ->
  3. DNS (search domains) ->
  4. DNS

Valid names for the different name resolution methods:

for 1: almost arbitrary names
for 2: name.local
for 3: name (+ search.domain in your network prefs) A Start Of Authority (SOA) record for the top level domain is obligatory.
for 4: fqdn

In your first scenario (myserver.local) you only use 'Files' and mDNS. 'Files' fails because there is no entry myserver.local in your hosts file. mDNS succeeds resolving it because it's a valid and resolvable mDNS name.

In your second scenario (myserver & search.domain local) you use 1, 2, 3 (and 4). 'Files' fails because you have no entry myserver, mDNS fails because it's no valid mDNS name. DNS (search domains) fails because you don't have a DNS-server with a SOA record for .local in your network (as well as DNS).

So just enter sudo nano /etc/hosts in Terminal and add the line:

 a.x.y.z      myserver

(a.x.y.z= IP-number of your server) and it should work. If you are really lazy even an 'a' as name might be sufficient. But don't use single numbers (like 1 or 123) because then ssh might try to connect to 0.0.0.1 or 0.0.0.123. At least ping connects to 0.0.0.1 or 0.0.0.123.

Solution 2:

@klanomath's answer explains perfectly how name resolution works, why your attempt did not and how you can create a pseudonym on your local machine for a static address through the /etc/hosts file.

However, if myserver does not have a static address but rather is assigned one dynamically (e.g. by DHCP), then /etc/hosts is not ideal as one must find some way to keep the address therein updated.

For SSH, one can instead create an alias in /etc/ssh/ssh_config (system-wide) or ~/.ssh/config (user-specific):

Host myserver
    HostName myserver.local

Then you can simply ssh myserver.