Configuring NFS on Linux


Installing NFS Server and NFS Client


We need to install NFS packages (nfs-utils and nfs-utils-lib ) which contains all required NFS services  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.

[root@nfsserver ~]# yum install nfs-utils nfs-utils-lib

[root@nfsserver ~]# yum install portmap (not required with NFSv4)

Start the services on both machines and enable auto start at boot time.

[root@nfsserver ~]# /etc/init.d/portmap start

[root@nfsserver ~]# /etc/init.d/nfs start

[root@nfsserver ~]# chkconfig --level 35 portmap on

[root@nfsserver ~]# chkconfig --level 35 nfs on



Setting Up the NFS Server for file sharing

Configure Export directory


For sharing any directory with NFS we have to make an entry in “/etc/exports” configuration file. For example we have to share a directory /nfsdir

Edit the /etc/exports and make an entry with ip of client to whom we want to share an options (more detail about options ).

[root@nfsserver ~]# vi /etc/exports

/nfsdir 192.168.1.101(rw,sync,no_root_squash)


Setting Up the NFS Client


After configuring the NFS server, we need to mount that shared directory or partition in the client server.

Mount Shared Directories on NFS Client

To find out the shares available on NFS Server use showmount command with server IP.

[root@nfsclient ~]# showmount -e 192.168.1.100

Export list for 192.168.1.100:

/nfsdir 192.168.1.101

Mount Shared NFS Directory


To mount that shared NFS directory we can use following mount command.

[root@nfsclient ~]# mount -t nfs 192.168.1.100:/nfsdir /mnt/nfsfolder

The above command will mount that shared directory in “/mnt/nfsfolder” on the client server. You can verify it following command.

To mount an NFS directory permanently on your system across the reboots make an entry in /etc/fstab file as below.

[root@nfsclient ~]# vi /etc/fstab

192.168.1.100:/nfsdir /mnt/nfsfolder nfs default 0 0



Important commands for NFS Server.


showmount -e : Shows the available shares on your local machine

showmount -e <server-ip or hostname>: Lists the available shares at the remoteserver

showmount -d : Lists all the sub directories

exportfs -v : Displays a list of shares files and options on a server

exportfs -a : Exports all shares listed in /etc/exports, or given name

exportfs -u : Unexports all shares listed in /etc/exports, or given name

exportfs -r : Refresh the server’s list after modifying /etc/exports



More on NFS

No comments: