Network File System (NFS) is a distributed file system protocol originally developed by Sun Microsystems (Sun) in 1984, allowing a user on a client computer to access files over a computer network much like local storage is accessed. NFS, like many other protocols, builds on the Open Network Computing Remote Procedure Call (ONC RPC) system. The NFS is an open standard defined in a Request for Comments (RFC), allowing anyone to implement the protocol.
dnf -y install nfs-utils
You would be working mainly on below configuration files to setup NFS server and Clients.
/etc/exports: It is the main configuration file, controls which file systems are exported to remote hosts and specifies options.
/etc/fstab: This file is used to control what file systems including NFS directories are mounted when the system boots.
/etc/sysconfig/nfs: This file is used to control which ports the required RPC services run on.
/etc/hosts.allow and /etc/hosts.deny: These files are called TCP wrappers, controls the access to the NFS server. It is used by NFS to decide whether or not to accept a connection coming in from another IP address.
# vi /etc/exports
Create a NFS share something like below.
/home *(rw,sync,no_root_squash)
/home: shared directory
192.168.1.20: IP address of client machine. We can also use the hostname instead of an IP address. It is also possible to define the range of clients with subnet like 192.168.1.0/24. Use * for all addresses.
rw: Writable permission to shared folder
sync: All changes to the according filesystem are immediately flushed to disk; the respective write operations are being waited for.
no_root_squash: By default, any file request made by user root on the client machine is treated as by user nobody on the server. (Exactly which UID the request is mapped to depends on the UID of user "nobody" on the server, not the client.) If no_root_squash is selected, then root on the client machine will have the same level of access to the files on the system as root on the server.
Once the packages are installed, enable and start NFS services.
# systemctl start nfs-server rpcbind # systemctl enable nfs-server rpcbind
We need to configure the firewall on the NFS server to allow NFS client to access the NFS share. To do that, run the following commands on the NFS server.
# firewall-cmd --permanent --zone=public --add-service=mountd # firewall-cmd --permanent --zone=public --add-service=rpc-bind # firewall-cmd --permanent --zone=public --add-service=nfs # firewall-cmd --reload
# showmount -e 192.168.1.10
First we need a mountpoint.
mkdir /net
Mount the shares with: IP4:/path
mount -t nfs 10.10.0.10:/backups /net
When done use:
umount /net
If the NFS mount has an entry in the fstab file, remove it.
This is the same as mounting partitions.
To automatically mount an NFS share when your Linux system starts up add a line to the /etc/fstab file. The line must include the hostname or the IP address of the NFS server, the exported directory, and the mount point on the local machine.
# <file system> <dir> <type> <options> <dump> &<pass> 10.10.0.10:/backups /var/backups nfs defaults 0 0
Where 10.10.0.10 the NFS server IP address, /backup is the exported directory and /var/backups is the local mount point.