Installing an NFS file server on linux mainly consists of three short steps: install the NFS package, then configure (or in another words export) the NFS shares and lastly set the built-in firewall to allow incoming NFS queries.
1. Install NFS on CentOS
# The nfs-utils package contains the nfs server, also the client binaries yum install -y nfs-utils # Start and enable the NFS services systemctl start nfs-server rpcbind systemctl enable nfs-server rpcbind
# Create the directory that will be exported as NFS share mkdir /NFSShare # Set read-write access for Everyone on it chmod 777 /NFSShare # Export the directory as NFS share, add the following line to the /exports file vi /etc/exports
The /etc/exports file:
*: allow all hosts to connect to the share. If you want to specify different rules for different clients, simply create a separate line for each, using the IP address of the client instead of the asterisk character /NFSShare: the shared directory that will be remotely accessible rw: writable permission to the folder sync: all changes to the files are flushed immediately to disk. This makes the process a little slower, but more stable no_root_squash: root on the client machine will have root access on the NFS shared files instead of handled as user 'nobody'
# Re-export the NFS shares after editing the /etc/exports file exportfs -r
3. Allow NFS on the server's firewall
NFSv4 uses only one port 2049/tcp that makes if easy to configure the firewall on the linux server. On the other hand, NFSv3 also needs 111 tcp and upd, and higher ports also be opened, to open them we issue the following commands:
# Firewall rules for NFSv4 firewall-cmd --permanent --add-service nfs firewall-cmd --reload # Firewall rules for NFSv3 firewall-cmd --permanent --add-service nfs firewall-cmd --permanent --add-service mountd firewall-cmd --permanent --add-service rpc-bind firewall-cmd --reload
# Mount the NFS share using nfs version 4 (default) [root@client ~]# mount -t nfs -o vers=4 10.0.1.200:/NFSShare /NFSmounted # Mount the NFS share using nfs version 3 (older, but required by legacy systems) [root@client ~]# mount -t nfs -o vers=3 10.0.1.200:/NFSShare /NFSmounted
Comments