Linux System Administration

0 of 85 lessons complete (0%)

Managing Unix File Systems

Network File Systems

You don’t have access to this lesson

Please register or sign in to access the course content.


Network File System (NFS) is a protocol in Linux that allows files to be shared between multiple computers over a network. It provides a way for users to access files on remote systems as if they were part of the local file system. This is particularly useful in environments where centralized data storage is required, and it is important in networked environments such as corporate networks, server farms, or development clusters.

How NFS Works

  • Server: The system where files are physically stored and shared with other machines.
  • Client: The system that accesses the shared files over the network.
  • NFS enables a client to mount a remote file system and interact with it as though it were a local file system.

Key Features of NFS

  1. Transparency: Users can access remote files in the same way they access local files.
  2. Compatibility: Works across different UNIX-like systems (Linux, macOS, etc.).
  3. Centralized Storage: Ideal for centralizing storage across multiple systems.
  4. Performance: Uses RPC (Remote Procedure Call) for efficient communication.
  5. Security: Can be secured using methods such as Kerberos for authentication and encryption.

NFS Components

  • nfs-server: The server program that provides access to file systems over the network.
  • nfs-client: The client program that allows a system to mount and access the shared file system.
  • /etc/exports: A file on the server that defines which directories can be shared and with which clients.

Steps to Set Up NFS

1. Install NFS Utilities

On the Server:

or

On the Client:

or

2. Configure the NFS Server

Step 1: Create a directory to share:

Step 2: Set permissions for the directory:

Step 3: Edit the /etc/exports file to specify which directories to share and with which clients. This file defines the access control for NFS shares. Open the file:

Add the following line to share the /mnt/nfs_share directory with the client system (identified by IP address):

Explanation of options:

  • rw: Allows the client read and write access.
  • sync: Writes changes to the disk before responding, ensuring data integrity.
  • no_subtree_check: Prevents subtree checking, improving performance.

Step 4: Export the file system:

Step 5: Start and enable the NFS service:

3. Configure the NFS Client

Step 1: Create a directory to mount the shared folder on the client machine:

Step 2: Mount the shared folder from the NFS server:

Here, 192.168.1.20 is the IP address of the NFS server, and /mnt/nfs_share is the directory shared from the server.

Step 3: Verify the mounted file system:

You should see the shared NFS directory mounted on the client system.

4. Automating Mount with fstab

To automatically mount the NFS share on the client system during boot, add the following line to the /etc/fstab file:

5. Manage NFS Access Permissions

NFS can be fine-tuned by specifying different access controls for different clients in /etc/exports. For example:

Read-only access:

Access for multiple clients:

6. Unmounting the NFS Share

To unmount the NFS share on the client system:

Troubleshooting Common NFS Issues

NFS Service Not Running: Ensure that the NFS server service is running with the command:

Firewall Blocking NFS: Ensure that the firewall is configured to allow NFS traffic. On most systems, NFS uses port 2049. You can open this port using the ufw firewall on Ubuntu:

NFS Stale File Handle: This error can occur if the NFS server restarts or exports are updated while the client is still accessing the old file handle. To resolve this, unmount and remount the NFS share.

Lab Exercise: Working with NFS

Objective

Set up a basic NFS server and mount a shared directory on the client system.

Steps

  1. On the NFS Server:
    • Install NFS utilities.
    • Create a directory to share (/mnt/nfs_share).
    • Configure /etc/exports and export the share.
    • Start the NFS server service.
  2. On the NFS Client:
    • Install NFS utilities.
    • Create a directory to mount the shared folder (/mnt/nfs_client_share).
    • Mount the NFS share from the server.
    • Verify the mounted directory.
  3. Optional:
    • Configure automatic mounting using fstab.
    • Unmount the shared directory when done.