Creating Centralized, Shareable Storage on CentOS — Easy Student Steps
If you’re learning Linux and have more than one machine, you’ll need to share files between them. Network File System (NFS) lets you do that — easily. One machine (the server) shares a folder, and other machines (clients) can use it like it’s their own. No copying. No USB drives. Just one folder, many machines.
This guide walks you through every step — in simple, clear language — so you can set it up without confusion.
What is NFS? (Explained Simply)
NFS is a way for computers to share folders over a network — like a “network drive” in Windows, but for Linux.
Think of It Like a Shared Whiteboard
Imagine the NFS Server is a classroom whiteboard. The NFS Client is a student with a window looking directly at that whiteboard. Whatever the teacher writes on the board, the student sees instantly. If the student could reach through the window to write on it, everyone else would see it too. That’s NFS — one shared space, visible and editable from many machines.
| Component | What It Does | What You Need to Do |
|---|---|---|
| NFS Server | The machine that owns and shares the folder. | Install NFS, create a folder, say who can access it, start services, open firewall. |
| NFS Client | The machine that uses the shared folder. | Install NFS, create a mount point, connect to server, test, make it permanent. |
Step-by-Step: Setting Up the NFS Server
Let’s say your server’s IP address is 192.168.1.200. We’ll share a folder called /srv/nfs/shared_data with all computers in the 192.168.1.0/24 network (like your home or classroom lab).
- Step 1: Install NFS
Open a terminal and run:
sudo dnf install -y nfs-utils - Step 2: Create the Shared Folder
sudo mkdir -p /srv/nfs/shared_data sudo chown nfsnobody:nfsnobody /srv/nfs/shared_data sudo chmod 2770 /srv/nfs/shared_data - Step 3: Configure the
/etc/exportsFileThis file tells NFS what to share and with whom. Edit it with:
sudo vim /etc/exportsThen add this line:
/srv/nfs/shared_data 192.168.1.0/24(rw,sync,no_root_squash)Deconstructing the Options
rw: Clients can **r**ead and **w**rite files.sync: Safer — waits until data is saved to disk before replying.no_root_squash: Lets root users on clients act as root on the server. ⚠️ Use only in trusted networks like labs.
- Step 4: Start and Enable the Services
sudo systemctl enable --now nfs-server sudo systemctl enable --now rpcbind sudo systemctl enable --now mountd - Step 5: Configure the Firewall
Open the required ports:
sudo firewall-cmd --add-service=nfs --permanent sudo firewall-cmd --add-service=rpc-bind --permanent sudo firewall-cmd --add-service=mountd --permanent sudo firewall-cmd --reload - Step 6: Apply the Exports
Make your share active without rebooting:
sudo exportfs -rav
✅ Server Setup Complete!
Your server is now sharing /srv/nfs/shared_data with your network. Time to connect from a client machine!
Step-by-Step: Setting Up the NFS Client
Now, on another CentOS machine (your laptop, VM, or friend’s computer), let’s connect to the server.
- Step 1: Install NFS Packages
sudo dnf install -y nfs-utils - Step 2: Create a Mount Point
This is where the shared folder will appear locally:
sudo mkdir -p /mnt/shared - Step 3: Mount the Share Temporarily
sudo mount 192.168.1.200:/srv/nfs/shared_data /mnt/shared - Step 4: Verify the Mount is Working
Check that the mount shows up:
df -hYou should see a line like:
192.168.1.200:/srv/nfs/shared_data 49G 2.0G 47G 5% /mnt/sharedNow test by creating a file:
touch /mnt/shared/test-file.txtGo to the server and check:
ls -l /srv/nfs/shared_dataIf you see
test-file.txt— it’s working! 🎉 - Step 5: Make the Mount Persistent
Edit
/etc/fstabto auto-mount on boot:The
_netdevOption is CriticalAlways include
_netdevfor network mounts. It tells the system to wait until the network is ready — avoiding boot failures.Add this line to
/etc/fstab:192.168.1.200:/srv/nfs/shared_data /mnt/shared nfs defaults,_netdev 0 0Test it without rebooting:
sudo umount /mnt/shared sudo mount -a
✅ Client Setup Complete!
Your client will now automatically connect to the shared folder on every boot. Use /mnt/shared just like any local folder!