Setting up an NFS share on Linux

Tuesday, September 7, 2010

In this post, we will see how to setup an NFS share in linux and access remote directories shared from the NFS server from an NFS client machine.

Assuming that you have an NFS server with an IP 10.5.150.1 and NFS client 10.5.150.2, the steps to share and access the NFS shared directory is as follows.

1. Lets assume that the NFS directory you want to share is /export/NFS-Server/share in the NFS server box.
[root@10.5.150.1]# pwd
/export/NFS-Server/share
[root@10.5.150.1]# ls -l
total 0
-rw-r--r-- 1 root root 0 Sep  6 14:08 nfs_server_file.txt
[root@10.5.150.1]#
2. If you want to grant read/write permissions for this directory, then edit /etc/exports and add the directory entry you want to share with the read/write permissions as shown below.
[root@10.5.150.1]# chmod 777 /export/NFS-Server/share/
[root@10.5.150.1]# cat /etc/exports
# Generated by Allstart on Wed Sep  1 04:53:40 2010
/export/NFS-Server/share   *(rw)
# Put custom additions below (Do not change/remove this line)
[root@10.5.150.1]#
Note: You can additionally configure the /etc/hosts.allow and /etc/hosts.deny for increased security for the NFS share, but those details are outside the scope of this article.

3. Once the directory is shared in the NFS server, restart NFS service for the share to be active.
[root@10.5.150.1]# /etc/init.d/nfs stop
Shutting down NFS mountd:                                  [  OK  ]
Shutting down NFS daemon:                                  [  OK  ]
Shutting down NFS quotas:                                  [  OK  ]
Shutting down NFS services:                                [  OK  ]
[root@10.5.150.1]# /etc/init.d/nfs start
Starting NFS services:                                     [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
[root@10.5.150.1]#
4. Now the NFS share can be accessed from the client system which can be mounted to the shared directory on the NFS server.

(Assuming that the directory is mounted on /export/NFS-Client/share on the NFS client 10.5.150.2)
[root@10.5.150.2]# pwd
/
[root@10.5.150.2]# mkdir -p /export/NFS-Client/share
[root@10.5.150.2]# ls -l /export/NFS-Client/share/
total 0
[root@10.5.150.2]# mount 10.5.150.1:/export/NFS-Server/share/ /export/NFS-Client/share/
[root@10.5.150.2]# cd /export/NFS-Client/share/
[root@10.5.150.2]# ls -l
total 0
-rw-r--r-- 1 root root 0 Sep  6 17:38 nfs_server_file.txt
[root@10.5.150.2]# touch new-file.txt
[root@10.5.150.2]# ls -l
total 0
-rw-r--r-- 1 65534 65534 0 Sep  6 17:40 new-file.txt
-rw-r--r-- 1 root  root  0 Sep  6 17:38 nfs_server_file.txt
[root@10.5.150.2]# umount -f /export/NFS-Client/share/
[root@10.5.150.2]# ls -l /export/NFS-Client/share/
total 0
[root@10.5.150.2]# 

No comments:


Copyright © 2016 Prasanna Seshadri, www.prasannatech.net, All Rights Reserved.
No part of the content or this site may be reproduced without prior written permission of the author.