Server Configuration
/etc/exports contains the exported directories
on NFS servers. Refer to the exports.5 manual page
for the syntax of this file. Also refer to the "NFS HowTo" available at
https://nfs.sourceforge.net/nfs-howto/ for information on
how to configure the servers and clients in a secure manner. For
example, for sharing the /home
directory over the local network, the following line may be added:
cat >> /etc/exports << EOF
/home 192.168.0.0/24(rw,subtree_check,anonuid=99,anongid=99)
EOF
![[Note]](../images/note.png)
Note
Be sure to replace the directory, network address. and prefix above
to match your network. The only space in the line above should be
between the directory and the network address.
![[Note]](../images/note.png)
Note
Install the NFSv4 server units
included in the "blfs-systemd-units" package
to start the server at boot.
make install-nfsv4-server
If you have disabled NFSv4 support, run the following command as the
root user to omit the NFSv4 specific systemd units:
make install-nfs-server
You can edit the /etc/default/nfs-utils
file to change the startup options for NFS daemons. Defaults
should be fine for most use cases.
Client Configuration
/etc/fstab contains the directories that
are to be mounted on the client. Alternately the partitions can be
mounted by using the mount command with the proper
options. To mount the /home
and /usr partitions, add the
following to the /etc/fstab:
<server-name>:/home /home nfs rw,_netdev 0 0
<server-name>:/usr /usr nfs ro,_netdev 0 0
The options which can be used are specified in man 5 nfs
. If both the client and server are running recent versions
of linux, most of the options will be negotiated (but see the Note
above on nfsver=3). You can specify either rw or
ro, _netdev if the filesystem is
to be automatically mounted at boot, or noauto (and
perhaps user) for other filesystems.
If the fileserver is not running a recent version of linux, you may
need to specify other options.
You may need to enable autofs v4 in your kernel, and add the option
comment=systemd.automount. Some machines may need
this because systemd tries to mount the external filesystems before
the network is up. An alternative is to run mount -a
as the root user after the system has started.
![[Note]](../images/note.png)
Note
The following systemd units are not required
if the nfs-server units are installed.
Install the units included in the
"blfs-systemd-units" package to start
the client services at boot.
make install-nfs-client
Or Create the following files as root by running the following commands:
cat > /etc/default/nfs-utils << "EOF"
# Begin /etc/default/nfs-utils
# Options to pass to rpc.idmapd.
# See rpc.idmapd(8) for more details.
IDMAPD_OPTS=""
# Options to paass to rpc.mountd.
# If you have a port-based firewall, you might want to set up
# a fixed port here using the --port option.
# See rpc.mountd(8) for more details.
MOUNTD_OPTS=""
# Options to pass to rpc.nfsd.
# See rpc.nfsd(8) for more details.
NFSD_OPTS=""
# Options to pass to sm-notify.
# See sm-notify(8) for more details.
SM_NOTIFY_OPTS=""
# Options to pass to rpc.statd.
# See rpc.statd(8) for more details.
STATD_OPTS=""
# End /etc/default/nfs-utils
EOF
cat > /usr/lib/systemd/system/rpc-statd.service << "EOF"
[Unit]
Description=NFS status monitor for NFSv2/3 locking.
DefaultDependencies=no
Conflicts=umount.target
Requires=nss-lookup.target rpcbind.target
After=network.target nss-lookup.target rpcbind.target
PartOf=nfs-client.service
[Service]
Type=forking
EnvironmentFile=/etc/default/nfs-utils
PIDFile=/run/rpc.statd.pid
ExecStart=/sbin/rpc.statd --no-notify $STATD_OPTS
EOF
cat > /usr/lib/systemd/system/rpc-statd-notify.service << "EOF"
[Unit]
Description=Notify NFS peers of a restart
Requires=network-online.target
After=network-online.target nss-lookup.target nfs-server.service
PartOf=nfs-client.service
[Service]
Type=forking
EnvironmentFile=/etc/default/nfs-utils
ExecStart=/sbin/sm-notify $SM_NOTIFY_OPTS
EOF
cat > /usr/lib/systemd/system/nfs-client.service << "EOF"
[Unit]
Description=NFS server and client services
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/true
EOF
cat > /usr/lib/systemd/system/ << "EOF"
[Unit]
Description=NFS client services
Before=remote-fs-pre.target
Wants=remote-fs-pre.target rpc-statd-notify.service
[Install]
WantedBy=multi-user.target
WantedBy=remote-fs.target
EOF