Linux [ServerSupport]

Configuringring NFS(Network File System) Server - Linux

Required Package & Services for Server

In Red Hat Enterprise Linux, the nfs-utils package is required for full NFS support. Generally NFS will get installed by default. To check for instalation, run rpm -q nfs-utils to see if the nfs-utils is installed. If it is not installed and you want to use NFS, run the following command as the root user to install it:
Server@root:~$yum install nfs-utils
Also check the following are installed nfs-utils-lib, and portmap.

  • Required Services
  • nfs — ( /sbin/service nfs start) starts the NFS server and the appropriate RPC processes to service requests for shared NFS file systems.
  • nfslock — ( /sbin/service nfslock start) is a mandatory service that starts the appropriate RPC processes to allow NFS clients to lock files on the server.
  • portmap — accepts port reservations from local RPC services. These ports are then made available

In order for NFS to work with a default installation of Red Hat Enterprise Linux with a firewall enabled, IPTables with the default TCP port 2049 and protmap on 111 must be configured. Without proper IPTables configuration, NFS does not function properly.

Another way to check if NFS is functioning, use command rpcinfo -p and you should get as shown in below image.
#rpcinfo -p

You can also check the file "/proc/filesystems"

Configuring Exports file on Server

Server side file is "/etc/exports". In this file we need to add the required folder path to share the folder.
Few Common exports option are as bellow.

Commonly used export options.

Example Description
/projdata/proj1/ 192.168.11.5(rw,sync) Export nfs folder to host having ip address 192.168.11.5 with read write permission and synchronize.
/projdata/proj2/ 192.168.11.0/24(ro,sync) export /projdata/proj2 directory for network 192.168.11.0 having netmask 255.255.255.0 with read only permissions and synchronized mode
/projdata/proj3/ 192.168.11.100(rw,sync) 192.168.11.10(ro,sync) export /projdata/proj3 directory for host with IP 192.168.11.100 with read, write permissions, synchronized mode, and also export /projdata/proj3 directory for hosts with IP 192.168.11.10 with read only permissions and synchronized mode
/projdata/proj4/ 192.168.11.100(rw,sync,no_root_squash) export /projdata/proj4/ directory for host with IP 192.168.11.100 with read, write permissions, synchronized mode and the remote root user will be treated as a root and will be able to change any file and directory.
/projdata/proj5/ *(r0,sync) export /projdata/proj5 directory for any host with a read only permission and synchronized mode
/projdata/proj1/ *.nfsserver.org(ro,sync) export /projdata/proj1 directory for any host within nfsserver.org domain with a read only permission and synchronized mode
/projdata/proj2/ nfsclient1(rw,sync) export /projdata/proj2 directory for hostname nfsclient1 with read, write permissions and synchronized mode

Editing Export file

Open up your favorite text editor, for example, vim and edit /etc/exports file and add line /projdata/proj1 *(ro,sync) to export /projdata/proj1 directory for any host with read only permissions.

    $vim /etc/exports
    /projdata/proj1     *(ro,sync)
    ~
    ~
    ~
    :x ↲
    

Save the file and exit using the ":x" option. Need to be sure that the directory exported by NFS exists.

Restart NFS Daemon

Once the /etc/exports file is edited, need to restart the NFS Daemon if already running or you can just start the NFS Daemon to apply changes from /etc/exports file. Depending on your Linux distribution, the starting/re-starting of NFS daemon many differ.
Redhat/Centos/Fedora users:
# /etc/init.d/nfs start (or) /etc/init.d/nfs restart (or) root$ service nfs start / restart
Debain Users:
# /etc/init.d/nfs-kernel-server restart / start
If you later decide to add more NFS exports to the /etc/exports file, you will need to either restart NFS daemon or run command exportfs:
# exportfs -ra

NFS Client Configure

Mount remote file system on the client.

First need to create mount point
# mkdir /projdata/proj1
Be sure that NFS Client and mount point are ready, you can run mount command to mount exported NFS remote file system.
# mount -t nfs 192.168.11.20:/projdata/proj1 /projdata/proj1
Here -t option specify the type of file system. Now you should be able to see the files system is mounted.

Automount Configure on client

To make this completely available to users when they boot their PC, need to edit "/etc/fstab" file with your favorite editor and create a new line like this:
# 192.168.11.20:/projdata/projd1 /projdata/proj1 nfs defaults 0 0

To see shared folders on the NFS Server

To see the shared folders on NFS Server use showmount command.
# /usr/sbin/showmount -e <NFS Server IP address>
# /usr/sbin/showmount -e 192.168.11.20 ↲
/projdata/proj *.nfsserver.org,*.techsupport.com,192.168.11.0/24
/projdata/proj2 *.nfsserver.org,*.techsupport.com,192.168.11.0/24
/system/OSsetup/RHEL5.5 (everyone)
/system/OSsetup/RHEL5.4_64bit (everyone)