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

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

Leave a Comment