NFS stands for Network File System that is a file service used to allow file sharing between Linux based systems. NFS is a file-level sharing protocol. It means you can mount and access shared data using NFS, but you cannot use NFS to create and format disk partitions. In this tutorial, we will explain how to configure NFS in Ubuntu 17.04. The latest version of NFS is NFSv4. Typically NFS is used for Linux based systems but it can also be now configured between Windows systems.
- How to configure and use NFS in Windows systems.
- How to configure DHCP In Ubuntu 17.04
- How to configure DNS in Ubuntu 17.04
For this tutorial, we will create a shared folder on a Ubuntu server and then will mount it on a Ubuntu client machine. In order to configure NFS in Ubuntu 17.04, you need to perform the following steps:
- Install the required packages on Ubuntu server.
- Modify the configuration file.
- Adding the shared directories.
- Enabling and starting NFS service
- Mounting NFS share on the client machine.
Installing NFS Packages in Ubuntu
The following command is used to install the NFS package in Ubuntu Linux.
sudo apt install nfs-kernel-server
Configure NFS Options
Once you have installed the NFS packages, next, you need to update your domain name in the NFS configuration file. For this, you need to execute the following command.
sudo vi /etc/idmapd.conf
In the above file, find the Domain option and replace it with your domain name as shown in the following figure. However, this is an optional step.
Configure NFS Shared Options
Now, you need to specify the following NFS server settings in the /etc/exports file.
- Share directories
- Allowed network or hosts
- Access permissions and options
To specify the NFS configuration options, edit the /etc/exports file. The following syntax shows the basic options used with NFS protocol in Ubuntu and other Linux variants.
<shared directory> <allowed clients> <access permissions>
Let’s have a look at few of the NFS examples:
- Share directories: /shareddata
- Allowed network or hosts: 10.0.0.0/8
- Access options: read and write with root squash
In order to configure NFS as per the above-mentioned option, the /etc/exports file should look like as follows:
/shareddata 10.0.0.0/8 (rw,no_root_squash)
Let’s have a look at another example:
- Share directories: /shareddata
- Allowed network or hosts: All networks
- Access options: read-only with root squash
The /etc/exports file should look like as follows:
/shareddata *.* (ro,no_root_squash)
If you are interested in learning more options about NFS configuration, you can read the NFS manual reference file by executing the following command:
Enabling and Starting NFS Service
Once you have set the desired shared directory with the desired access permissions and NFS options, next you need to enable and start the NFS service.
sudo systemctl enable nfs-server sudo systemctl restart nfs-server sudo systemctl status nfs-server
Ensure that the NFS service is running properly as shown in the following figure.
Listing NFS Shares
Make sure that the NFS shares are listed by using the sudo exportfs command as shown in the following figure.
NFS Ports and Firewall Configuration
It is always recommended to check that the NFS TCP and UDP ports are listening. If your server is behind the Firewall, you will need to allow the following ports:
- TCP and UDP ports 2049
- TCP and UDP ports 111
- TCP and UDP ports 1110
We assume that the above ports are allowed between NFS server and NFS clients.
Mounting NFS Share on NFS Client
Now, you all set to mount and use the NFS shared data and directory on the NFS client.
Install the NFS package on Client
Typically, you do not need to install the NFS client packages, but if required, you can install using the following command.
sudo apt install nfs-common
Move on to NFS client and execute the following command to list down the NFS shares.
sudo showmount -e <nfs-server-ip>
NFS Persistent Mounting (Permanent Mount)
You can mount the NFS shares temporary using the mount command. However, once you will your machine, you would need to mount it again. For the permanent NFS mounting, you need to update the file system table file that is /etc/fstab. Edit the /etc/fstab file and mount the NFS share using the following syntax.
<nfs-server-ip>:<nfs-shared-directory> <mount-point> <protocol> defaults 0 0
For example, to mount the shareddata directory on the /NFSData mount point, (assuming that your server IP address is 10.0.0.100) you will have to add the following line at the end of the /etc/fstab file.
10.0.0.100:/shareddata /NFSData nfs defaults 0 0
Save the /etc/fstab file and execute the following command to update the file system table.
sudo mount –a
Go to the NFS mounted directory and use it as your local directory.
In this tutorial, we have explained how to configure NFS in Ubuntu latest version that is Ubuntu 17.04. However, the same steps can also be used to configure NFS in the earlier version of Ubuntu such as Ubuntu 16.04 and Ubuntu 14.04.