Friday, January 3, 2014

HOWTO NFS Mount Using Exportfs

Network File System (NFS) is a distributed file system protocol originally developed by Sun Microsystems in 1984, allowing a user on a client computer to access files over a network much like local storage is accessed.

Here are some tips for a daily use of NFS:

1. To export a directory to a remote machine, do the following:
exportfs REMOTEIP:PATH

where:
    REMOTEIP – IP of the remote server to which you want to export.
    PATH – Path of directory that you want to export.

For example:
root@anneke:~# exportfs 192.168.3.0/255.255.255.0:/nfs_export/test

2. To mount the remote file system on the local server, do the following:
mount REMOTEIP:PATH_ORIGIN PATH_DEST

For example:
root@anneke:~# mount 192.168.3.0/255.255.255.0:/nfs_export/test /mnt/test

where:
    REMOTEIP – IP of the remote server which exported the file system
    PATH_ORIGIN – Path of directory which you want to export.
    PATH_DEST - Path on the local server where you want to mount the export

3. Unmount Remote File System
You can un-mount the remote file system mounted on the local server using the normal umount PATH. For more option refer to umount command examples.

For example:
root@anneke:~# umount /mnt/test

4. Unexport the File System
You can check the exported file system as shown below.

root@anneke:~# exportfs
/nfs_export/test

                192.168.3.0/255.255.255.0

To unexport the file system, use the -u option as shown below:
exportfs -u REMOTEIP:PATH

For example:
root@anneke:~# exportfs 192.168.3.0/255.255.255.0:/nfs_export/test

After unexporting, check to make sure it is not available for NFS mount as shown below.

root@anneke:~# exportfs

5. Make NFS Export Permanent Across System Reboot
Export can be made permanent by adding that entry into /etc/exports file.

root@anneke:~# cat /etc/exports
/nfs_export/test       192.168.3.0/255.255.255.0


6. Make the Mount Permanent Across Reboot
Mount can be made permanent by adding that entry into /etc/fstab file.

root@anneke:~# cat /etc/fstab
192.168.3.6:/nfs_export/test    /mnt/test   ext4    noauto,vers=3,nolock,noatime,port=2049,proto=udp   0 0


(Options on the fstab depends on your system and what you need them for! You can always use "defaults" options :) )