0% found this document useful (0 votes)
14 views3 pages

Setup NFS Server on CentOS 7 Guide

This document provides a step-by-step guide to setting up an NFS server on CentOS 7 and configuring client automount. It covers the installation of necessary software, creation of logical volumes, configuration of NFS exports, firewall settings, and client-side setup for automount. The guide includes specific commands and configurations to ensure proper functionality of the NFS server and client.

Uploaded by

Huy Taxuan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views3 pages

Setup NFS Server on CentOS 7 Guide

This document provides a step-by-step guide to setting up an NFS server on CentOS 7 and configuring client automount. It covers the installation of necessary software, creation of logical volumes, configuration of NFS exports, firewall settings, and client-side setup for automount. The guide includes specific commands and configurations to ensure proper functionality of the NFS server and client.

Uploaded by

Huy Taxuan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Setup 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

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 [Link] and resides on [Link]/24 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
/mnt/nfs [Link]/24(rw,sync,no_subtree_check,root_squash,all_squash)

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
exporting [Link]/24:/mnt/nfs

Check:

# showmount -e
Export list for [Link]:
/mnt/nfs [Link]/24

NFS Server Firewall

Allow NFS, rpcbind (portmapper) and mountd access from [Link]/24 LAN:

# iptables -A INPUT -s [Link]/24 -p tcp -m multiport --dport 111,2049,20048 -j ACCEPT


# iptables -A INPUT -s [Link]/24 -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/[Link]:

/nfs /etc/[Link]

Create the file /etc/[Link] with the following content:

public -rw [Link]:/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 ..

Common questions

Powered by AI

The root_squash option maps requests from the root user (uid/gid 0) to the nfsnobody user, effectively reducing root access on the NFS volume to ordinary user privileges, enhancing security. The all_squash option further maps all user and group IDs to nfsnobody, which standardizes access rights for all users, simplifying the management of permissions across different clients .

Logical volumes provide a flexible storage solution for NFS servers, enabling the efficient allocation and management of disk space for shared files. In the described setup, a 5GB logical volume named lv_nfs is created, formatted, and mounted, allowing the NFS server to manage storage more dynamically and adjust to changing needs without reformatting .

For an NFS server setup, firewall rules should allow inbound traffic from the LAN, specifically permitting ports used by NFS and related services: 111 (rpcbind), 2049 (NFS), and 20048 (mountd). This can be achieved using iptables with rules such as: `iptables -A INPUT -s 10.8.8.0/24 -p tcp -m multiport --dport 111,2049,20048 -j ACCEPT` for TCP and a similar rule for UDP .

On the client side, install both autofs and nfs-utils. Append a line to /etc/auto.master specifying the mount point, here '/nfs', and an associated map file described in /etc/auto.nfs. This map file should define the mount behavior, e.g., 'public -rw spacewalk.hl.local:/mnt/nfs/public'. Enable and restart the autofs service to begin automatically managing these mounts as needed .

Iptables rules secure access to an NFS server by restricting incoming traffic to specifically allowed IP address ranges, protocols, and ports. By allowing only trusted subnets and necessary service ports like 111 (rpcbind), 2049 (NFS), and 20048 (mountd), these rules prevent unauthorized access and mitigate risks of external attacks or data breaches .

Adding the NFS logical volume to the fstab file ensures that the volume is automatically mounted at boot time. This configuration is critical for maintaining persistent storage access across reboots, ensuring the NFS share remains available without requiring manual intervention .

Improperly configured NFS exports can lead to unauthorized access, where sensitive data might be exposed. Without options like root_squash, a malicious root user on a client could gain root access on the NFS server. Failing to restrict access to specific IP ranges or subnets can also allow unwanted connections. Using the all_squash option helps mitigate these risks by minimizing privilege levels .

The sync option ensures that changes are written to stable storage before a request is acknowledged, which improves reliability and data integrity but may reduce performance. In contrast, asynchronous operation allows quicker responses by buffering writes, which can improve performance at the cost of potential data loss or inconsistency in the event of a failure .

To set up an NFS server on CentOS 7, first install the necessary software 'nfs-utils'. Enable and start the rpcbind and nfs-server services using systemctl. Next, create a logical volume under the vg_centos7 group, format it with ext4, and mount it to /mnt/nfs. Modify /etc/exports to configure NFS exports with appropriate options such as rw, sync, no_subtree_check, root_squash, and all_squash. Use exportfs to export the share. Finally, update firewall settings to allow necessary traffic from the LAN .

The no_subtree_check option disables subtree checking, which normally verifies if the requested file is within the exported file system, improving performance. However, it can expose security risks since it doesn't confirm whether a file is part of a subtree within the indicated directory structure, potentially allowing access to adjacent non-exported files if symlinked .

You might also like