The server in NFS implements NFS daemon processes so that the files are shared with the clients and clients can access the shared data in their local machine as a local storage file. The server holds the rights and permissions over the shared file and can give full access or half access to the client depending on him/her. NFS server can be installed on almost all the major operating systems however In this article, we will install and configure an NFS server on Ubuntu 20.04
Installing NFS Server on Ubuntu
- Before going into the NFS server installation let us first update all our packages by executing the following command in our Ubuntu 20.04 terminal: If all the packages are up to date then you don’t have to run the following command of the upgrade, however, if they are not then execute the following command:
- Now that our system packages are updated and upgrade let us start installation the nfs-kernel-server package with the following command:
- Once you are done with installing the nfs-kernel-server, create an NFS export directory that will be shared with a client, use the following command: It is this nfs_share directory that we will share with the client and the client will be able to view or update this directory in their local system.
- The next step is to set permissions of the nfs_share directory so that the client machines can access the nfs_share directory: According to your requirements and needs, you can also give other permissions as well but we will give the read, write and execute permission to all the clients that are inside the directory with the following command:
- Let us now give access to client systems of nfs_share directory whose permissions are in the /etc/exports directory and to change it first you have to open it in your favorite editor with the following command: Once opened you will see the following screen: In /etc/exports you can set permission for a single client or multiple clients as well as an entire subnet depending on your requirements. However, we will access an entire subnet to access our nfs_share directory by adding the following line in the opened file /etc/exports: Replace the Ip address in the above line with the client’s IP address. We can see in the above line that we have given the 192.168.43.0/24 subnet access to rw (read and write), sync(writing all changes to disk before applying), no_subtree_check( excludes subtree checking). However, if you want to grant a single client access then insert the following line in the above-opened file which is /etc/exports. /mnt/nfs_share client_IP_Address_1 (re,sync,no_subtree_check) Replace the clinet_IP_Adress_1 with the client IP address and then save the file by pressing CTRL+S and then to exit press CTRL+X.
- The last step with giving access to a client machine is to export the directory nfs_share which will be achieved with the following command: Now we have to restart our nfs-kernel-server for which purpose type or copy the following command on your Ubuntu 20.04 terminal:
- We are done with exporting the nfs_share directory and now we have to allow the NFS through the UFW firewall in ubuntu for which execute the following command on your Ubuntu 20.04 terminal: If the firewall is turned off then use the following command to enable it: After enabling the ufw firewall, let us check the status of the ufw firewall with the following command:
Confiugre NFS client to Mount Share
- As it is a recommended step we will first update and upgrade our client system packages with the following command:
- Now that we are done with updating and upgrading our system packages let us install nfs_common in our client system with the following command:
- This Step involves creating a mount point from which we will mount the nfs_share directory from the NFS server with the following command:
- This is the last step where we will enable the client to have access to the nfs_share directory but first go to your server system terminal and type the following command so that we can find out the server Ip address: Now all you have to do is to execute the following command by replacing your server IP address show above:
Verify the NFS Mount
Now that we are done with everything, let us test that if the nfs_share directory has client access or not for which first we have to move to the /mnt/nfs_share/ directory with the following command on our Server Ubuntu Machine: Next, let’s create some files in nfs_share directory by executing the following commands in the Ubuntu Server terminal: Now let’s go back to our client system Ubuntu and check whether the files created in the above step in Ubuntu Server are available or not: Congratulations! as seen in the above output test1.txt and test2.txt are available in the client ubuntu system.
Conclusion
Now that we have successfully installed and then configured the NFS server on Ubuntu 20.04 we can share our files with another system over a network without any hassle no matter where your client system is in the world. The above article showed you how to install and configure the NFS server on ubuntu 20.04. We hope that if you follow the steps thoroughly you are set with the NFS Server.