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 and NFS client, 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@]# pwd
[root@]# ls -l
total 0
-rw-r--r-- 1 root root 0 Sep  6 14:08 nfs_server_file.txt
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@]# chmod 777 /export/NFS-Server/share/
[root@]# 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)
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@]# /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@]# /etc/init.d/nfs start
Starting NFS services:                                     [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
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
[root@]# pwd
[root@]# mkdir -p /export/NFS-Client/share
[root@]# ls -l /export/NFS-Client/share/
total 0
[root@]# mount /export/NFS-Client/share/
[root@]# cd /export/NFS-Client/share/
[root@]# ls -l
total 0
-rw-r--r-- 1 root root 0 Sep  6 17:38 nfs_server_file.txt
[root@]# touch new-file.txt
[root@]# 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@]# umount -f /export/NFS-Client/share/
[root@]# ls -l /export/NFS-Client/share/
total 0

No comments:

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