Monday, September 23, 2024

NFS (Network File System) : NFS Server and NFS Client configuration

NFS, or Network File System, is a distributed file system protocol developed by Sun Microsystems in 1984. It allows a system to share directories and files with others over a network. With NFS, users and applications can access files on remote systems as if they were local, enabling seamless file sharing across different systems, architectures, and locations.

Key Features of NFS:

- Transparency: NFS provides users with transparent access to files on a remote server as if they were located on their local machine.

- Interoperability: NFS is platform-independent, allowing different operating systems to communicate and share files across a network.

- Statelessness: In its early versions, NFS was designed to be stateless, meaning that the server did not maintain session information for clients. This design provided resilience but also led to limitations in reliability and consistency.

- Security: Over time, NFS introduced several security improvements, including support for Kerberos authentication in NFSv4.

History and Evolution of NFS :

1. NFSv1 (1984):

   - NFS was initially developed by Sun Microsystems as a way to provide network file sharing in SunOS.
   - It was proprietary to Sun and served as an early attempt to allow file sharing across systems in a networked environment.

2. NFSv2 (1989):

   - The first widely available version, NFSv2, was introduced in RFC 1094.
   - It operated using the User Datagram Protocol (UDP) for fast, connectionless communication.
   - NFSv2 supported only 32-bit file sizes, which limited its scalability as file sizes grew.
   - It used a stateless protocol, meaning the server didn’t keep track of clients, which simplified server-side management but limited its capabilities for complex applications.

3. NFSv3 (1995):

   - Introduced in RFC 1813, NFSv3 addressed many limitations of NFSv2.
   - Improvements:
     - Larger file size support with 64-bit file handling.
     - Asynchronous Writes: To improve performance, NFSv3 allowed asynchronous writes, meaning the client could continue            writing without waiting for server acknowledgment.
     - Introduced support for TCP, allowing for better reliability in file transfers over unreliable networks.
     - Still stateless but more robust in handling large workloads.

4. NFSv4 (2003):

   - Defined in RFC 3530, NFSv4 represented a significant evolution from previous versions.
   - Major Features:
     - Stateful Protocol: NFSv4 introduced statefulness, allowing for better handling of file locks and recovery from network                failures.
     - Security: NFSv4 incorporated stronger security features, including support for Kerberos and improved ACLs (Access                  Control Lists).
     - Single Port: NFSv4 used a single well-known port (2049), which simplified firewall configuration.
     - Performance Optimizations: NFSv4 added features like compound operations and better caching mechanisms to enhance            performance in WAN environments.
   - Cross-Platform: As a stateful and more secure protocol, NFSv4 gained popularity across different Unix-like systems and               was widely adopted in enterprise environments.

5. NFSv4.1 (2010):

   - Introduced pNFS (parallel NFS), allowing clients to read and write files in parallel, which improved performance for large, distributed workloads.
   - Sessions: NFSv4.1 introduced sessions, providing reliable and robust mechanisms for handling multiple file operations.

6. NFSv4.2 (2016):

   - Added new features like server-side cloning, application I/O hints, and a standardized method for handling holes in sparse files.

NFS Server Configuration : 

1. Install NFS Utilities:

   First, install the NFS server utilities (`nfs-utils`) using `dnf`. This package provides essential NFS-related services and tools, including `rpcbind`, `nfsd`, and other utilities needed for the NFS server to function.

   dnf install nfs-utils -y

2. Manage Firewall:

   If the firewall is running, it can block NFS traffic by default. Use these commands to check the status, stop, or disable the firewall. If security is a concern, you should configure the firewall to allow NFS traffic on specific ports instead of turning it off entirely.

   systemctl status firewalld

   systemctl stop firewalld

   systemctl status firewalld

If you need to keep the firewall running, ensure you open the following ports for NFS:

   firewall-cmd --add-service=nfs --permanent

   firewall-cmd --reload

3. Start and Enable NFS Services:

   To make the NFS server persist across reboots, enable and start the `nfs-server.service`. The NFS server will provide access to the shared directories over the network.

   systemctl start nfs-server.service

   systemctl enable nfs-server.service

   systemctl status nfs-server.service

4. Restart `rpcbind` and `nfs-utils` Services:

   NFS requires RPC (Remote Procedure Call) services to operate, specifically the `rpcbind` service. Restart `rpcbind` and `nfs-utils` to ensure proper functioning of NFS.

   systemctl restart rpcbind.service

   systemctl restart nfs-utils.service

5. Create a Directory to Share:

   Create the directory that you want to export (share) over NFS. For example, in this case:

   mkdir /sachinpb

   

6. Configure NFS Exports:

   Edit the `/etc/exports` file to configure the directory export settings. This file defines which directories will be shared over NFS and the permissions for each directory.

   edit  /etc/exports  ==> /sachinpb *(rw,async,no_root_squash)

Add the following line to export the `/sachinpb` directory to all clients (`*`), with read-write access, asynchronous mode (`async`), and no root squashing (`no_root_squash`):

Here’s what these options mean:
   - `rw`: Clients can read and write to the shared directory.
   - `async`: Writes to the shared directory will be cached, improving performance.
   - `no_root_squash`: The root user on the client will have root privileges on the NFS share. Use with caution, as it could pose security risks.

7. Apply Export Settings:

   After updating `/etc/exports`, use `exportfs` to apply the export settings:

   exportfs -a

   You can verify the shared directories using `showmount`:

  showmount -e

8. Test NFS Server:

   Navigate to the shared directory and create a test file to verify that the NFS export is accessible.

   cd /sachinpb
   touch file1


NFS Client Configuration

1. Manage Firewall:

   As with the server, the firewall on the client might block NFS traffic. If needed, stop the firewall or configure it to allow NFS traffic. Check and stop the firewall:

   systemctl status firewalld
   systemctl stop firewalld

2. Install NFS and RPC Utilities:

   Install the required packages on the client side. The `nfs-utils` package provides the necessary utilities for mounting NFS shares, and `rpcbind` is essential for NFS communication.

   dnf install rpc* -y
   dnf install nfs-utils -y

3. Create a Mount Point:

   Create a directory on the client machine where the NFS share will be mounted. This directory acts as the local mount point for the NFS share.

mkdir /sachinpb

4. Mount the NFS Share:

   Use the `mount` command to mount the NFS share from the server. Replace `9.53.174.120` with the actual IP address or hostname of your NFS server:

   mount -t nfs 9.x.y.12:/sachinpb /sachinpb

OR, you can also add this in /etc/fstab file  as shown below :

# cat /etc/fstab
9.x.y.12:/sachinpb     /sachinpb  nfs     defaults        0 0

followed by mount -a

This command mounts the `/sachinpb` directory from the NFS server onto the `/sachinpb` directory on the client.

5. Verify the Mount:

   Change to the mounted directory and check if the contents from the NFS server are visible on the client machine:

    cd /sachinpb

   If the mount is successful, you should see the `file1` created earlier on the NFS server.

No comments:

Post a Comment