Monday, January 12, 2009

How to setup Network File System (NFS)?

NOTE: This document does not provide in depth about the configuration file. Also, Please note that installing required modules/packages is not the scope of this document. I will try to provide different article about configuration of /etc/exports (now available here), /etc/sysconfig/nfs and available mount options.

What is NFS?

Network File System (NFS) allows mounting the file system of Remote machine as if it is local file system.

How to Setup an NFS Server?

1. On both NFS Server and Client, make sure your kernel has nfs support. To check

$ cat /proc/filesystems
minix

ext2
msdos
nodev proc
nodev nfs

If you donot see nfs, you have to compile your own kernel with NFS enabled, or have to load the kernel module if your NFS support was compiled as a module.

2. Portmapper – To offer NFS service, portmapper (or rpc.portmap) should be running before starting NFS daemons. To start manually, run rcportmap start.

To check whether portmapper is running or not, run rpcinfo –p. If it is running, you can see portmapper daemon, its version, protocol and port numbers as follows:

$ rpcinfo -p
program vers proto port
100000 2 tcp 111 portmapper
100000 2 udp 111 portmapper
100003 2 udp 2049 nfs
100003 3 udp 2049 nfs
100003 4 udp 2049 nfs
100003 2 tcp 2049 nfs
100003 3 tcp 2049 nfs
100003 4 tcp 2049 nfs
100024 1 udp 32770 status
100021 1 udp 32770 nlockmgr
100021 3 udp 32770 nlockmgr
100021 4 udp 32770 nlockmgr
100024 1 tcp 32769 status
100021 1 tcp 32769 nlockmgr
100021 3 tcp 32769 nlockmgr
100021 4 tcp 32769 nlockmgr
100005 1 udp 644 mountd
100005 1 tcp 645 mountd
100005 2 udp 644 mountd
100005 2 tcp 645 mountd
100005 3 udp 644 mountd
100005 3 tcp 645 mountd

3. Make necessary configuration such as directory to be shared, hosts allowed to use the shared directories and other options in /etc/exports. Addition to that, you may configure such as number of nfs threads required at /etc/sysconfig/nfs


4. Start nfsserver from /etc/init.d, which start all required daemons (rpc.nfsd, rpc.lockd, rpc.statd, rpc.mountd, rpc.rquotad). You may also start these daemons one by one manually.

How to Setup an NFS Client?

To begin using machine as an NFS client, you will need the portmapper running on that machine, and to use NFS file locking, you will also need rpc.statd and rpc.lockd running on both the client and the server

To mount from command line, run as follow (master.foo.com is nfs server, home is the shared folder on that server. /mnt/home is the local mount point):

# mount master.foo.com:/home /mnt/home

To automate this while booting, add an entry as below in /etc/fstab file:
# device mountpoint fs-type options dump fsckorder
...
master.foo.com:/home /mnt nfs rw 0 0
...


Related topic - How to setup NFS Configuration files (/etc/exports)?

2 comments:

Breathing Linux said...

How to see shared folder in NFS Server from NFS Client?

showmount -e ip_address_of_NFS-Server

- Sikkandar.Linux at Gmail.Com

Linux Made Easy by Sikkandar said...

When trying to mount shared NFS folder from client, got "RPC: Timed out"

Noticed that NFS server trying to resolve client's IP to domain i.e rDNS. After adding client's IP in /etc/hosts of NFS server, I was able to mount shared folder.

This may not be the exact solution for "RPC: Timed out", but resolved for me.

Sometimes, you may need to allow client's IP in /etc/hosts.allow file to resolve this issue.

Sikkandar.Linux at Gmail.Com