[vc_row][vc_column width="3/4"][vc_column_text]In this article, we will learn how to install NFS on Ubuntu 16.04Network File System (NFS) protocol and a filesystem which allows you to access the shared folders from the┬áremote system or server and also allows you to mount as a remote directory on the servers. This allows you┬áto share the storage space between different clients in different locations. NFS has been always the easiest way to access the remote storages over a network.

<strong>NFS┬á</strong>( Network file systems ) is used to share files with other computers over the network. It is mainly used for centralized home folders.

To accomplish this demo, we need two systems which Ubuntu installed and user with sudo permissions with a private network.[/vc_column_text][vc_custom_heading stm_title_font_weight="500" text="Setup NFS server on ubuntu 14.04" font_container="tag:h3|text_align:left" google_fonts="font_family:Ubuntu%3A300%2C300italic%2Cregular%2Citalic%2C500%2C500italic%2C700%2C700italic|font_style:400%20regular%3A400%3Anormal"][vc_tta_accordion][vc_tta_section title="Installing the Packages on Server" tab_id="1522223448415-161a1f70-8c52"][vc_column_text css=".vc_custom_1522225582156{padding-top: 10px !important;padding-right: 10px !important;padding-bottom: 10px !important;padding-left: 10px !important;background-color: #000000 !important;}"]
<pre><span style="color: #000000;">$ sudo apt update
$ sudo apt install nfs-kernel-server
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
┬á keyutils libnfsidmap2 libpython-stdlib libpython2.7-minimal
┬á libpython2.7-stdlib libtirpc1 nfs-common python python-minimal python2.7
┬á python2.7-minimal rpcbind
Suggested packages:
┬á watchdog python-doc python-tk python2.7-doc binutils binfmt-support
The following NEW packages will be installed:
┬á keyutils libnfsidmap2 libpython-stdlib libpython2.7-minimal
┬á libpython2.7-stdlib libtirpc1 nfs-common nfs-kernel-server python
┬á python-minimal python2.7 python2.7-minimal rpcbind
0 upgraded, 13 newly installed, 0 to remove and 98 not upgraded.
Need to get 4,375 kB of archives.
After this operation, 18.5 MB of additional disk s
Selecting previously unselected package libnfsidmap2:amd64.
(Reading database ... 56995 files and directories currently installed.)
..
ÔÇª
ÔÇª
currently installed.)
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (229-4ubuntu4) ...
Setting up libnfsidmap2:amd64 (0.25-5) ...
Setting up libpython2.7-stdlib:amd64 (2.7.12-1~16.04) ...
Setting up python2.7 (2.7.12-1~16.04) ...
Setting up libpython-stdlib:amd64 (2.7.11-1) ...
Setting up python (2.7.11-1) ...
Setting up libtirpc1:amd64 (0.2.5-1) ...
Setting up keyutils (1.5.9-8ubuntu1) ...
Setting up rpcbind (0.2.3-0.2) ...
Setting up nfs-common (1:1.2.8-9ubuntu12) ...
Creating config file /etc/idmapd.conf with new version
Progress: [ 98%] [##########################################################]
Adding system user `statd' (UID 110) ...
Adding new user `statd' (UID 110) with group `nogroup' ...
Not creating home directory `/var/lib/nfs'.
nfs-utils.service is a disabled or a static unit, not starting it.
Setting up nfs-kernel-server (1:1.2.8-9ubuntu12) ...
Creating config file /etc/exports with new version
Creating config file /etc/default/nfs-kernel-server with new version
Processing triggers for libc-bin (2.23-0ubuntu3) ...
Processing triggers for ureadahead (0.100.0-19) ...########################.]
Processing triggers for systemd (229-4ubuntu4) ...</span></pre>
[/vc_column_text][/vc_tta_section][/vc_tta_accordion][vc_tta_accordion][vc_tta_section title="Installing the Packages on Client Side" tab_id="1522225712038-777a08de-a909"][vc_column_text css=".vc_custom_1522225792488{padding-top: 10px !important;padding-right: 10px !important;padding-bottom: 10px !important;padding-left: 10px !important;background-color: #000000 !important;}"]
<pre>$ sudo apt update
$ sudo apt install nfs-common
apt install nfs-common
Reading package lists... Done
Building dependency tree
Reading state information... Done
Suggested packages:
 watchdog
The following NEW packages will be installed:
 nfs-common
0 upgraded, 1 newly installed, 0 to remove and 98 not upgraded.
Need to get 185 kB of archives.
After this operation, 734 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu xenial/main amd64 nfs-common amd64 1:1 .2.8-9ubuntu12 [185 kB]
Fetched 185 kB in 1s (126 kB/s)
Selecting previously unselected package nfs-common.
(Reading database ... 57864 files and directories currently installed.)
Preparing to unpack .../nfs-common_1%3a1.2.8-9ubuntu12_amd64.deb ...
Unpacking nfs-common (1:1.2.8-9ubuntu12) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for systemd (229-4ubuntu4) ...
Setting up nfs-common (1:1.2.8-9ubuntu12) ...</pre>
[/vc_column_text][/vc_tta_section][/vc_tta_accordion][vc_column_text]
<h4>Enabling and Creating the Share Directories on the Server</h4>
Here for demo┬ápurpose, we are going to share two folders to differentiate the configuration, setting, First one is with superuser permission and other with trusted users on the client system.
<h4>Exporting a General Mount</h4>
In this example, we will create a general NFS mount that with the default configuration which is difficult for a user without any permissions on the client machine they can access and this can be used to create a shared space to store the project files in the folders.[/vc_column_text][vc_tta_accordion][vc_tta_section title="Creating a Shared Folder for General Purpose" tab_id="1522226055499-fa305f77-ec76"][vc_column_text css=".vc_custom_1522226289374{padding-top: 10px !important;padding-right: 10px !important;padding-bottom: 10px !important;padding-left: 10px !important;background-color: #000000 !important;}"]
<pre>$ sudo mkdir /usr/nfs/common ÔÇôp</pre>
<span style="color: #ffffff;">Change the folder permission, so that anybody can write in the folder</span>
<pre>$ sudo chown nobody:nogroup /usr/nfs/common</pre>
<span style="color: #ffffff;">And now try to access the folder from a client with the below command</span>

<span style="color: #ffffff;">Before we mount any shared folder on the client, we needed to create a mount point on the client machine</span>
<pre>$ sudo mkdir /mnt/nfs/common
$ sudo mount 192.168.1.25:/usr/nfs/common /mnt/nfs/common</pre>
<span style="color: #ffffff;">This will mount the NFS share on the server 192.168.1.25 on the client machine with /mnt/nfs/common is mounted at /mnt/nfs/common on the client machine and it can be accessed as a local folder.</span>[/vc_column_text][/vc_tta_section][/vc_tta_accordion][vc_column_text]
<h4>Creating a Shared folder with Home Directory</h4>
We will share user home directories stored on the server to access from the client, the access needed to conveniently manage the users.
<h4>Configuring the NFS Settings on the Server</h4>
As we are seeing 2 types of NFS┬á Share, letÔÇØs see how to configure the setting to match our requirements.[/vc_column_text][vc_tta_accordion][vc_tta_section title="Open /etc/exports file with an editor" tab_id="1522232557326-f69ad31b-1003"][vc_column_text css=".vc_custom_1522232751754{padding-top: 10px !important;padding-right: 10px !important;padding-bottom: 10px !important;padding-left: 10px !important;background-color: #000000 !important;}"]
<pre>$ sudo vi /etc/exports
# /etc/exports: the access control list for filesystems which may be exported
# to NFS clients. See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)</pre>
<span style="color: #ffffff;">Add below lines to the configuration file ÔÇô</span>
<pre>/usr/nfs/common┬á ┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á   192.168.1.100(rw,sync,no_subtree_check)
/home ┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á ┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á 192.168.1.100(rw,sync,no_root_squash,no_subtree_check)</pre>
[/vc_column_text][/vc_tta_section][/vc_tta_accordion][vc_column_text]Below is the explanation for each option we used in the above commands which we used.

Rw -&gt; This will allow client computers to read and write to the share.

Sync -&gt; This will allow the data to be written in the NFS before it applies to queries and It also increase consistent environment and will be stable.

Nosubtreecheck -&gt; This will prevent subtree checking, where if we enable this option, it will cause many problems if the client has opened the file.

Norootsquash -&gt; This will makes the NFS translation request from the root user for the client into a not ÔÇôprivileged users of the server, where it will also prevent the root account on the client from using the file system of the server as root.[/vc_column_text][vc_tta_accordion][vc_tta_section tab_id="1522232834784-031655a7-feac"][vc_column_text css=".vc_custom_1522232868280{padding-top: 10px !important;padding-right: 10px !important;padding-bottom: 10px !important;padding-left: 10px !important;background-color: #000000 !important;}"]
<pre>$ sudo systemctl restart nfs-kernel-server</pre>
[/vc_column_text][/vc_tta_section][/vc_tta_accordion][vc_tta_accordion][vc_tta_section tab_id="1522232923916-c7f0821b-31a8" title="Mounting the Directories on the Client"][vc_column_text css=".vc_custom_1522233046148{padding-top: 10px !important;padding-right: 10px !important;padding-bottom: 10px !important;padding-left: 10px !important;background-color: #000000 !important;}"]<span style="color: #ffffff;">Before, we mount the share folders on the client, we needed to create a mount point and we will link the share folder from the NFS server to the local folders (mount points).</span>
<pre>$ mkdir /mnt/common
$ mkdir /mnt/home
$ sudo mount 192.168.1.100:/usr/nfs/common /mnt/common
$ sudo mount 192.168.1.100:/home /mnt/home</pre>
&nbsp;

<span style="color: #ffffff;">After we run the commands we will not verify that the NFS share folders are mounted correctly or not</span>
<pre>$ df ÔÇôh
Filesystem┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á Size┬á Used Avail Use% Mounted on
udev┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á 538M┬á┬á┬á┬á 0┬á 538M┬á┬á 0% /dev
tmpfs┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á249M┬á 628K┬á┬á 249M┬á┬á 2% /run
/dev/vda1┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á100G┬á 10G┬á┬á 90G┬á 10% /
tmpfs┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á 445M┬á┬á┬á┬á 0┬á 445M┬á┬á 0% /dev/shm
tmpfs┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á 10.0M┬á┬á┬á┬á0┬á 10.0M┬á┬á 0% /run/lock
tmpfs┬á ┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á245M┬á┬á┬á┬á 0┬á 245M┬á┬á 0% /sys/fs/cgroup
tmpfs┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á┬á249M┬á┬á┬á┬á 0┬á┬á 249M┬á┬á 0% /run/user/0
192.168.1.100:/home┬á┬á┬á┬á┬á 124G┬á 11.28G┬á┬á 118.8G┬á┬á 9% /mnt/home
192.168.1.100:/usr/nfs/common┬á┬á 124G┬á 11.28G┬á┬á 118.8G┬á┬á 9% /mnt/common</pre>
<span style="color: #ffffff;">As we can see that they both share are mounted and we can see them at the bottom, as they are mounted from the same server so we can see the same disk usage.</span>[/vc_column_text][/vc_tta_section][/vc_tta_accordion][vc_tta_accordion][vc_tta_section tab_id="1522233337020-a921734e-90b5" title="Mounting the NFS Share at the Boot Time"][vc_column_text css=".vc_custom_1522233557768{padding-top: 10px !important;padding-right: 10px !important;padding-bottom: 10px !important;padding-left: 10px !important;background-color: #000000 !important;}"]<span style="color: #ffffff;">We can mount the NFS share at the time of boot so that if we needed to connect the NFS share folders, we can directly access the folders at the mount points</span>

<span style="color: #ffffff;">Open the /etc/fstab file and add the below lines.</span>
<pre>$ sudo vi /etc/fstab</pre>
<span style="color: #ffffff;">Add the below line at the bottom of the files</span>
<pre>. . .
192.168.1.100:/usr/nfs/common┬á┬á┬á /mnt/general┬á┬á nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0
192.168.1.100:/home┬á┬á┬á┬á┬á┬á        /mnt/home┬á┬á┬á┬á┬á nfs auto,nofail,noatime,nolock,intr,tcp,actimeo=1800 0 0</pre>
[/vc_column_text][/vc_tta_section][/vc_tta_accordion][vc_tta_accordion][vc_tta_section tab_id="1522233616912-bf8ffae7-5871" title="Unmounting the NFS Share Folders"][vc_column_text css=".vc_custom_1522233670088{padding-top: 10px !important;padding-right: 10px !important;padding-bottom: 10px !important;padding-left: 10px !important;background-color: #000000 !important;}"]<span style="color: #ffffff;">As if we do not want to use the folders, we can unmount the NFS share folders using the below commands</span>
<pre>$ sudo umount /mnt/common
$ sudo umount /mnt/home</pre>
[/vc_column_text][/vc_tta_section][/vc_tta_accordion][/vc_column][vc_column width="1/4"][stm_sidebar sidebar="3072"][/vc_column][/vc_row]