CentOS – Configure a basic NFS – Part 1

NFS allows users to access files over the network as if the files are stored locally on the client’s machine. This is a basic how to on how to setup NFS on CentOS.

Step 1: Install NFS

In order to instal and configure NFS  the required software type

yum install nfs-utils nfs-utils-lib

yum install system-config-firewall

 

Step 2: Enable NFS on the appropriate run levels

chkconfig – -levels 35 nfs on

 

Step 3: Start RPCBIND and NFS service

/etc/init.d/nfs start

/etc/init.d/rpcbind start

 

Step 4: Create the NFS drive on your NFS server

The directory below can be located and named in whatever location you wish.

mkdir /home/nfs_shares

 

Step 5: Export your drive

vi /etc/exports

enter the full path of your drive.

/home/nfs_shares *(rw)

The following options can be passed
The asterisk allows for all IPs to enter.
The rw option gives read and write permissions.
The ro option optionally will give read only permission.

Then you will have to export your drives by typing as root:

export -a

exportfs -a

 

You can view your new mount points on the server by typing

showmount -e  enter_ip_of_your_server

 

Step 6:Edit your hosts.allow and hosts.deny files

The hosts.allow will access to the hosts, addresses listed.

The hosts.deny will deny access to all hosts, addresses listed besides those listed in the hosts.allow file.

– In your Hosts.allow enter

portmap: An_IP_Address or range of a IP_Addresses. Example (portmap: 10.0.0.2/24)
lockd: An_IP_Address or range of a IP_Addresses. Example (portmap: 10.0.0.2/24)
mountd: An_IP_Address or range of a IP_Addresses. Example (portmap: 10.0.0.2/24)
rquotad: An_IP_Address or range of a IP_Addresses. Example (portmap: 10.0.0.2/24)
statd: An_IP_Address or range of a IP_Addresses. Example (portmap: 10.0.0.2/24)

– In your Hosts.deny enter

portmap: ALL
lockd: ALL
mountd: ALL
rquotad: ALL
statd: ALL

This tells the operating system to deny all access to hosts besides the ones listed in the allow configuration file.

Step 7: Configure your firewall

As root type system-config-firewall.

Scroll down until you find the NFS service and check it and save your changes.

Step 8: Edit your /etc/sysconfig/nfs file and uncomment the following lines

LOCKD_TCPPORT=32803
LOCKD_UDPPORT=32769
MOUNTD_PORT=892
STATD_PORT=662

Restart nfs by executing

/etc/init.d/nfs restart
/etc/init.d/nfslock restart

7) Setup your client machine

On the client machine you will have to use root or sudo to mount the NFS directory. First of all you will need to create a mount point to the client machine and you can do that by typing

mkidr /some_folder/wherever/you/want

To mount it you will have to type the following from your client machine.

mount IP_address_of_your_NFS_Server:/the_directory/that_is/listed/in_your/exports_file  /folder/your_created/on_client_box

So for example if on your NFS server called Penguin you have pointed /home/nfs_shares as your NFS drive and you have created on the client machine the folder /home/shares that will serve as a mount point the command above will be like this on your client machine:

mount penguin:/home/nfs_shares   /home/shares

 

Note that if you reboot your client machine you will lose the mount. In order to setup the NFS drive to be mounted automatically you will have to edit your fstab file. This will be covered on another tutorial which will go into detail about the fstab file.

 

 

Share Button

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload the CAPTCHA.