Before starting, make sure you have:
- Access to a root account or an account with sudo privileges.
- Stable internet connection.
- At least two systems running CentOS 7 for testing NFS functionality (one as the server, the other as the client).
Installation of NFS
The first step is to install the necessary packages for the NFS server. Open a terminal and run the following command for installation:
sudo yum install nfs-utils -y
After the installation completes, enable and start the NFS server services using the following commands:
sudo systemctl enable rpcbind
sudo systemctl start rpcbind
sudo systemctl enable nfs-server
sudo systemctl start nfs-server
sudo systemctl enable rpc-statd
sudo systemctl start rpc-statd
sudo systemctl enable nfs-idmapd
sudo systemctl start nfs-idmapd
Configuration of Sharing
Now it's time to configure the directories you want to share with NFS clients. Create a directory you want to share using the mkdir
command. For example:
sudo mkdir /var/nfs/share -p
Next, you need to edit the /etc/exports
file, which controls which directories are shared. Open this file in any text editor and add a line for each directory you want to share, along with information about who has access to the directory. For example:
/var/nfs/share 192.168.1.0/24(rw,sync,no_root_squash,no_all_squash)
In this example, /var/nfs/share
is the shared directory, and 192.168.1.0/24
is the network range allowed access. Options rw
, sync
, no_root_squash
, and no_all_squash
specify how the sharing will function.
After editing the /etc/exports
file, apply the changes by running:
sudo exportfs -arv
Firewall Configuration
To allow access to NFS services through the firewall, run the following commands:
sudo firewall-cmd --permanent --zone=public --add-service=nfs
sudo firewall-cmd --permanent --zone=public --add-service=mountd
sudo firewall-cmd --permanent --zone=public --add-service=rpc-bind
sudo firewall-cmd --reload
NFS Client Configuration
On the client, you need to install NFS packages and mount the shared directory. Installation is done in the same way as on the server. To mount the shared directory, use:
sudo mount -t nfs <nfs_server_ip>:/var/nfs/share /mnt
Replace <nfs_server_ip>
with the IP address of your NFS server.
You should now have a functioning NFS server that shares directories with clients on the network. NFS is a powerful tool for file sharing that can greatly simplify file management in a networked environment. It's important to always prioritize security and correctly configure access settings and the firewall to keep your data safe.