CIFS mount in fstab succeeds on IP, fails on hostname written in /etc/hosts

I wonder why my Ubuntu Server 14.04 LTS has problems resolving a hostname from fstab. I tried to mount the following entry:

//NAS-5h2-20/backuppc/  /mnt/backuppc   cifs   auto,user=THEUSER,password=THEPASSWORD,cifsacl,uid=109      0       0

the mount fails with the error

mount: wrong fs type, bad option, bad superblock on //NAS-5h1-15/backuppc,
   missing codepage or helper program, or other error
   (for several filesystems (e.g. nfs, cifs) you might
   need a /sbin/mount.<type> helper program)
   In some cases useful info is found in syslog - try
   dmesg | tail  or so

and the Syslog entry:

Unable to determine destination address.

HOWEVER, this works like a charm if I exchange the hostname NAS-5h2-20 for its IP 192.168.1.29. However, for portability reasons, I'd like to map the mount by hostname within the fstab.

Contents of /etc/hosts is (among other lines):

192.168.1.28    NAS-5h1-15
192.168.1.29    NAS-5h2-20
192.168.1.30    NAS-6h1-04

These Hostnames are not registered with the local DNS-Server. And it's intended do be in some cases able to use different IPs (servercluster/workstation) for DNS and server-internal usage, so I can't register them to the DNS.

It's also no Problem to

ping NAS-5h2-20

.

Thus I'm sure, it's a resolver problem. However, I can't figure out, where. I look at nsswitch.conf, nothing special there:

passwd:         compat
group:          compat
shadow:         compat
hosts:          files dns
networks:       files
protocols:      db files
services:       db files
ethers:         db files
rpc:            db files
netgroup:       nis

And /etc/resolv.conf also looks OK:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 192.168.1.1
search ourdomain.local

So, questions: - why does the resolver fail to read OR ignores the hosts file in this special case?
- is DNS/WINS/ some other resolving method hardcoded into mount.cifs?


By default, the samba (cifs) package on some distributions doesn't use the hosts file to resolve the name. Instead, it uses the NetBIOS name to resolve to the IP. There are two ways to go about this:

  • Set samba to use the hosts file for resolution.

In your smb.conf file, find and modify or create the following line:

    [global]
    name resolve order =  host lmhosts wins bcast

and restart samba. This will set samba to a use a standard host name to IP address resolution, using the system /etc/hosts, NIS, or DNS lookups, to resolve the server name. Additionally, added machine-name.domainname as an alias in your hosts file:

    192.168.1.28    machine-name    machine-name.domainname
  • Set the NetBIOS name of the machines you are trying to connect to.

On the machines you're trying to connect to set the following in the smb.conf file:

    netbios name = MachineName

and restart samba.


Ideally, you want to do both of these things, however just setting samba to use the hosts file should work.

References: https://www.samba.org/samba/docs/using_samba/ch07.html