NFS Server & Client Installation on Linux Environment

What is Network File System (NFS)

Network File System (NFS) is a distributed file system that allows various users to access and share files over a network. It is commonly used in Linux and Unix systems as an alternative to other file sharing protocols like SMB or CIFS.

 What is needed?

Since NFS uses a server to client(s) relationship, we will use the following:

NFS server – server.example.com – 172.25.1.5

NFS client – client.example.com – 172.25.1.4

let’s ensure that both of our systems are up to date. we will use the following command on both the server and client:

# sudo yum -y update

And finally, we need to install the nfs-utils package to both our systems.

# sudo yum -y install nfs-utils (must do on both servers and client)

Configure the server

Step 1: Start and enable the newly installed nfs-utils service.

#sudo systemctl start nfs-server.service

#sudo systemctl enable nfs-server.service

Step 2: Confirm the nfs-server service is up and running.

#sudo systemctl status nfs-server.service

nfs-server.service – NFS server and services

Loaded: loaded (/usr/lib/systemd/system/nfs-server.service; enable>

Active: active (exited)

Main PID: 61026 (code=exited, status=0/SUCCESS)

Tasks: 0 (limit: 50657)

server.example.com systemd[1]: Starting NFS server a

server.example.com systemd[1]: Started NFS server

lines 1-10/10 (END)

 

The NFS service is now up and running on your server. Next, let’s create an NFS share.

Create and export the share.

First, we need to designate a folder for sharing.

# sudo mkdir -p /test/nfs_share/

# sudo chown -R nobody: /test/nfs_share/

# sudo chmod -R 777 /test/nfs_share/

Next, we need to create an /etc/exports file.

# vi /etc/exports

Make the following entry in the new file:

/test/nfs_share   172.25.1.5 (rw,sync,no_all_squash,root_squash)

The parameters used here.

  • 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.

Now that we have created the share, let’s export it to the client.

# exportfs -rav

exporting 172.25.1.5:/test/nfs_share

Notice that I mapped the entire subnet here. You can include only a single IP or hostname here if you prefer.

with the server-side completed, we can now focus our attention on the client machine.

Configure the client

Since we already updated our system and installed the nfs-utils package as shown above

Create an entry in /etc/host for the NFS server. It should look like this:

# cat /etc/hosts

127.0.0.1 localhost

172.25.1.5 localhost

Now, let’s see if anything is shared from the NFS server. Our server share path /test/nfs_share/ as a shared directory.

# showmount –exports nfs-server

Export list for nfs-server:

/test/nfs_share/ 172.25.1.5

Next, create a directory on the client machine to mount the remote share.

# sudo  mkdir p /test/client_share

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

# sudo mount -t nfs 172.25.1.5:/test/nfs_share/  /home/test/client_share

Run the following command to verify the share:

# sudo mount | grep -i nfs

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

172.25.0.5:/test/nfs_share/ /home/test/client_share  nfs defaults 0 0

Easy day.

Proof of concept

Create a file on the server in /test/nfs_share/ named test_doc for testing purpose.

# ls -lrt

-rw-r–r–. 1 root root 39 Jun 25 16:21 test_doc

Let’s see if our test_doc is exported to our client machine via NFS.

On the client machine:

# cd test/client_share/

#client client_share]$ ls

test_doc

Conclusion

NFS is a great tool for sharing files over a network, especially in a Linux or Unix environment. With this guide, you should be able to install NFS on your system and share files with other systems on the network.

Recent Posts