User Tools

Site Tools


nfs_server

NFS Server & Client

1.0 --- Install NFS Server

Run the following command in order to install the NFS Kernel Server on your system:

sudo apt install nfs-kernel-server

1.1 --- Create Export Directory

The directory that we want to share with the client system is called an export directory. You can name it according to your choice; here, we are creating an export directory by the name of tpl-share in our system’s mnt(mount) directory.

Use the following command, by specifying a mount folder name according to your need, through the following command as root:

sudo mkdir -p /mnt/tpl-share

As we want all clients to access the directory, we will remove restrictive permissions of the export folder through the following commands:

sudo chown nobody:nogroup /mnt/tpl-share
sudo chmod 777 /mnt/tpl-share

1.2 --- NFS export file

After creating the export folder, we will need to provide the clients the permission to access the host server machine. This permission is defined through the exports file located in your system’s /etc folder. Please use the following command in order to open this file through the Nano editor:

sudo nano /etc/exports

Once you have opened the file, you can allow access to:

/mnt/tpl-share 192.168.10.0/24(rw,sync,no_subtree_check)
---OR---
/mnt/tpl-share 192.168.10.100(rw,sync,no_subtree_check)
/mnt/tpl-share 192.168.10.101(rw,sync,no_subtree_check)
/mnt/tpl-share 192.168.10.102(rw,sync,no_subtree_check)
[...]

The permissions “rw,sync,no_subtree_check” permissions defined in this file mean that the client(s) can perform:

  • rw: read and write operations
  • sync: write any change to the disc before applying it
  • no_subtree_check: prevent subtree checking

1.3 --- Export the shared directory

After making all the above configurations in the host system, now is the time to export the shared directory through the following command as sudo:

sudo exportfs -a

Finally, in order to make all the configurations take effect, restart the NFS Kernel server as follows:

sudo systemctl restart nfs-kernel-server

1.4 --- Open firewall for the client

An important step is to verify that the server’s firewall is open to the clients so that they can access the shared content. The following command will configure the firewall to give access to clients through NFS:

sudo ufw allow from [clientIP or clientSubnetIP] to any port nfs
sudo ufw allow from 192.168.10.0/24 to any port nfs
---OR---
sudo ufw allow from 192.168.10.100/24 to any port nfs
sudo ufw allow from 192.168.10.101/24 to any port nfs
sudo ufw allow from 192.168.10.102/24 to any port nfs
[...]

Now when you check the status of your Ubuntu firewall through the following command, you will be able to view the Action status as “Allow” for the client’s IP:

sudo ufw status
22/tcp                     ALLOW       Anywhere                  
80/tcp                     ALLOW       Anywhere                  
443/tcp                    ALLOW       Anywhere                  
8080/tcp                   ALLOW       Anywhere                  
[...]               
2049                       ALLOW       192.168.10.0/24           
22/tcp (v6)                ALLOW       Anywhere (v6)             
80/tcp (v6)                ALLOW       Anywhere (v6)             
443/tcp (v6)               ALLOW       Anywhere (v6)             
[...]

2.0 --- NFS Client

Run the following command in order to install the NFS Common client on your system:

sudo apt install nfs-common

Your client’s system needs a directory where all the content shared by the host server in the export folder can be accessed. You can create this folder anywhere on your system. We are creating a mount folder in the mnt directory of our client’s machine:

sudo mkdir -p /mnt/tpl-share

The folder that you created in the above step is like any other folder on your system unless you mount the shared directory from your host to this newly created folder. Use the following command in order to mount the shared folder from the host to a mount folder on the client:

sudo mount serverIP:/exportFolder_server /mnt/mountfolder_client
sudo mount 192.168.10.10:/mnt/tpl-share /mnt/tpl-share

Please create or save a file in the export folder of the NFS host server. Now, open the mount folder on the client machine; you should be able to view the same file shared and accessible in this folder.

Now we will make sure the folder automounts on reboot:

sudo nano /etc/fstab
[...]
# mounting nfs shares from tpl-rpi3
192.168.10.10:/mnt/tpl-share    /mnt/tpl-share          nfs     defaults    0 0

For Windows client configuration please follow the guide linked in references.

That's it!

x.x --- References

nfs_server.txt · Last modified: 2019/02/04 16:28 by pi