Practical: - 5
AIM
Page 1
INTRODUCTION
NFS (Network File System) is basically developed for sharing of files and folders between Linux/Unix systems by Sun Microsystems in 1980. It allows you to mount your local file systems over a network and remote hosts to interact with them as they are mounted locally on the same system. With the help of NFS, we can set up file sharing between Unix to Linux system and Linux to Unix system.
Benefits of NFS
1. NFS allows local access to remote files.
2. It uses standard client/server architecture for file sharing between all *nix based machines. 3. With NFS it is not necessary that both machines run on the same OS.
4. With the help of NFS we can configure centralized storage solutions. 5. Users get their data irrespective of physical location.
6. No manual refresh needed for new files.
7. Newer version of NFS also supports acl, pseudo root
NFS Services
It’s a System V-launched service. The NFS server package includes three facilities, included in
the portmap and nfs-utils packages.
1. portmap : It maps calls made from other machines to the correct RPC service
(not required with NFSv4).
2. nfs: It translates remote file sharing requests into requests on the local file system.
3. rpc.mountd: This service is responsible for mounting and unmounting of file systems.
Important Files for NFS Configuration
1. /etc/exports : It’s a main configuration file of NFS, all exported files and directoriesare defined in
this file at the NFS Server end.
2. /etc/fstab : To mount a NFS directory on your system across the reboots, we need to make an entry
in /etc/fstab.
3. /etc/sysconfig/nfs : Configuration file of NFS to control on which port rpc and other
IMPLEMENTATION
Installing nfs server and nfs client
We need to install NFS packages on our NFS Server as well as on NFS Client machine. We can install it via “yum” (Red Hat Linux) and “apt-get” (Debian and Ubuntu) package installers.
Page 2 STEP:
1) Disable firewall on Both Machines.
To Disable firewall write the following
command: Systemctl stop firewalld.service
2) Open terminal.
Find the IP address of both the PCs using ifconfig:
Server address: 10.10.104.55 / 10.10.105.58 Client address: 10.10.104.56 / 10.10.105.57
3) Check the connectivity of two pc using ping.
Ping server ip add/client ip add
4) Configure Server Side
For configure NFS on server side we need to edit 3 files:
hosts.allow
hosts.deny
exports
a) For hosts.allow:-
Write the following permissions in file. Client address is to be written. Whichever hosts we want to allow to access mounted services we write their IP address
portmap:10.10.104.56 lockd: 10.10.104.56 rquotad: 10.10.104.56 mountd: 10.10.104.56 statd: 10.10.104.56
b) For hosts.deny:-
portmap: ALL
Page 3
c) For exports:-
Save and exit all three files. To apply changes we made in exports file write this command: exportfs -a
This command is used to exports all directories which are mentioned in the export file.
Here different options are given to each mounted directories which are described as follows:
i. ro: To give read-only access to client. This is default permission.
ii. rw: To give read-write permission to client.
iii. sync: It confirms request to shared directories only once when changes are committed.
iv. no_root_squash: When it is selected, then root on the client machine will have the same
level of access to the files on the system as root on the server.
v. no_subtree_check: If only part of a volume is exported, a routine called subtree checking
verifies that a file that is requested from the client is in the appropriate part of the volume. If the entire volume is exported, disabling this check will speed up transfers.
5) Configure Client Side
To install portmap service use command: yum -y install portmap
6) Execute following commands on both machines:
These commands are used to start demons:
i) service nfs restart
ii) rpc.statd
iii) rpc.portmap
iv) rpc.mountd
v) rpc.nfsd
vi) rpc.lockd
vii)rpc.rquotad
Page 4
The following screenshot is of client side:
7) Check mounted directories from server
[root@localhost ~]# showmount -e
8) Check shared directories from client
[root@localhost ~]# showmount -e server_IP_address
9) Mount shared directories on client machine
To mount directory temporary use
command: mount \server_IP:shred_dir /client_dest_dir
To check mounted directories we use command: df -TH
Page 5 We need to add a single line at the end of file
i.e. server_ip:/shared_dir /client_dest_dir nfs defaults 0 0
[root@localhost ~]# vi /etc/fstab
10)Access Shared file from client
Some Basic Functions:
i) rpc.portmap: The portmap service is required to map RPC requests to the correct services.
RPC processes notify portmap when they start, revealing the port number they are monitoring and the RPC program numbers they expect to serve. The client system then contacts portmap on the server with a particular RPC program number. portmap then redirects the client to the proper port number to communicate with its intended service
ii) rpc.mountd: NFS mount daemon. The rpc.mountd program implements the NFS mount
protocol. When receiving a MOUNT request from an NFS client, it checks the request against the list of currently exported file systems. If the client is permitted to mount the file
system, rpc.mountd obtains a file handle for requested directory and returns it to the client.
iii) rpc.nfsd: NFS server process. The rpc.nfsd program implements the user level part of the NFS service. The main functionality is handled by the nfsd kernel module. The user space program merely specifies what sort of sockets the kernel service should listen on, what NFS versions it should support, and how many kernel threads it should use.
iv) rpc.statd: The rpc.statd server implements the NSM (Network Status Monitor) RPC protocol.
This service is somewhat misnomed, since it doesn't actually provide active monitoring as one might suspect; instead, NSM implements a reboot notification service. It is used by the NFS file locking service, rpc.lockd, to implement lock recovery when the NFS server machine crashes and reboots.
v) rpc.lockd: The rpc.lockd utility provides monitored and unmonitored file and record locking
services in an NFS environment. To monitor the status of hosts requesting locks, the locking daemon typically operates in conjunction with rpc.statd