NFS & CIFS client

To setup an NFS client and mount NFS file systems we need to make sure the packages nfs-utils and rpcbind are installed:

# dnf install nfs­utils rpcbind
Loaded plugins: langpacks
Package 1:nfs­utils­1.3.0­0.el7.x86_64 already installed and latest version
Package rpcbind­0.2.0­23.el7.x86_64 already installed and latest version
Nothing to do

Then we need to enable (if they are disabled) and start (if they’re stopped) the rpcbind.service and nfs-lock.service if we are going to be using NFSv2 or NFSv3 (NFSv4.0 only needs the daemon rpc.mountd and v4.1 not even that).

# systemctl status rpcbind.service
rpcbind.service ­ RPC bind service
Loaded: loaded (/usr/lib/systemd/system/rpcbind.service; enabled)
Active: active (running) since Sat 2015­04­04 19:29:11 EDT; 1min 11s left
Process: 1942 ExecStart=/sbin/rpcbind ­w ${RPCBIND_ARGS} (code=exited, status=0/SUCCESS)
Main PID: 1952 (rpcbind)
CGroup: /system.slice/rpcbind.service
└─ 1952 /sbin/rpcbind ­w
Apr 04 19:29:11 rhce7 systemd[1]: Started RPC bind service.
# systemctl status nfs­lock.service
nfs­lock.service ­ NFS file locking service.
Loaded: loaded (/usr/lib/systemd/system/nfs­lock.service; enabled)
Active: active (running) since Sat 2015­04­04 19:29:11 EDT; 1min 2s left
Process: 1995 ExecStart=/sbin/rpc.statd $STATDARG (code=exited, status=0/SUCCESS)
Process: 1961 ExecStartPre=/usr/libexec/nfs­utils/scripts/nfs­lock.preconfig (code=exited,
Main PID: 2041 (rpc.statd)
CGroup: /system.slice/nfs­lock.service
└─ 2041 /sbin/rpc.statd
Apr 04 19:29:11 rhce7 rpc.statd[2041]: Version 1.3.0 starting
Apr 04 19:29:11 rhce7 systemd[1]: Started NFS file locking service..

Assuming that an NFS server in is running and sharing the directory /nfs/companies, mounting such directory would only require a simple mount:

# mount -t nfs -o rw  /mnt/companies

Or if we want that directory to be mounted at boot time from now on, then we edit /etc/fstab adding:    /companies     nfs     rw,noatime     0    0

If we add an NFS directory to the /etc/fstab to use on an ongoing basis, we have to get it right! So we have to specify the right options to ensure no hiccups.

First choice is between the hard and soft options. If we mount a file system with the soft option and a file request fails, the NFS client will simply report an error back to the requesting program. If that program can handle the error and react the right way everything would be fine. Unfortunately that is not the case for most programs. So we should go for hard unless there’s a very good reason not to.
Using hard, it is a must to also specify the option intr for interruptible for the client to be able to cancel a request.

The next choice is the size of read and write chunks (rsize & wsize). A good starting point might be setting them to 8 kbytes (8192 bytes) and tweak it up/down from there.

The next set of values to decide on are timeo and retrans. Timeo determines the timeout period in tenths of a seconds that the client will wait before it decides to resend the request assuming packet loss, network congestion, etc. The retrans value determines the number of times a request will be retried before giving up. The default value for timeo is 0.7 seconds and for retrans it is 3 times. If we are OK with those values we can skip explicitating them in the options section.

Then we can choose between the tcp and udp protocols. If the NFS server is in the local network, we might want to use udp for performance reasons. If it is not, then tcp is recommended.

If we are a bit paranoic about security and do not fully trust the NFS server, we can use any or all of the following options: noacl,nosuid,noexec.

Finally, we can decide whether to use NFSv3 or 4. If version 4 is available in both client and server, that will be the default one. If version 4 is not available in both, version 3 will be used. But if we want to force the use of version 3 even having 4 available, we can do so using vers=3 in the options section. If we want to explicitly use version 4, then the file system type should be changed from “nfs” to “nfs4”.

So now we can reset the line in /etc/fstab to something a bit better:    /companies     nfs     rw,noatime,hard,intr,tcp,noacl,nosuid,noexec     0    0

We can see what filesystems a remote server makes available to us by running:

# showmount ­-e servernfs1
Export list for servernfs1

And we can mount all shared filesystems from a remote server with:

# mount  servernfs1:/  /mnt

The CIFS (aka Samba) client is far easier to configure. We can mount a remote CIFS file system as follows:

# mount -­t cifs -­o rw,username=marc,password=psswd // /share

If we do not want to scream out loud the credentials, we can run this instead …

# mount -­t cifs -­o rw,credentials=/etc/samsa.passwd // /share

… assuming the file /etc/samba.passwd exists (and it’s only readable by root!) and contains the credentials in the following format:

# cat /etc/samba.passwd

Adding this entry permanently to /etc/fstab could be done as follows:

//     /share      cifs     rw,credentials=/etc/samba.psw      0   0

<< swap                  automounter >>