NFS Server Setup on Linux | Step-by-Step Guide to Share Files Over Network
Learn how to set up an NFS server on Linux using AWS and RHEL 9. This practical guide covers installation, configuration, security settings (SELinux, firewall), and client-side mounting to enable real-time file sharing across your network.

Ever wished you could share files across multiple Linux machines as if they were local? That’s exactly what NFS (Network File System) delivers. In this hands‑on guide you’ll learn how I deployed an NFS server on AWS using RHEL 9 and mounted it from a client instance, all while navigating SELinux, firewalls, and cloud security groups. Follow along to create your own real‑time, network‑based file‑sharing environment!
What Is NFS?
Network File System (NFS) is a protocol that lets one Linux host (the server) export directories so other hosts (the clients) can mount them over the network. To the client, the share behaves like any local folder—read, write, and modify in place—but the data lives entirely on the remote server.
Lab Topology
Role | OS / Platform | Purpose |
---|---|---|
NFS Server | RHEL 9 on AWS EC2 | Hosts and exports the shared directory |
NFS Client | RHEL 9 (or any modern Linux) on AWS EC2 | Mounts and consumes the share |
Network | AWS VPC, same subnet | Low‑latency traffic; port 2049 open in the security group |
Step 1 — Prepare the NFS Server
1. Update system packages
sudo dnf update -y
2. Install NFS services
sudo dnf install -y nfs-utils
3. Create the shared directory
sudo mkdir -p /srv/nfs/shared
sudo chown nfsnobody:nfsnobody /srv/nfs/shared
sudo chmod 0777 /srv/nfs/shared # loosest perms for demo
4. Configure export rules
Edit /etc/exports:
sudo tee -a /etc/exports <
-
10.0.0.0/24
= your client subnet. -
no_root_squash
lets root on the client act as root on the share (use with caution).
5. Enable & start NFS services
sudo systemctl enable --now nfs-server rpcbind
6. Refresh exports
sudo exportfs -rav
Step 2 — Harden the NFS Server
Control | Command or Setting |
---|---|
SELinux | sudo setsebool -P nfs_export_all_rw on |
Firewall (firewalld) | sudo firewall-cmd --permanent --add-service=nfs sudo firewall-cmd --reload |
AWS Security Group | Inbound TCP 2049 from your client’s IP/subnet |
Step 3 — Configure the NFS Client
1. Install NFS utilities
sudo dnf install -y nfs-utils
2. Discover exported shares
showmount -e
3. Create a local mount point
sudo mkdir -p /mnt/shared
4. Test a one‑off mount
sudo mount -t nfs :/srv/nfs/shared /mnt/shared
Confirm: df -h | grep shared
5. Make the mount persistent
Add to /etc/fstab:
:/srv/nfs/shared /mnt/shared nfs defaults,_netdev 0 0
Reload:
sudo mount -a
Step 4 — Verify Real‑Time Sync
-
On the client
echo "Hello from client $(hostname)" | sudo tee /mnt/shared/hello.txt
-
On the server
cat /srv/nfs/shared/hello.txt # Output should match the client's message
If the content appears instantly, your NFS share is live!
Common Troubleshooting Tips
Symptom | Quick Check |
---|---|
Mount hangs | Confirm port 2049 open in AWS SG & firewalld |
Permission denied | Check /etc/exports subnet mask and SELinux booleans |
Slow transfer | Ensure both instances are in the same AZ & use enhanced networking |
Why NFS Matters for DevOps
-
Centralized storage for logs, configs, or build artifacts
-
Stateless compute nodes; data lives on the NFS appliance
-
Seamless scaling—add more clients without moving files
-
Familiar Linux permissions & tooling—no proprietary agents required
Key Takeaways
-
NFS simplifies file sharing across Linux systems with minimal overhead.
-
SELinux, firewall, and AWS security groups must align for a secure deployment.
-
Persist mounts in /etc/fstab so shares survive reboots.
-
Real‑time sync proves your DevOps pipeline can rely on network storage.
With this quick practical guide you’re ready to spin up a production‑ready NFS environment, whether on AWS, on‑prem, or in any hybrid cloud scenario.
FAQs :
What is NFS in Linux?
NFS (Network File System) is a protocol that allows file sharing between systems over a network, making remote directories accessible like local folders.
What are the benefits of using NFS?
NFS allows centralized file storage, easier collaboration, reduced redundancy, and seamless access from multiple Linux clients.
How do I install NFS on RHEL 9?
Use the command sudo dnf install -y nfs-utils
on both server and client systems.
What is the role of /etc/exports?
The /etc/exports
file defines which directories to share via NFS and who can access them.
How do I start the NFS service?
Use sudo systemctl enable --now nfs-server
to start and enable the service on boot.
How do I check shared directories from a client?
Use showmount -e
to view exported directories.
How do I mount an NFS share?
Use mount -t nfs
to mount manually.
How can I make the NFS mount persistent?
Add an entry in /etc/fstab
on the client system for automatic mounting at boot.
What port does NFS use?
NFS typically uses TCP port 2049.
How do I configure SELinux for NFS?
Use sudo setsebool -P nfs_export_all_rw on
to allow NFS read-write exports.
Do I need to open ports in the firewall for NFS?
Yes, open port 2049 using firewall-cmd
and reload the firewall.
Can I use NFS in the cloud?
Yes, NFS works on cloud platforms like AWS, GCP, and Azure. Ensure security group rules allow NFS traffic.
What happens if NFS is not mounted at boot?
You’ll need to mount it manually unless /etc/fstab
is properly configured.
How do I check if NFS is working?
Try reading/writing a test file in the mounted directory from the client and verify it appears on the server.
Is NFS secure?
NFS is not encrypted by default. Use firewalls and secure networks. For encryption, use NFSv4 with Kerberos or VPN.
What are the limitations of NFS?
NFS can have performance issues over WAN, lacks built-in encryption, and may require advanced tuning for scalability.
Can Windows access NFS shares?
Windows Pro and Enterprise editions support NFS mounting with the appropriate services enabled.
How do I stop the NFS service?
Use sudo systemctl stop nfs-server
.
How do I remove a mount?
Use sudo umount /mount/point
to unmount the share.
How to fix "permission denied" errors in NFS?
Ensure correct subnet in /etc/exports
, proper SELinux settings, and open firewall ports.
What is no_root_squash?
It allows the root user on the client to have root access on the NFS share. Use cautiously.
Can NFS shares be read-only?
Yes, specify ro
in /etc/exports
.
How does file sync work between server and client?
NFS syncs in real time; any file changes are visible immediately on both systems.
Can I restrict client IPs?
Yes, configure IPs/subnets in /etc/exports
for access control.
How do I refresh exports?
Use sudo exportfs -rav
to reload the export configuration.
How do I check active NFS shares?
Use exportfs
without arguments on the server.
What is _netdev in fstab?
It tells the system to wait for the network to be ready before mounting NFS during boot.
Can I run NFS on different subnets?
Yes, ensure routing and firewall rules allow it.
Is NFS better than Samba?
NFS is preferred in Unix/Linux environments; Samba is better for Windows interoperability.
Can I share multiple directories with NFS?
Yes, list multiple entries in /etc/exports
with different paths and client settings.