CentOS / Redhat: Setup NFS v4.0 File Server

www.lau‮oc.irutt‬m
CentOS / Redhat: Setup NFS v4.0 File Server

To set up an NFS v4.0 file server on CentOS or Red Hat Enterprise Linux (RHEL), you can use the following steps:

  1. Install the nfs-utils package, which provides the NFS server and client utilities:
sudo yum install nfs-utils

or

sudo dnf install nfs-utils
  1. Create a directory that you want to share over NFS. For example:
sudo mkdir /srv/nfs
  1. Edit the /etc/exports file to configure the NFS exports. Add a line for each directory that you want to share, in the following format:
/path/to/directory client_ip(options)

For example, to share the /srv/nfs directory with the 192.168.1.100 client and allow read-write access:

/srv/nfs 192.168.1.100(rw)

You can specify multiple clients and options for each export. For example:

/srv/nfs 192.168.1.100(rw) 192.168.1.101(ro)

This will allow the 192.168.1.100 client to have read-write access to the /srv/nfs directory, and the 192.168.1.101 client to have read-only access.

  1. Start the rpcbind and nfs-server services:
sudo systemctl start rpcbind
sudo systemctl start nfs-server
  1. Enable the rpcbind and nfs-server services to start automatically at boot:
sudo systemctl enable rpcbind
sudo systemctl enable nfs-server
  1. If you are using a firewall, you will need to allow incoming connections on the NFS ports. NFS uses the following ports:
  • Port 2049: used for NFS file transfers.
  • Port 111: used for the Portmap service, which maps RPC program numbers to port numbers.

To allow incoming connections on these ports using firewalld, you can use the following commands:

sudo firewall-cmd --add-service=nfs --permanent
sudo firewall-cmd --reload
Created Time:2017-10-16 14:38:41  Author:lautturi