Mount and unmount network file systems using NFS

6. Create and Configure File Systems

πŸ“˜Red Hat Certified System Administrator (RHCSA – EX200)


What is NFS?

  • NFS (Network File System) is a protocol that allows a computer (client) to access files over a network as if they were on its local hard drive.
  • Example: A developer on one server can read/write files that are physically stored on a different server, without copying them.
  • NFS is mostly used in Linux and Unix environments.

Why NFS is Important in IT

  • Shared storage for multiple servers (e.g., web servers accessing the same configuration files).
  • Centralized data management (all backups happen from one location).
  • Easy collaboration between systems in a network.

How NFS Works

  1. Server: The machine that shares directories.
  2. Client: The machine that mounts and uses the shared directories.
  3. Exports: The directories on the server that are available to clients.
  4. Mounting: Connecting the client to the NFS server to use the shared folder.

Think of mounting like β€œconnecting to a shared drive” on another server.


Step 1: Install NFS Tools

  • On Linux, you need NFS packages installed:
# On the server (Red Hat/CentOS/Fedora)
sudo yum install nfs-utils -y# On the client
sudo yum install nfs-utils -y

Step 2: Configure the NFS Server

  1. Create a directory to share:
sudo mkdir -p /srv/nfs/shared
  1. Give proper permissions:
sudo chown nobody:nogroup /srv/nfs/shared
sudo chmod 777 /srv/nfs/shared
  1. Edit /etc/exports file to define which clients can access the directory:
/srv/nfs/shared 192.168.1.10(rw,sync,no_root_squash)
  • 192.168.1.10 β†’ IP of the client allowed to connect.
  • rw β†’ read and write permission.
  • sync β†’ changes are written immediately.
  • no_root_squash β†’ allows root on client to have root permissions on the shared folder.
  1. Start and enable NFS server services:
sudo systemctl enable nfs-server
sudo systemctl start nfs-server
  1. Export the directories:
sudo exportfs -a
  1. Check shared directories:
sudo exportfs -v

Step 3: Mount NFS on the Client

  1. Create a mount point:
sudo mkdir -p /mnt/nfs/shared
  1. Mount the NFS share:
sudo mount 192.168.1.20:/srv/nfs/shared /mnt/nfs/shared
  • 192.168.1.20 β†’ NFS server IP.
  • /mnt/nfs/shared β†’ local mount point on the client.
  1. Verify mount:
mount | grep nfs

or

df -h

Step 4: Make NFS Mount Persistent (Optional but Exam-Relevant)

  • Edit /etc/fstab to mount NFS automatically at boot:
192.168.1.20:/srv/nfs/shared /mnt/nfs/shared nfs defaults 0 0

Step 5: Unmount NFS

  • To safely unmount:
sudo umount /mnt/nfs/shared
  • Always unmount before shutting down or disconnecting the network share to avoid data corruption.

Step 6: Common NFS Commands

CommandPurpose
showmount -e <server>Show exported directories from server
mount -t nfs <server>:/path /mountpointMount NFS manually
umount /mountpointUnmount NFS
exportfs -vList exported directories on server

Key Points for Exam

  1. Server vs Client roles: Know which commands go where.
  2. NFS Permissions: rw, ro, sync, no_root_squash are important.
  3. Mounting/unmounting: You must know mount, umount, and /etc/fstab.
  4. Network accessibility: NFS requires network connectivity; the client must reach the server.
  5. Verification: Always check mount, df -h, or showmount -e.

Real-Life IT Examples

  • Multiple Linux web servers reading from the same content directory on a central server.
  • Backup servers accessing critical data directories over the network.
  • A development team accessing a shared code repository folder hosted on another server.

βœ… Summary

  • NFS allows network-wide file sharing.
  • Configure server exports, mount client directories, and unmount safely.
  • /etc/exports and /etc/fstab are key files to remember.
  • Use NFS commands to verify and troubleshoot.
Buy Me a Coffee