Configuring an NFS (Network File System) server on a Linux system

Configuring an NFS (Network File System) server on a Linux system involves setting up the server, exporting directories to be shared, and configuring access control. Here’s a step-by-step guide on how to configure an NFS server:

  1. Install NFS Server Software:The NFS server software varies by distribution. On most Linux distributions, you can use nfs-kernel-server or nfs-server as the package name. Use your package manager to install it:For Debian/Ubuntu-based systems:sudo apt-get update sudo apt-get install nfs-kernel-server For Red Hat/CentOS-based systems:bashCopy codesudo yum install nfs-utils
  2. Create or Select a Directory to Share:Choose the directory that you want to export over NFS. This directory could be an existing directory or a new one. In this example, we’ll use /srv/nfs_share.sudo mkdir -p /srv/nfs_share
  3. Edit the NFS Exports Configuration:Open the /etc/exports file in your text editor to define the directories you want to share. You can specify IP addresses, hostnames, or subnets that are allowed to access the shared directories.sudo nano /etc/exports Add an entry for the directory you want to share. For example:/srv/nfs_share 192.168.1.0/24(rw,sync,no_root_squash)
    • /srv/nfs_share: The directory to be shared.192.168.1.0/24: The IP address range or specific IP addresses allowed to access the share.rw: Allows read and write access.sync: Data is written to the server’s disk before it is acknowledged.no_root_squash: Allows the root user on the client to have root-level access.
    Adjust the options according to your needs.
  4. Reload NFS Configuration:After editing the /etc/exports file, you need to update the NFS server configuration:sudo exportfs -ra
  5. Start and Enable the NFS Server:Start the NFS server and enable it to start at boot:For systemd-based systems (e.g., Ubuntu 16.04 and later):sudo systemctl start nfs-kernel-server sudo systemctl enable nfs-kernel-server For sysvinit-based systems (e.g., CentOS 6):sudo service nfs start sudo chkconfig nfs on
  6. Configure Firewall (if necessary):If you have a firewall enabled, ensure that it allows NFS traffic. The NFS service uses port 2049 for TCP and UDP, among others. The exact configuration may vary based on your firewall software.
  7. Test the NFS Share:On a client system, you can mount the NFS share to verify that it’s accessible. Replace NFS_SERVER_IP with the IP address or hostname of your NFS server:sudo mount -t nfs NFS_SERVER_IP:/srv/nfs_share /mnt/nfs_mount You can then navigate to /mnt/nfs_mount on the client to access the shared files.

Your NFS server is now set up and configured to share the specified directory. Remember to adjust the export options, access control, and firewall settings according to your security and sharing requirements.

Leave a comment