To set up an NFS v4.0 file server on CentOS or Red Hat Enterprise Linux (RHEL), you can use the following steps:
nfs-utils
package, which provides the NFS server and client utilities:sudo yum install nfs-utils
or
sudo dnf install nfs-utils
sudo mkdir /srv/nfs
/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.
rpcbind
and nfs-server
services:sudo systemctl start rpcbind sudo systemctl start nfs-server
rpcbind
and nfs-server
services to start automatically at boot:sudo systemctl enable rpcbind sudo systemctl enable nfs-server
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