nfs

How To Set Up an NFS Mount on CentOS 8

Network File System (NFS) is a powerful tool that allows you to share files and directories between multiple computers over a network. If you’re running a CentOS 8 environment and need to set up an NFS mount, you’re in the right place! In this blog post, we’ll walk you through the step-by-step process of setting up an NFS mount on CentOS 8.

Prerequisites

Before we begin, ensure you have the following:

  1. CentOS 8 System: You should have a CentOS 8 server (NFS server) and a client machine where you want to mount the NFS share.
  2. Root Access: You need root access or sudo privileges on both the NFS server and the client.
  3. Network Connectivity: Ensure that the server and client can communicate over the network.

Step 1: Install NFS Packages

First, you need to install the NFS utilities on both the server and the client. Open your terminal and run the following command:

On both server and client:

sudo dnf install nfs-utils -y

Step 2: Set Up the NFS Server

2.1 Create a Shared Directory

Choose or create a directory you want to share. For example, let’s create a directory called nfs_share in the /srv directory.

sudo mkdir -p /srv/nfs_share

2.2 Configure Permissions

Set the appropriate permissions for the directory. You can adjust the ownership and permissions based on your needs.

sudo chown -R nfsnobody:nfsnobody /srv/nfs_share
sudo chmod 755 /srv/nfs_share

2.3 Export the Directory

Edit the /etc/exports file to specify which clients can access the shared directory. Use your preferred text editor:

sudo nano /etc/exports

Add the following line to the file, replacing 192.168.1.0/24 with your client’s IP address or network range:

/srv/nfs_share 192.168.1.0/24(rw,sync,no_root_squash)
  • rw: Allows the client to read and write to the share.
  • sync: Ensures changes are written to disk before they are acknowledged.
  • no_root_squash: Allows root on the client to have root access on the NFS share.

2.4 Export the NFS Share

To make the NFS share available to the clients, run the following command:

sudo exportfs -a

2.5 Start and Enable the NFS Service

Now, start and enable the NFS server to run at boot time:

sudo systemctl start nfs-server
sudo systemctl enable nfs-server

2.6 Open Firewall Ports

If the firewall is running, you’ll need to allow NFS traffic. Use the following commands to do so:

sudo firewall-cmd --permanent --add-service=nfs
sudo firewall-cmd --permanent --add-service=mountd
sudo firewall-cmd --permanent --add-service=rpc-bind
sudo firewall-cmd --reload

Step 3: Set Up the NFS Client

3.1 Create a Mount Point

On the NFS client, create a mount point where you will mount the NFS share:

sudo mkdir -p /mnt/nfs_share

3.2 Mount the NFS Share

Now, you can mount the NFS share using the following command (replace nfs_server_ip with your NFS server’s IP address):

sudo mount -t nfs nfs_server_ip:/srv/nfs_share /mnt/nfs_share

3.3 Verify the Mount

To confirm that the NFS share has been mounted successfully, run:

df -h

You should see an entry that lists the NFS share mounted on /mnt/nfs_share.

Step 4: Automate the Mount at Boot

To ensure the NFS share is automatically mounted at boot time, you’ll need to add an entry to the /etc/fstab file on the client. Open it in your text editor:

sudo nano /etc/fstab

Add the following line:

nfs_server_ip:/srv/nfs_share /mnt/nfs_share nfs defaults 0 0

Save the file and exit.

Conclusion

Congratulations! You have successfully set up an NFS mount on CentOS 8. Your NFS server is sharing files, and the client can access those files seamlessly over the network. NFS is an excellent solution for file sharing among multiple systems, especially in a collaborative environment.


Don’t forget to check out more articles on the Greenhost.Cloud blog for insightful guides and tips on cloud hosting and server management!