Install NFS server on CentOS

Network FileSystem (NFS) is created by Sun company. It provide you a service to share files between different machine via network. It is similar with Samba which I mentioned before. But the transport speed is faster than Samba. Because it does not need user to type account and password. The server has white list to allow legal IP to login to access files directly.

Install server is very easy. We just use yum command to find necessary libraries and install automatically.
[nick1811@NAS ~]$ sudo yum install nfs-utils nfs-utils-lib
Create white list. We allows all IP in subnetwork(192.168.0.*). And all users have access right for read and write.
[nick1811@NAS ~]$ vim /etc/exports
/home/nick1811/Shared_Folder 192.168.0.1/24(rw)
Run several startup scripts for the NFS server
[nick1811@NAS ~]$ sudo service rpcbind start
[nick1811@NAS ~]$ sudo service nfs start
Finally, remember turn on the port in iptables.
[nick1811@NAS ~]$ sudo vim /etc/sysconfig/iptables
# NFS
-A INPUT -m state --state NEW -m tcp -p tcp --dport 2049 -j ACCEPT
[nick1811@NAS ~]$ sudo service iptables restart
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]
iptables: Applying firewall rules:       


Although we have been set complete. But how to check all setting are correctly? To reach this purpose. I choose other CentOS and install NFS client to do it.

First, we also need to install necessary libraries.
[nick1811@Client ~]$ sudo yum install nfs-utils nfs-utils-lib
Second, we use showmount command to check we can see the shared folder.
[nick1811@Client ~]$ showmount -e 192.168.0.1
Export list for 192.168.0.1:
/home/nick1811/Shared_Folder  192.168.0.1/24
Finally, we mount shared folder to local folder which is we created.
[nick1811@Client ~]$ mount 192.168.0.1:/home/nick1811/Shared_Folder /mnt/nfs
When we can put files to /mnt/nfs and we can see files on the server side, we successfully setup NFS server.

Reference: http://linux.vbird.org/linux_server/0330nfs.php