This is a simple article detailing how to install NFS on CentOS/RHEL servers. NFS is used to share a directory between several Linux systems. It allows remote hosts to mount file systems over a network and interact with those file systems as though they are mounted locally on your system.
(Recommended Read: Learn to use Wget command with 12 examples)
Scenario Setup
To install & test the shared folder, we require at least 2 machines:-
- NFS Server with IP Address: 192.168.1.100
- Client machine to test the setup with IP Address: 192.168.1.101
NFS Installation
Firstly we will install NFS, which is easy & can be installed using the following command
# yum install nfs* -y
now, we need to start our server
# service nfs start
# chkconfig nfs on
Configuration
Now, we will share a directory, lets share our home (/home) directory. Open the configuration file
# vi /etc/exports
since its an empty file, we will the following lines to the file to share /home folder
/home 192.168.1.0/24 (rw,sync)
S0, the above line means
/home is the directory to be shared,
192.168.1.0/24 will be the subnet range for which the shared folder will be available, you can just mention a single IP here,
rw means the client will have both read & write permissions. You can also use ro for read-only.
Now, restart the service to implement changes to the server,
# service nfs restart
Our shared folder is now ready to be used.
Note: If we are giving rw (read, write) settings on nfs share, make sure the permissions on the folder are 777.
Testing shared folder
On the Server, use the following command to show the shared folder
# mountfs -V
& on the client-side, use the following command to see the shared folder
# show mount -e 192.168.1.100
Client-side configuration
On the Client-side, we will have to firstly install nfs
# yum install nfs* -y
we will now mount the shared folder to /mnt
# mount 192.168.1.100:/home /mnt
so the above command will mount the shared folder, which we can use as a regular partition. But this will only be a temporary mount i.e. when we restart our system, our mount will be lost.
Therefore in order to permanently mount the shared folder, we need to make an entry in /etc/fstab
# vi /etc/fstab
After opening fstab, make the following entry at the bottom of the file,
192.168.1.100:/home /mnt nfs defaults 0 0
& drive will remain mounted even after the system reboot.
Important commands which might come handy,
- showmount -e : Shows the available shares on your local machine
- showmount -e <server-ip or hostname>: Lists the available shares at the remote server
- showmount -d : Lists all the subdirectories
- exportfs -a : Exports all shares listed in /etc/exports, or given name
- exportfs -v : Displays a list of shares files and options on a server
- exportfs -r : Refresh the server’s list after modifying /etc/exports
- exportfs -u : Unexports all shares listed in /etc/exports, or given name
and in our future tutorials, we will also be discussing VSFTP (very secure FTP) server & Samba server.
So, if you have any questions/comments about this tutorial on NFS installation & configuration, please write them down below. I will surely address them.