To Configure the NFS client and server on Linux machines.

Sonam Kumari Singh
4 min readDec 14, 2023

NFS Protocal ( Network File System )

Used file-sharing protocol is NFS, Network File System is a distributed file system protocol originally developed by Sun Microsystems in 1984, allowing a users to access files and directories located on remote computers and treat those files and directories as if they were local.

Using NFS are centralized data storage, increased efficiency, data security, and scalability. However, it’s not a good choice for sharing sensitive data over public networks and doesn’t support hierarchical storage management.

1. Update & Install NFS

Yum package manager is used to install nfs-utils package.

# sudo yum update

# yum install nfs-utils -y

Enable & start NFS server

# sudo systemctl enable nfs-server

# sudo systemctl start nfs-server

You must also start the rpcbind service ( NFS relies on Remote Procedure Calls (RPC) for remote communication. RPC services are controlled by the rpcbind service. ), which NFS uses for port mapping:

# sudo systemctl enable rpcbind

2. Configure your firewall

# sudo firewall-cmd — add-service nfs — permanent

# getenforce

#setenforce 0

for convience, I have disabled SELinux

3. Set a shared location & permissions

create a location on the filesystem to share with client computers. This could be a separate drive, a separate partition, or just a place on your server.

# sudo mkdir -p /home/nfs/share_dir

With all the NFS services installed and running as expected, it’s time to create the NFS share directory, which is the directory that will contain files that will be accessed by NFS clients in the network.

we will assign global permissions that will accord NFS clients read, write, and execute permissions.
# sudo chmod 777 -R /home/nfs/share_dir #everyone can modify files

4. Allow server access through NFS export file

For the NFS service to know to broadcast the existence of your share_dir shared location, you must add the location to the /etc/exports file, as well as the subnet you want to have access and the global access permissions.

# sudo vi /etc/exports

Add the following entry. Be sure to replace the server-ip with your NFS server’s IP address.

# /home/nfs/share_dir server-ip/24(rw,no_root_squash)

To better understand the parameters used here, let’s break them down one by one.

  • rw — Allows us to read and write to the NFS share.
  • sync — Requires writing of changes to the disk before any other operations are completed.
  • no_all_squash — Maps all UIDs and GIDs from the client request to the identical UIDs and GIDs on the NFS server.
  • root_squash — Maps requests from the client-side root user to an anonymous UID/GID.

To update the table, run the exportfs command along with the -r command to export all directories

# sudo exportfs -rv

Run the following command to view the NFS shares.

# sudo showmount -e localhost

5. Configure NFS client

Since we already updated our system and installed the nfs-utils package. First, create a directory on the client machine to mount the remote share.

client-side# mkdir -p client/myshare

Now that we have created a mount directory, let’s mount the share.

client-side# mount -v -t nfs server-ip:/home/nfs/share_dir/ client/myshare

Finally, to ensure that the mount is persistent across reboots, add the following line to the /etc/fstab file:

client-side# vi /etc/fstab

Then add the following entry & save and exit the configuration file..

server-ip:/home/nfs/share_dir /root/client/myshare nfs defaults 0 0

client-side# systemctl daemon-reload

6. Testing NFS SetUp

On the client side, we will create the files in the NFS share directory.

# touch client/myshare/file{1..4}.txt

To verify that the files have been created,

# ls -l client/myshare/

Back to the server side, verify that the files are available in the mount directory without any service refresh or restart of any services as seen in the following output.

Hope this article helped you to configure the NFS. Follow me for such articles of Linux . If any queries or suggestions reach out to me on LinkedIn.

--

--

Sonam Kumari Singh

SONAM here! Grateful for your connection! Tech enthusiast exploring new languages, deep into DevOps, with a spotlight on Linux. 😊🚀