NFS server stands for Network File Sharing Server.
Basically in this, we create a machine as server, and select some folders, which we want to use from any machine in the same network.
So if you share a Folder named ‘Linux Servers’, we just need to mount it on the client’s pc, and he can use it any time, from his local machine. If you make an entry of this share in fstab, each time your machine boots, it will mount it automatically. So you can access that folder when you want.
So lets check out the steps to make configure NFS Server and Client. First we will create the NFS Server and then mount it on Client’s machine.
Server Side.
Yum install nfs* -y
Install all packages associated withnfs using yum or apt-getmkdir /srv/foldername
Make the folder you want to share. If it already exists, skip this step.chmod 0755 /srv/foldername
Change the permissions of the newly created folder or the folder you’re sharing. (in the next line, I am Just copying some files into that newly created folder.)vim /etc/exports
open the exports file. When you install NFS, it automatically creates an ‘exports’ file in ‘/etc’ In this exports file you describe your sharing folder and their permissions.- /share folder1 (properties)
/share folder2 (properties)
This is the main part of your configuration. if you get this wrong, either there will be no sharing, or the shared folders wouldn’t open properly. The format to define sharing is :
‘path of folders to be shared’ IP/users (properties)
If you need a whole subnet of IP to use that folder, or a particular IP, or a range of IP, you can define it here. If you want to share it with particular users on network, enter their hostnames.
Properties
ro = read only access
rw= read and write access
sync = will keep syncing the folder (If Shared folder is updated.)
no_subtree_check : Increases the speed of transfer if large folder is shared.
insecure : Tells the NFS server to use unprivileged ports (ports > 1024).
Sample Output :Here, I am allowing any IP between 192.168.0.0-192.168.0.255 to read or write my share.
/etc/init.d/nfs restart
Restart the service.
Client Side.
Lets look at the configuration on the client side. Make sure, you have installed ‘nfs-common’ package on client.
showmount -e [ip address of server]
‘Show mount -e ‘ is used to check the mounting properties of a server. If you’re in the same network, and you can ping the server, it will show the shared folders and users/IP it is accessible to.
Sample Output :mkdir /mnt/share1
Create a new folder where you want the server’s shared folders to be mounted. Skip this, if you want to mount it on an already existing directory. Since you can see the server has 2 shared Directories, So create two new directories, with the same name, to avoid confusion.
Sample Output :mount [source] [destination]
Now you have the directories, where you need to mount those shared folders, so time to mount it. My server’s Ip is 192.168.0.107, so ‘mount 192.168.0.107:/home’ is the source and ‘/mnt/nfs/home’ is the destination in my machine.
Sample Output :- Check if the shared folders are mounted.
Sample Output :
If you need to add it in fstab :
192.168.0.107:/home /mnt/nfs/home nfs rw 0,0