How to Set NFS on Linux?


Setting up NFS (Network File System) on your Linux system is a crucial skill for efficient file sharing and data access in a networked environment. NFS allows you to share directories and files between Linux systems seamlessly. In this comprehensive guide, we will walk you through the process of configuring NFS on Linux, from installation to advanced settings. Whether you are a beginner or an experienced Linux user, this article will provide you with valuable insights and step-by-step instructions to master NFS.

How to Set NFS on Linux?

NFS Installation and Configuration

Setting up NFS begins with the installation and configuration process. Follow these steps to get started:

Installing NFS Server

Before you can set up NFS, you need to install the NFS server package on your Linux system. To do this, open your terminal and enter the following command:

sudo apt install nfs-kernel-server   # For Debian/Ubuntu
sudo yum install nfs-utils          # For CentOS/RHEL

Creating Shared Directories

After installing the NFS server, you should create directories that you want to share with other machines on the network. For example:

sudo mkdir /shared_directory

Configuring NFS Exports

Now, you need to specify which directories you want to share and which systems can access them. Edit the /etc/exports file to configure NFS exports:

sudo nano /etc/exports

Add the following line to the file to allow access to the shared directory:


Exporting NFS Shares

After configuring the exports file, export the shared directory using the following command:

sudo exportfs -a

Starting NFS Server

Start the NFS server to make the shared directory accessible:

sudo systemctl start nfs-kernel-server   # For Debian/Ubuntu
 systemctl start nfs-server          # For CentOS/RHEL

Now that you’ve set up NFS on your Linux system, let’s explore some advanced configurations and common tasks.

How to Set NFS on Linux?

Advanced NFS Configuration

Configuring NFS Security

NFS security is essential to protect your shared files. You can enhance security by restricting access to specific IP addresses or networks. Edit the /etc/exports file to define access permissions:

/shared_directory,sync,no_subtree_check)   # Allow access to a specific IP
/shared_directory,sync,no_subtree_check) # Allow read-only access to a range of IPs

Mounting NFS Shares on Client Systems

To access NFS shares on client systems, you need to mount them. Use the mount command to do this:

sudo mount -t nfs server_ip:/shared_directory /mnt/mount_point

Automounting NFS Shares

Automounting NFS shares ensures they are mounted at system startup. Edit the /etc/fstab file and add an entry like this:

server_ip:/shared_directory /mnt/mount_point nfs defaults 0 0

Now, let’s address some frequently asked questions about setting up NFS on Linux.


What is NFS, and why is it used on Linux?

NFS (Network File System) is a distributed file system protocol that allows file sharing between networked computers. It is widely used on Linux for efficient data access and sharing.

Can I share files between different Linux distributions using NFS?

Yes, NFS is platform-independent, so you can share files between different Linux distributions without any issues.

Is NFS secure for file sharing?

NFS can be secure if configured properly, with access control and firewall rules. It’s essential to implement security measures to protect shared data.

What are the advantages of using NFS over other file-sharing protocols?

NFS offers low overhead, excellent performance, and seamless integration with Linux systems, making it a preferred choice for many users.

Can I set up NFS on Linux for both local and remote file sharing?

Yes, NFS can be configured for both local network file sharing and remote file sharing across different networks.

You can troubleshoot NFS problems by checking the server’s logs, verifying network connectivity, and ensuring proper NFS configuration.

How to start NFS on Linux?

To start NFS on Linux, you can use the “systemctl” command to enable and start the NFS server service, like this: sudo systemctl enable nfs-server sudo systemctl start nfs-server

How to use NFS in Linux?

To use NFS in Linux, you can mount remote NFS shares using the “mount” command or by adding entries to the “/etc/fstab” file.

How to set NFS on Linux?

To set up NFS on Linux, you need to install the NFS server package, configure the exports file (/etc/exports) to specify the directories to share, and then start the NFS server as mentioned in the first answer.


Setting up NFS on Linux is a valuable skill for efficient file sharing and data access. This guide has provided you with a comprehensive overview of NFS installation, configuration, and advanced settings. By following these steps and best practices, you can create a secure and reliable NFS environment on your Linux system.

Remember to prioritize security by configuring access control and firewall rules to protect your shared data. With NFS, you can seamlessly share files and collaborate with ease in a networked Linux environment.

Leave a comment