NFS(Network File System) developed by Sun Microsystem, for sharing the files and directories between the UNIX/Linux systems.NFS it allows you to mount your local filesystems over a network and also remote server to interact with them as they are mounted locally on the same system
NFS is purely based on the RPC(Remote Procedure Call) which allows the client to automatically mount the remote filesystems.
Advantages of NFS:
1.No manual refresh needed for new files
2.With this NFS it is Not necessary that both the machines run on the same OS
3.secured with firewall and Kerberos
4.Files may be accessed via IP addresses, groups, users etc
5.The central management of this system would cut the workload by 80%
1.The greatest disadvantages are the issue of security because NFS is based on RPC, remote procedure calls, it is inherently insecure and should only be used on a trusted network behind a firewall.
Let us see some of the important services that are needed for NFS
1.nfs = It translates remote file sharing requests in to request on the local filesystem
2.rpc.mountd = This service is responsible for mounting and unmounting the filesystems
Configuration files for NFS:
1./etc/exports = Important configuration file for NFS, all exported files and directories are defined in this file at the NFS server end.
2./etc/fstab = To mount the NFS share resources automatically on system reboots, we need to manually put an entry inside this file
3./etc/sysconfig/nfs = Configuration file for NFS to control on which port RPC and other services are listening
Check NFS daemon is listening on both UDP and TCP port 2049:
#rpcinfo -p |grep nfs
From the above output, it is confirmed that NFS server is running and accepting calls on port 2049.
Check whether your system supports NFS or not:
#cat /proc/filesystem |grep nfs
Note: If you don’t see any output means NFS is not supported or NFS module have not been loaded in to your kernel
To load the NFS module:
When everything is installed correctly, the NFS daemon should be now listening on both UDP and TCP 2049 port and the portmap should be waiting for instructions on a port 111
Check portmap is listening or not
#rpcinfo -p |grep portmap
Configure NFS server:
1.NFS server: hostname=linuxvasanth.com, IP address 10.250.1.100
2.NFS Client: hostname: Dataserver, IP address=10.250.1.50
As I said above for sharing the directory we need to make an entry in “/etc/exports configuration file.In this example, i will share a directory name “myshare” in “/” partition to share with the client-server
Create some files and directories inside this directory
#cd /myshare #touch doc1 doc2 doc3 #mkdir d1 d2 d3
Now /myshare directory is having three files and three subdirectories.
Step:1 Make an entry in “/etc/exports” to make the directory shareable
#vi /etc/exports /myshare 10.250.1.50(rw,sync) :wq!
The above entry says the directory myshare from “/” is being shared with the client IP 10.250.1.50 with read and write permission with the sync option.You can also use the hostname in place of the IP address.
NFS sharing options:
ro = can provide read-only access to the shared files,i.e the client can only able to read
sync: It confirms the requests to the shared directory only once the changes have been committed
no_subtree_check = It prevents the subtree checking when a shared directory is the subdirectory of the larger filesystem, NFS performs scans of every directory above it, in order to verify its permissions and details, disabling the subtree check may improve the performance of NFS but it reduces security
Note: The default behavior of NFS kernel daemon is to include additional option to export your line which is “no_subtree_check”
Step:2 Restart the NFS daemon
Once you have edited /etc/exports file you need to restart the NFS daemon to apply any changes
Note: Depending upon your Linux distribution restarting procedure for NFS daemon may differ
To restart the NFS service
#service nfs restart
To restart the RPC bind service
#service rpcbind restart
NFS and rpcbind are compulsory services for NFS daemon
rpcbind = Remote procedure call(RPC) service is controlled by rpcbind service
To list the NFS shared directories locally and remotely:
If this command shows error then the communication might be blocked by the firewall.
Configuring NFS client:
Now at the NFS client end, we need to mount that directory on our server to access it locally, to do this first we need to find out the shares available on the NFS server.
To mount the shared NFS directory
#mount <option> <NFSserver IP>:<NFS shared directory path> <mount point directory path at NFS client>
To view the shared resources from NFS server:
#showmount -e <NFS server IP> #showmount -e 10.250.1.100
from the above output, one directory is shared in NFS server
Create a new mount point directory:
Now mount the NFS share directory to your local mount point directory as follows,
#mount -t nfs 10.250.1.100:/myshare /data
To check the mounted files
As you can see from the above output the shared directory from NFS server has been successfully mounted on NFS client at the location /data
To remove the NFS mount
The following services are associated with NFS daemons and each service have its script files in init.d directory
1./etc/init.d/nfs =This is the main control script for NFS daemons which controls NFS services
2./etc/init.d/nfslock = Script for lock files and statd daemon, which locks and provides the status of files those are currently in use
3./etc/init.d/rpcbind = RPC program number converter
4./etc/init.d/rpcgssd = script for RPC related security services
Note: If you want to start a script manually you can execute by using the following syntax
#/etc/init.d <script-name> Ex: /etc/init.d/nfs
If you found this article useful, Kindly Subscribe here 👉🏿👉🏿 Click this link to Subscribe
Never miss an article Do like my official FB page 👉🏿 Learn Linux in an easier way