Setting Up NFS Server and Client on Linux

NFS Server Setup

Installing Required Packages

yum install -y nfs-utils

Configuring the Export File

Edit the exports configuration file to define which dierctories to share:

vim /etc/exports

Add the following line to share /data/shared with the specified network:

/data/shared 10.0.0.0/24(rw,sync,fsid=0)

Configuration options explained:

Option Description
rw Read-write acess
sync Synchronous writes to disk
fsid=0 Exports this directory as the NFS root

Starting NFS Services

Enable and start the required services. Important: rpcbind must be started before NFS:

systemctl enable rpcbind.service
systemctl enable nfs-server.service
systemctl start rpcbind.service
systemctl start nfs-server.service

Verify the server is running:

rpcinfo -p

Refresh and verify the export configuration:

exportfs -r
exportfs

Expected output:

/data/shared 10.0.0.0/24

NFS Client Setup

Installing and Starting Services

Install the same package on the client:

yum install -y nfs-utils

Enable and start rpcbind:

systemctl enable rpcbind.service
systemctl start rpcbind.service

Note: The NFS client does not require the NFS server service to be running.

Discovering Shared Directories

Query the NFS server to list available exports:

showmount -e 10.0.0.100

Expected output:

Export list for 10.0.0.100:
/data/shared 10.0.0.0/24

Mounting the Shared Directory

Create a local mount point and attach the remote directory:

mkdir -p /mnt/nfs
mount -t nfs 10.0.0.100:/data/shared /mnt/nfs

Verify the mount:

df -h

Troubleshooting: Port Mapper Failures

If showmount fails with a "No route to host" error, the server firewall may be blocking required ports.

First, check which ports the NFS services are using:

rpcinfo -p 10.0.0.100

Typical output shows services running on these ports:

Service Port Protocol
portmapper 111 tcp/udp
nfs 2049 tcp/udp
mountd 20048 tcp/udp
nlockmgr 31206-31241 tcp/udp

To resolve, add firewall rules on the server to allow access from the client subnet:

# Port mapper
iptables -I INPUT -p tcp -s 10.0.0.0/24 --dport 111 -j ACCEPT
iptables -I INPUT -p udp -s 10.0.0.0/24 --dport 111 -j ACCEPT

# NFS protocol
iptables -I INPUT -p tcp -s 10.0.0.0/24 --dport 2049 -j ACCEPT
iptables -I INPUT -p udp -s 10.0.0.0/24 --dport 2049 -j ACCEPT

# Mount daemon
iptables -I INPUT -p tcp -s 10.0.0.0/24 --dport 20048 -j ACCEPT
iptables -I INPUT -p udp -s 10.0.0.0/24 --dport 20048 -j ACCEPT

# Lock manager
iptables -I INPUT -p tcp -s 10.0.0.0/24 --dport 31206 -j ACCEPT
iptables -I INPUT -p udp -s 10.0.0.0/24 --dport 31206 -j ACCEPT

After adding these rules, the showmount command and NFS mounting should work correctly.

Tags: NFS network-file-system Linux server-configuration client-setup

Posted on Thu, 14 May 2026 19:12:44 +0000 by ryanfern86goa