Network File System (NFS) is a distributed file system protocol that allows a user on a client computer to access files over a network as if they were on the local computer. In Linux, NFS is implemented as a kernel module that enables remote access to a file system mounted on a server.
To set up an NFS server on Linux, follow these steps:
Install the NFS package: On most Linux distributions, NFS is included in the default package repository. To install the server package, use the following command:
sudo apt-get install nfs-kernel-server # for Ubuntu/Debian
sudo yum install nfs-utils # for CentOS/RHEL
Configure the NFS exports: NFS exports are the directories that will be shared with the clients. To configure the exports, edit the /etc/exports file and add the directories to be shared along with the client IP address or subnet mask. For example:
/mnt/data 192.168.1.0/24(rw,sync,no_subtree_check)
This exports the /mnt/data directory to clients on the 192.168.1.0/24 network with read/write permissions.
Restart the NFS server: After configuring the exports, restart the NFS server to apply the changes:
sudo systemctl restart nfs-kernel-server # for Ubuntu/Debian
sudo systemctl restart nfs-server # for CentOS/RHEL
To set up an NFS client on Linux, follow these steps:
Install the NFS package: Install the NFS client package using the following command:
sudo apt-get install nfs-common # for Ubuntu/Debian
sudo yum install nfs-utils # for CentOS/RHEL
Mount the NFS share: After installing the NFS package, create a directory where the NFS share will be mounted and use the mount command to mount the NFS share. For example:
sudo mkdir /mnt/nfs
sudo mount 192.168.1.100:/mnt/data /mnt/nfs
This mounts the /mnt/data directory on the NFS server at the /mnt/nfs directory on the client.
Once the NFS server and client are set up, the client can access the shared directories on the server as if they were on the local file system. The NFS protocol provides a way to share files between Linux systems that is simple, reliable, and efficient.