NFS
Notes// archive From the original Code Walker docs. Kept for reference, so some versions and commands may be out of date.
The Network File System (NFS), is an internet standard protocol used by Linux, UNIX, and similar operating systems as their native network file system.
NFS servers export shares) and NFS clients mount an exported share to a local mount point.
Mount NFS Shares#
Temporarily mount an NFS share using the mount command:
sudo mount -t nfs -o rw,sync remoteserver:/share /mountPersistently mount an NFS share using /etc/fstab:
remoteserver:/share nfs rw,sync 0 0Use the nfsconf tool to manage NFS client and server configuration files to get, set, or unset NFS configuration parameters. It updates the /etc/nfs.conf configuration file.
Examples:
nfsconf --set nfsd vers4.2 y
nfsconf --get nfsd vers4.2
nfsconf --unset nfsd vers4.2To configure an NFSv4-only client:
nfsconf --set nfsd udp n
nfsconf --set nfsd vers2 n
nfsconf --set nfsd vers3 nAutomounter#
The automounter is a service autofs that automatically mounts NFS shares “on-demand,” and automatically unmounts NFS shares when they are no longer used.
Install the autofs package:
dnf install autofs nfs-utilsAdd a master map file to /etc/auto.master.d:
vi /etc/auto.master.d/example.autofs/shares /etc/auto.exampleCreate the mapping file:
/etc/auto.example* -rw,hard,intr 192.168.122.200:/nfsdata/&
* -rw,sync,fstype=nfs4 server.example.com:/shares/&Start the autofs service:
systemctl enable autofs
systemctl start autofsExample of direct mapping:
/- /etc/auto.directSummary
Mount and unmount an NFS export from the command line.
Configure an NFS export to mount at startup automatically.
Configure the automounter with direct and indirect maps, and describe their differences. Configure NFS clients to use NFSv4 using the new nfsconf tool.
Command References:
mount, umount, fstab, nfsconf, autofs.
Serving NFS shares#
The following describe how to configure a Red Hat Enterprise Linux 8 or equivalent server to serve out NFS shares.
Install nfs-utils:
dnf install nfs-utils -yEnable and start the two required services required:
systemctl enable --now rpcbindsystemctl enable --now nfs-serverOpen the required firewall ports:
firewall-cmd --permanent --add-service=nfsfirewall-cmd --permanent --add-service=rpc-bindfirewall-cmd --permanent --add-service=mountdfirewall-cmd --reloadDepending on the storage available, create directories on the NFS host to share out, for example:
mkdir -p /nfs/my_shareThen define the share in /etc/exports:
/nfs/my_share 192.168.1.1/24(rw,sync,no_wdelay,no_root_squash,insecure)Use the following command to make any defined share available:
exportfs -arvUse the following commands to view available shares on the NFS host:
exportfs -sshowmount -e 127.0.0.1You can also use the showmount command on an external host to test the visibility:
showmount -e 192.168.1.100