NFS client and server handy commands

In case you are using NFS server, here are some handy commands you can use while working in production. These were tested in Ubuntu Linux.

Install nfs server

To install nfs server

$ sudo apt-get install nfs-common 
$ sudo apt-get install nfs-kernel-server 

Add the following line to /etc/hosts.allow

rpcbind mountd nfsd statd lockd rquotad :

export a directory

Create the directory to be exported.

$ sudo mkdir -p /myexport/dir1 

Add the following line to /etc/exports

/myexport/dir1 *(rw,sync,no_subtree_check,no_root_squash)

Note that this will allow any client to mount the exported directory on server if port 2049 is accessible from client to server. You may want to set appropriate client IPs here.

Now run the following to export the directory:

$ exportfs -ar

show what exports are available on a server

Use showmount to show what exports are available on localhost

showmount -e localhost

show what exports are available on a server from client

Use showmount on client machine to show what exports are available from nfs server

showmount -e
Export list for
/myexport/dir1 *

Mount directory from client

Mount directory from client

$ mkdir -p /mnt1/
$ mount -t nfs /mnt1/

Displaying clients connected to server

Use netstat to list all connections and grep for NFS port.

MYIP=`ifconfig eth0 | grep "inet addr:" |awk -F":" '{print $2}' | awk '{print $1}'`
$ netstat -an | grep $MYIP:2049
tcp        0      0       ESTABLISHED

Note: In case you want to automount the file during startup, add the following line in /etc/fstab /mnt1/ nfs rw

After that mount and unmount can be done directly using

mount /mnt1/
umount /mnt1/
Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit


Click here to write/view comments