Setup NFS Service on CentOS 7
NSF (Network-base File System) can allow computers (clients) to access files on another computer(server) over the network even the clients have different operating systems from the server. And this article will guide you exstablishing your own NFS service on CentOS 7, which is generally used as server os.
To establish your NFS service, you need at least two instances (one as server, and the remains as clients) with CentOS 7 fresh installed. CentOS 7 supports NFSv3 and NFSv4.
NFS service needs RPC service, which includes:
Now we will configure our nfs server supposed that ip is
sudo yum install -y nfs-utils rpcbind
The fortmat of nfs config file /etc/exports is like:
/path/to/shared client1_ip (options) [client2_ip(options)]
Suppose you want to expose the dirs to client1 with ip
192.168.0.3, the file is like:
If you wish all clients have rights to access to the server, you can make it by the following configure:
Caution: do not grant writing right to everyone.
mkdir -p /path/to/shared
sudo systemctl enable --now nfs-server
## exportfs -r will re-exports entries in /etc/exports
## install nfs-utils
sudo mkdir -p /local/path
The following is an example
sudo mount -t nfs -o rw,nosuid 192.168.0.2/opt/shared /opt/shared
This mounts /opt/shared on 192.168.0.2 to /opt/shared on local machine
If you want to mount at boot time, you can add the following line to
/etc/fstab, and backup
/etc/fstab before changing it:
remote_host:/path/to/shared /local/path nfs rw,nosuid 0 0
If you enable the firewalld service, you need to allow the nfs, mountd, rpc-bind services through the firewall.
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
Now you can access files on 192.168.0.2 from clients.