Seems like nobody in Linux World ever solved the problem of permanently mounting CIFS shares on Linux without hardcoding IP addresses though.
This was gnawing at me, so I went back and gave it another try. I'm going to post the instructions here just so that the one goddamned place on the entire goddamned internet to have a complete, working set of instructions is Kiwi Farms.
These instructions are only good for Linux distributions that use systemd.
Permanently Mount CIFS Share By Name
1. Install packages for CIFS and WINS
Make sure you have all of the following installed via your package manager of choice:
winbind
,
libnss-winbind
,
cifs-utils
2. Set up winbind to run on startup, but only after the network is up.
Edit
/lib/systemd/system/winbind.service
and make sure that the "After" section includes "network-online.target". On my system it only had "network.target" by default, which is not enough.
The service itself should already exist after you install winbind.
3. Add WINS name resolution
Edit
/etc/nsswitch.conf
and add "wins" to the hosts line. Internet sources suggest that the order matters, and "wins" should be inserted after "files" but before "dns". Mine looks like:
Code:
hosts: files wins mdns4_minimal [NOTFOUND=return] dns
4. Create credentials file (optional)
If you're saving a username/password for the share you're mounting, create a credentials file as described in the man page for
mount.cifs
, and set some sort of appropriate file protection on it. (chmod 400 seems to be a good start - not sure if this is sufficient)
5. Create mount point in your filesystem
Create an empty directory wherever you want the CIFS share to be mapped to.
6. Add mounts to fstab
Edit
/etc/fstab
and add CIFS filesystem mounts, with a special parameter to have them only processed by systemd
after winbind is loaded.
Example line:
Code:
//servername/sharename /mountpoint/path cifs credentials=/path/to/creds,iocharset=utf8,file_mode=0666,dir_mode=0777,x-systemd.requires=winbind.service 0 0
The credentials parameter can be omitted if you're not using a credentials file.
The file_mode and dir_mode values probably could use tightening up.
The x-systemd.requires parameter is the key here, so that systemd won't try to mount these filesystems until winbind is active, so the server name can successfully be looked up.
If you do all this you can have CIFS/SMB shares that automatically mount on startup, without having to assign a static IP to the server, run a DNS server on your home network, or hardcode IP addresses anywhere in your config.