How to configure the NFS Share on CentOs

1. Ensure that both client & server had installed the NFS.

2. You can check if the NFS package has been installed by calling the following Linux command:

# rpm -q nfs-utils

3. If there is no NFS package had been installed (Normally, it should be already installed when the CentOs had been set up). Then you can install it by the following Linux command:

# yum install nfs-utils nfs-utils-lib portmap system-config-nfs

4. Start the NFS server by the following Linux command:

#  service nfs start

5. At this stage, you should have the NFS running in both server and client sides.

For an example:
* NFS Server: server.example.com, IP address: 192.168.0.100
* NFS Client: client.example.com, IP address: 192.168.0.101

6. Let says you want to make the directory /home/testnfs in the server(192.168.0.100) to be accessible from the client(192.168.0.101).

On the NFS Server Side (step7 - 9):

7. So, you must “export” it on the server by editing the /etc/exports.

# vi /etc/exports

8. Then, append the following line of codes at the bottom of the file -> /etc/exports.

/home/testnfs  192.168.0.101(rw,sync,no_root_squash) 

[Note : The no_root_squash option makes the /home/testnfs to be accessed as root.]

9. To make the changes in /etc/exports taking effect, please issue the following Linux command:

# exportfs -a 

On the NFS Client Side (step10 - 13):

10. Let says you want to mount the directory /home/testnfs on the server to the directory /home/testnfs_client on the client. Then, you can issue the following Linux command:

# mount -t nfs 192.168.0.100:/home/testnfs /home/testnfs_client

11. That’s all for configuring the NFS share in CentOs. You should now see the NFS shares in the outputs of the following commands:

# df -h

OR

# mount

12. To unmount the NFS share of the directory /home/testnfs_client to the NFS server, you can issue the following command:
# umount -t nfs /home/testnfs_client

13. Finally, instead of mounting the NFS shares manually on the client, you could modify /etc/fstab so that the NFS shares get mounted automatically when the client boots.

192.168.0.100:/home/testnfs  /home/testnfs_client  nfs   rw,sync,hard,intr  0     0

November 20th, 2008 @ 07:54 PM • Filed under Linux