Wednesday, April 21, 2010

Setting up NFS Server on Linux

Steps to setup the NFS server on RHEL 5 Linux:
For details you can refer to http://nfs.sourceforge.net/.
1. Check if NFS is not already running by typing the command: rpcinfo -p

# rpcinfo -p
program vers proto port
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100024 1 udp 895 status
100024 1 tcp 898 status
100011 1 udp 725 rquotad
100011 2 udp 725 rquotad
100011 1 tcp 728 rquotad
100011 2 tcp 728 rquotad
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100021 1 udp 32774 nlockmgr
100021 3 udp 32774 nlockmgr
100021 4 udp 32774 nlockmgr
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100021 1 tcp 54361 nlockmgr
100021 3 tcp 54361 nlockmgr
100021 4 tcp 54361 nlockmgr
100005 1 udp 791 mountd
100005 1 tcp 794 mountd
100005 2 udp 791 mountd
100005 2 tcp 794 mountd
100005 3 udp 791 mountd
100005 3 tcp 794 mountd

If the output looks something similar to above then NFS service is already running and you may need to just restart it in case you are modifying the /etc/exports file. If you don't see the nfs service being printed as output of command rpcinfo -p then follow the next steps.

2. Create a /etc/exports file (if not already present). For details and other examples refer to the man exports documentation.

Format for entries in this file is:
/directory/to/share nfs_client_host(options)

Following entry is only good for testing purposes (as it is insecure).
----- edit start -----
/vm_share *(rw,insecure)

----- edit end ------

3. Now run the below command to export all the directories.

$ /usr/sbin/exportfs -a

4. Restart the nfsd from the /etc/init.d script file. This may vary across distributions of linux. In case of RHEL 5, this file happens to be /etc/init.d/nfs. Pass it the option to start or restart.

5. Again verify that rpcinfo -p now prints nfs service too (as shown above).

Now you can use any NFS client to access the shared NFS directory /vm_share on the linux host.

No comments: