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:
- Install NFS Server Software:The NFS server software varies by distribution. On most Linux distributions, you can use
nfs-kernel-serverornfs-serveras 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-serverFor Red Hat/CentOS-based systems:bashCopy codesudo yum install nfs-utils - 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 - Edit the NFS Exports Configuration:Open the
/etc/exportsfile 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/exportsAdd 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.
- Reload NFS Configuration:After editing the
/etc/exportsfile, you need to update the NFS server configuration:sudo exportfs -ra - 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-serverFor sysvinit-based systems (e.g., CentOS 6):sudo service nfs start sudo chkconfig nfs on - 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.
- Test the NFS Share:On a client system, you can mount the NFS share to verify that it’s accessible. Replace
NFS_SERVER_IPwith the IP address or hostname of your NFS server:sudo mount -t nfs NFS_SERVER_IP:/srv/nfs_share /mnt/nfs_mountYou can then navigate to/mnt/nfs_mounton 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.

