Saturday, 25 August 2012

How to setup NFS in RedHat and Solaris

NFS stands for Network File System, we can use it to share files between different computers.

In Redhat Linux, to share NFS, we need to configure /etc/exports, the format of exports is:
<directory to share>   <host>(<option>)
For example, if we want to share directory /data/forhost1 to host1, we can configure my /etc/exports like this:
/data/forhost1      host1
if we only want to grant read permission to /data/forhost1, we can add the ro option, ro stands for read-only
/data/forhost1     host1(ro)
Solaris uses a different configuration file /etc/dfs/dfstab for NFS.
If we want to share directory /data/forhost1 to host1, we can configure my /etc/dfs/dfstab like this:

share -F nfs -o ro=host1 -d "Readonly" /data/forhost1
For both RedHat Linux and Solaris, we need to restart the nfs service to make our configuration take effect, this can be done by using service or svcadm.

After we share /data/forhost1, we can mount it on host1:
if host1 is Redhat Linux
mount -t nfs server:/data/forhost1 /mnt/mynfs
if host1 is Solaris:
mount -F nfs server:/data/forhost1 /mnt/mynfs

To make the nfs mount permanent, we can configure /etc/fstab or /etc/vfstab to mount nfs on system start.