209.2 NFS Server Configuration (weight: 3)

Tech Tutorial: 209.2 NFS Server Configuration #

Introduction #

Network File System (NFS) is a distributed file system protocol that allows a user on a client computer to access files over a network in a manner similar to how local storage is accessed. NFS, originally developed by Sun Microsystems in the 1980s, has evolved through numerous versions, the most common being NFSv3 and NFSv4.

In this tutorial, we will explore how to configure an NFS server on a Linux system. This involves installing the necessary software, setting up the NFS exports, and ensuring proper security and performance configurations. This tutorial is aimed at system administrators and IT professionals preparing for the LFCS (Linux Foundation Certified Sysadmin) exam, specifically focusing on the NFS Server Configuration.

Key Knowledge Areas #

  • Understand NFS architecture and versions
  • Install NFS server
  • Configure exports
  • Manage NFS shares
  • Secure NFS
  • Troubleshoot NFS issues

Utilities: #

  • /etc/exports
  • exportfs
  • showmount
  • mount
  • systemctl
  • nfsstat

Step-by-Step Guide #

Step 1: Installing NFS Server #

Before configuring NFS, you need to install the NFS server package on your Linux distribution.

On Ubuntu/Debian systems: #

sudo apt update
sudo apt install nfs-kernel-server

On CentOS/RHEL systems: #

sudo yum update
sudo yum install nfs-utils

Step 2: Configuring NFS Exports #

The NFS exports are defined in the /etc/exports file. This file specifies which directories are shared and the permissions attached to them.

  1. Create a shared directory:

    sudo mkdir /var/nfs/general -p
    sudo chown nobody:nogroup /var/nfs/general
    
  2. Edit the /etc/exports file to add the export:

    sudo nano /etc/exports
    

    Add the following line to share the directory with a client:

    /var/nfs/general 192.168.1.100(rw,sync,no_subtree_check)
    
    • rw: Allow read and write permissions.
    • sync: Reply to requests only after the changes have been committed to stable storage.
    • no_subtree_check: Prevent subtree checking.
  3. Export the shares and restart NFS service:

    sudo exportfs -a
    sudo systemctl restart nfs-kernel-server
    

Step 3: Managing NFS Shares #

Use exportfs to manage NFS shares:

  • Show exported file systems:

    sudo exportfs -v
    
  • Re-export all directories after modification of /etc/exports:

    sudo exportfs -ra
    

Step 4: Client Configuration #

On the client machine, install NFS client utilities and mount the NFS share:

sudo apt install nfs-common  # On Debian/Ubuntu
sudo yum install nfs-utils   # On CentOS/RHEL

sudo mkdir /mnt/nfs
sudo mount 192.168.1.100:/var/nfs/general /mnt/nfs

Step 5: Security and Permissions #

Ensure the NFS server is secured by managing access through /etc/exports and using firewalls to limit access:

  • Firewall configuration example on Ubuntu:

    sudo ufw allow from 192.168.1.100 to any port nfs
    sudo ufw enable
    sudo ufw status
    

Step 6: Troubleshooting NFS #

Use nfsstat and showmount to troubleshoot:

  • Check NFS statistics:

    nfsstat
    
  • Show mountable volumes from the server:

    showmount -e 192.168.1.100
    

Conclusion #

Configuring an NFS server involves setting up and managing shared directories, securing access, and ensuring that clients can mount the shares as needed. Remember to monitor and troubleshoot your NFS setup regularly using the provided utilities to maintain optimal performance and security. This setup not only helps in passing the LFCS exam but also in managing real-world network file systems efficiently.