Skip to content

how to setup NFS service

Steps to setup NFS

Installing NFS Server and NFS Client

install

1
2
3
# “yum” (Red Hat Linux) as example
[root@nfsserver ~]# yum install nfs-utils nfs-utils-lib
[root@nfsserver ~]# yum install portmap (not required with NFSv4)

Start the services on both machines.

1
2
3
4
[root@nfsserver ~]# /etc/init.d/portmap start
[root@nfsserver ~]# /etc/init.d/nfs start
[root@nfsserver ~]# chkconfig --level 35 portmap on
[root@nfsserver ~]# chkconfig --level 35 nfs on

Setting Up the NFS Server

Configure Export directory

1
2
3
4
5
6
[root@nfsserver ~]# mkdir /nfsshare
[root@nfsserver ~]# vi /etc/exports

/nfsshare 192.168.0.101(rw,sync,no_root_squash)

[root@nfsserver ~]# exportfs -rv

NFS Options

  • ro: With the help of this option we can provide read only access to the shared files i.e client will only be able to read.
  • rw: This option allows the client server to both read and write access within the shared directory.
  • sync: Sync confirms requests to the shared directory only once the changes have been committed.
  • no_subtree_check: This option prevents the subtree checking. When a shared directory is the subdirectory of a larger file system, nfs performs scans of every directory above it, in order to verify its permissions and details. Disabling the subtree check may increase the reliability of NFS, but reduce security.
  • no_root_squash: This phrase allows root to connect to the designated directory.

Config firewall

1
2
3
4
5
[root@nfsserver ~]# firewall-cmd --permanent --add-service=rpc-bind
[root@nfsserver ~]# firewall-cmd --permanent --add-service=mountd
[root@nfsserver ~]# firewall-cmd --permanent --add-port=2049/tcp
[root@nfsserver ~]# firewall-cmd --permanent --add-port=2049/udp
[root@nfsserver ~]# firewall-cmd --reload

Auto run after reboot

1
[root@nfsserver ~]# systemctl enable rpcbind nfs-server

show NFS share

1
2
3
[root@nfsserver ~]# showmount --exports
[root@nfsserver ~]# exportfs -v
[root@nfsserver ~]# cat /var/lib/nfs/etab

Restart NFS service

1
[root@nfsserver ~]# systemctl restart rpcbind nfs-server

List NFS clients connected to NFS server

1
2
[root@nfsserver ~]# netstat -l | grep :nfs
[root@nfsserver ~]# ss -a | grep :nfs

Setting Up the NFS Client

Mount Shared Directories on NFS Client

1
2
3
4
[root@nfsclient ~]# showmount -e 192.168.0.100

Export list for 192.168.0.100:
/nfsshare 192.168.0.101

Mount Shared NFS Directory

1
[root@nfsclient ~]# mount -t nfs 192.168.0.100:/nfsshare /mnt/nfsshare

Check Mount infomation

1
2
3
4
[root@nfsclient ~]# df –h
[root@nfsclient ~]# mounnt
# which is equal with
[root@nfsclient ~]# cat /proc/mounts 

We need to make an entry in “/etc/fstab“ to mount an NFS directory permanently on your system across the reboots.

1
2
3
[root@nfsclient ~]# vi /etc/fstab

192.168.0.100:/nfsshare /mnt  nfs defaults 0 0

Removing the NFS Mount

1
2
[root@nfsclient ~]# umount /mnt/nfsshare
[root@nfsclient ~]# df -h -F nfs

Important commands for NFS

  • showmount -e : Shows the available shares on your local machine
  • showmount -e server-ip : Lists the available shares at the remote server
  • showmount -d : Lists all the sub directories
  • exportfs -v : Displays a list of shares files and options on a server
  • exportfs -a : Exports all shares listed in /etc/exports, or given name
  • exportfs -u : Unexports all shares listed in /etc/exports, or given name
  • exportfs -r : Refresh the server’s list after modifying /etc/exports
  • netstat -tulpen | grep 2049 : show nfs port status
  • rpcinfo -p server-ip : Lists the available RPC infomation at the remote server
  • cat /var/lib/nfs/etab : check NFS detail configurations

Github based Comments, sign in Github required.