Set up NFS Server on CentOS 7 and Configure Client Automount

NFS server is used to make its data generally available to clients. The automount program is used to manage mount points for autofs.


Software used in this article:

  1. CentOS 7.2
  2. nfs-utils 1.3.0
  3. autofs 5.0.7

NFS Server Installation

Packages rpcbind and tcp_wrappers are installed as dependencies.

# yum install nfs-utils
# systemctl enable rpcbind && systemctl start rpcbind
# systemctl enable nfs-server && systemctl start nfs-server

NFS Server Configuration

Our NFS server has a FQDN of spacewalk.hl.local and resides on LAN.

Create a Logical Volume for NFS Shares

Check volume groups:

# vgs
  VG         #PV #LV #SN Attr   VSize   VFree 
  vg_centos7   1   4   0 wz--n- 127.21g 75.22g

Create a 5GB logical volume named lv_nfs in the vg_centos7 group, format as ext4 and mount on /mnt/nfs.

# lvcreate --name lv_nfs --size 5G vg_centos7
# mkfs.ext4 -m 0 /dev/mapper/vg_centos7-lv_nfs
# mkdir -p /mnt/nfs
# mount /dev/mapper/vg_centos7-lv_nfs /mnt/nfs
# mkdir -p /mnt/nfs/public
# chown -R nfsnobody:nfsnobody /mnt/nfs

Don’t forget to add to fstab for permanent mount across reboots.

Configure NFS exports:

# cat /etc/exports

Parameters that are used in our case:

  1. rw: allows both read and write requests on the NFS volume,
  2. sync: replies to requests only after the changes have been committed to stable storage,
  3. no_subtree_check: disables subtree checking,
  4. root_squash: maps requests from (root) uid/gid 0 to the nfsnobody uid/gid,
  5. all_squash: maps all uids and gids to the nfsnobody uid/gid.

Export the share:

# exportfs -rav


# showmount -e
Export list for spacewalk.hl.local:

NFS Server Firewall

Allow NFS, rpcbind (portmapper) and mountd access from LAN:

# iptables -A INPUT -s -p tcp -m multiport --dport 111,2049,20048 -j ACCEPT
# iptables -A INPUT -s -p udp -m multiport --dport 111,2049,20048 -j ACCEPT

Client NFS and Automount Configuration

On a CentOS 7 client machine, install autofs:

# yum install autofs nfs-utils

Add the following line to the file /etc/auto.master:

/nfs  /etc/auto.nfs

Create the file /etc/auto.nfs with the following content:

public  -rw  spacewalk.hl.local:/mnt/nfs/public

Enable and restart the autofs service:

# systemctl enable autofs && systemctl restart autofs

You should notice the /nfs directory created by automount. Change into /nfs directory as a regular user, the folder should be empty:

$ cd /nfs
$ ls -a
.  ..

Now change into /nfs/public directory which is an NFS mount:

$ cd ./public
$ ls -la
total 4
drwxr-xr-x. 2 nfsnobody nfsnobody 4096 Mar 19 17:56 .
drwxr-xr-x. 3 root      root         0 Mar 19 18:11 ..

2 thoughts on “Set up NFS Server on CentOS 7 and Configure Client Automount

Leave a Reply

Your email address will not be published. Required fields are marked *