Network File System (NFS)
NFS, or Network File System, is a server-client protocol for sharing files between computers
on a common network. It is available on a variety of UNIX-based operating systems,
not just Linux. The server and client do not have to use the same operating system.
The client system just needs to be running an NFS client compatible with the NFS server.
RPM of Network File System (NFS)
If NFS rpm had already been installed. Use command.
[root@localhost ~]# rpm -qa | grep nfs
If your machine don’t have these rpm install these rpms.
RPM of NFS
If your machine don't have these rpm install these rpms.
Starting or stopping NFS service
[root@ server ~]# service nfs start
[root@ server ~]# service nfs stop
[root@ server ~]# service nfs restart
[root@ server ~]# /etc/init.d/nfs start
[root@ server ~]# /etc/init.d/nfs stop
[root@ server ~]# /etc/init.d/nfs restart
If you want service remain in effect after rebooting,
[root@ server ~]# chkconfig nfs on
First of all make the directory(s) that you want to share like this as shown in figure.
- I want to share /raj & /wisdom directories
directories for NFS
- Grant the permission
Permission for directories for NFS
- Configuration File for NFS
NFS servers have only one configuration file: /etc/exports.
This file lists the partitions that are sharable, the hosts they can be shared with, and with what permissions.
Here is the format of each entry in the /etc/exports file:
/wisdom client1(permissions) client2(permissions)
- /wisdom is the directory you want to share with other users.
- client1, client2 are the host names of the NFS clients. The wildcard
characters * and ? may be used.
- Permissions are the corresponding permissions for each client.(here permission not related to chmod)
- ro Files are read-only. No files may be written to (or newly created) on this
mount. This is the default
- rw Allow both read and write requests to this volume.
In all cases, use the sync option to ensure that file data cached in memory is automatically written to the disk after the completion of any disk data copying operation.
A backslash at the end of the line indicates that the entry continues on to the next line. Comments can be added by using a pound symbol (#) at the beginning of the line.
Understand NFS server by example step by step
Let us learn NFS working by example.
NFS at server side
Open the file /etc/exports
and write as shown in figure.
NFS server exports file
directory is shared by all clients with permission read only.
directory is shared by only 172.31.0.1/24 network with permission read and write.
Restart the service by using command
[root@server ~]# service nfs restart
Now I made two files for sharing as shown in figure.
NFS server file sharing
At client side NFS server
Client should be connected with server my client ip address is 172.31.0.1
If client want to check the which directories have been shared.
[root@clientside ~ ] # showmount -e ipaddress of server
Below figure would clear all the doubts.
NFS server -client side
If you want to use means read and write the files as per your permissions
First of all crate a directory then mount the server on that directory
To mount the server on that directory, use command
[root@clientside ~]# mount -t nfs ipaddress of server:/exports directory /directory
NFS server mounting directory
This is showing that client create a directory /game
and mount the export directory /raj
on client directory /game
Check the file by using ls- l
NFS server Client permission
If client has permission to write any file then he/she can create a file like this
NFS Client file creation
If you want to unmount the directory
Leave the directory then use command.
[root@clientside ~] umount server ip address
After use you should always unmount the NFS server.
Mount NFS server at the time of booting
In this way you can use shared folder. But this share folder will be available till system is up. It will not be available after reboot. To keep it available after reboot make its entry in /etc/fstab
Open the file
Make an extra entry in file as shown in figure.
NFS server at the time of booting
Red rectangle in figure is showing the new entry
First entry is ip address of server : export directory
Second entry /exp
is directory of client on which server would be mounted.
Third entry nfs type it is like partition type.
Third and fourth entry is same as above.
It is not good idea to have kept server mounting so long.
And also mount and umount the directory are become frustrating.
Using autofs to mount NFS file systems on demand
Recent improvements to auto-detecting and mounting removable devices have meant that
you can simply insert or plug in those devices to have them detected, mounted,
and displayed. However, to make the process of detecting and mounting remote
NFS file systems more automatic, you still need to use a facility such as autofs
. With the autofs
facility configured and turned on, you can cause any NFS shared directories to mount on demand. If you know the hostname and directory being shared by another host computer, you can simply change (cd) to the autofs
mount directory and have the shared resource automatically mount and be accessible to you.
The following steps explain how to turn on the autofs
- For automount the server we have to make two directories. One is physical but other is virtual.
- Make a new directory
[root@clientside ~]# mkdir /phy
- As root user from a Terminal window, open the /etc/auto.master file.
Make entry like this as shown in figure.
NFS server --/etc/auto.master
- Define the directory.
- Define auto.misc file in which we define our virtual directory.
- Inactivity timeout before which auto mounted directories are silently unmounted.
- Open the /etc/auto.misc file.
Add an extra line in the file as shown in the figure.
NFS server --/etc/auto.misc
- vir is virtual directory its real path is /phy/vir
- -rw--> read and write , soft--> software , intr--> execute .
- 192.168.0.3:/raj export directory
Restart the service
[root@clientside ~] # service autofs restart
Check the directory like this as shown in figure.
Accessing NFS directory