Learn how to configure the network file system (NFS) in Linux and HPUX servers. Howto export NFS, start/stop NFS services, and control access on it.
The network file system is one of the essential things in today’s IT infrastructure. One server’s file system can be exported as NFS over network and control access over it. Other servers can mount these exported mount points locally as an NFS mount. This enables the same file system making available to many systems thus many users. Let’s see NFS configurations in Linux and HPUX.
NFS Configuration file in Linux
We assume the NFS daemon is installed on a server and running in the background. If not check package installation steps and how to start service on Linux. One can check if NFS is running on the server with
ps -ef command. For NFS server i.e. server exporting directory should have portmap service running.
Make sure you have TCP and UDP port 2049, 111 on firewalls between client and server. It can be in OS firewall, iptables, network firewalls, or security groups in the cloud.
root@kerneltalks # ps -ef |grep -i nfs root 1904 2 0 2015 ? 00:00:08 [nfsd4] root 1905 2 0 2015 ? 00:00:00 [nfsd4_callbacks] root 1906 2 0 2015 ? 00:01:33 [nfsd] root 1907 2 0 2015 ? 00:01:32 [nfsd] root 1908 2 0 2015 ? 00:01:33 [nfsd] root 1909 2 0 2015 ? 00:01:37 [nfsd] root 1910 2 0 2015 ? 00:01:24 [nfsd] root@kerneltalks # service nfs status rpc.svcgssd is stopped rpc.mountd (pid 1897) is running... nfsd (pid 1913 1912 1911 1910 1909 1908 1907 1906) is running... rpc.rquotad (pid 1892) is running... root@kerneltalks # rpcinfo -p localhost program vers proto port service 100000 4 tcp 111 portmapper 100000 3 tcp 111 portmapper 100000 2 tcp 111 portmapper 100000 4 udp 111 portmapper 100000 3 udp 111 portmapper 100000 2 udp 111 portmapper ----- output clipped -----
/etc/exports is the configuration file which has all exported volume details along with their respective permissions.
/etc/exports follows the format as below :
<export> <host> (options)
- export is filesystem/directory to be exported
- the host is hostname/IP to which export is accessible where wile cards are acceptable
- options are permissions which are
Refer below chart which can be used to decide your entry in this file.
NFS config file parameters
| || |
|/my_share server3 (rw, sync)||Export /my_share directory for server3 with read write access in sync mode|
|/my_share * (ro, sync)||Export /my_share for any host with read only permission and sync mdoe|
|/my_share 10.10.2.3 (rw,async)||Export /my_share for IP 10.10.2.3 with rw in async.|
|/my_share server2 (ro, sync) server3 (rw, sync)||Exporting to two diff servers with diff permissions|
root@kerneltalks # cat /etc/exports /my_share 10.10.15.2(rw,sync) /new_share 10.10.1.40(rw,sync)
/etc/exports file can be edited using vi editor or using
How to start-stop NFS service in Linux
Once you made the changes in the file you need to restart NFS daemon to take all these changes in effect. This can be done using the service NFS restart command. If your NFS is already running and you just need to take a new configuration in action you can reload config using service NFS reload. To stop NFS you can run
service nfs stop command.
root@kerneltalks # service nfs status rpc.svcgssd is stopped rpc.mountd (pid 1897) is running... nfsd (pid 1913 1912 1911 1910 1909 1908 1907 1906) is running... rpc.rquotad (pid 1892) is running...
How to re-export NFS shares after editing the configuration file
In running the NFS environment, where multiple clients already mounted NFS shares from the NFS server and you need to edit NFS share configuration. You can edit the NFS configuration file and re-export NFS shares using
Make sure only additions happened to config file while reloading config otherwise it may affect already connected NFS shares.
root@kerneltalks # exportfs -ra
How to mount NFS share
At the destination, where export needs to be mounted should have NFS daemon running too. Mounting a share is a very easy two-step procedure.
- Create a directory to mount the share
- mount share using the mount command.
To make this permanent i.e. mounting share at boot time, make an entry to /etc/fstab like below so that manually mounting after the reboot of server can be avoided.
10.10.2.3:/my_share /tmp/nfs_share nfs defaults 0 0
NFS configuration in HPUX
This part is the same as Linux. In some versions, you need to edit
/etc/dfs/dfstab file. This file takes share commands as a per line entry. It can be filled like below :
share -F nfs -o root=server2:server3 /my_share
Above line indicates exporting
/my_share directory for
server3 with root account access.
Also, we need to specify
NFS_SERVER=1 parameter in /
etc/rc.config.d/nfsconf on the NFS server. By default, it is set to 0 i.e. server acts as NFS client. Along with this
START_MOUNTD needs to be marked to value 1 as well.
How to start-stop NFS service in HPUX
We have covered it here: NFS server start/stop on HPUX
For reloading config file in HPUX, you can run
This part is the same as Linux
Errors seen in Linux
If you did not prepare client properly then you might see below error :
mount: wrong fs type, bad option, bad superblock on 10.10.2.3:/mys_hare, missing codepage or helper program, or other error (for several filesystems (e.g. nfs, cifs) you might need a /sbin/mount.<type> helper program) In some cases useful info is found in syslog - try dmesg | tail or so.
nfs-common packages and you should be able to mount NFS filesystem without any issues.
Share Your Comments & Feedback: