Install NFS in Ubuntu and share your files over the network with this protocol

nfs1

NFS or Network File System is a distributed file system protocol, originally created, by Sun Microsystems. Through NFS, a system can be allowed to share directories and files with others over a network.

In NFS file sharing, users and even programs can access information on remote systems almost as if they were residing on a local machine.

NFS operates in a client-server environment where the server is responsible for managing client authentication, authorization, and management, as well as all shared data within a specific file system.

Upon authorization, any number of clients can access the shared data as if it were present on their internal storage.

Setting up an NFS server on your Ubuntu system is very simple. All you need to do is perform some necessary installations and configurations, both on the server and on the client machines, and you are good to go.

In this article, We will explain step by step how to configure an NFS server and client that will allow them to share files from one Ubuntu system to another.

Configuring the NFS server

To configure the host system to share directories, we will need to install the NFS Kernel server and then create and export the directories we want the client systems to access.

Now we are going to open a terminal with Ctrl + Alt + T and in it we are going to execute the following command:

sudo apt install nfs-kernel-server -y

Once the installation is done, now we are going to create a folder that we want to share with the client system, this will be an export folder.

In this example we are going to create the folder in the current directory where we are, but you can choose the path that you like best.

In the terminal we will type:

sudo mkdir -p carpeta-compartida

Since we want all clients to access the directory, We will remove the restrictive permissions from the export folder through the following commands:

sudo chown nobody: nogroup carpeta-compartida

sudo chmod 777 carpeta-compartida

It is important that if it is in another path, you place it is fine, since if you leave a single space you could change the permissions of the directories on your system.

Now all users of all groups on the client system will be able to access our "shared folder".

Now in this created folder you can place all the content you want to share.

Export the shared directory

After creating the export folder, we will need to give clients permission to access the host server machine.

This permission is defined through the export file located in the / etc folder on your system.

Use the following command to open this file with Nano:

sudo nano /etc/ exports

Once you've opened the file, you can allow access to the folder they created with the following command:

/ruta/de/la/ carpeta-compartida ip-de-cliente (rw, sync, no_subtree_check)

O you can add multiple clients by adding the following lines in the file:

/ruta/de/la/carpeta-compartida ip-de-cliente-1 (rw, sync, no_subtree_check)
/ruta/de/la/carpeta-compartida ip-de-cliente-2 (rw, sync, no_subtree_check)

Or you can put an IP range as follows:

/ruta/de/la/carpeta-compartida ip-de-cliente1/24 (rw, sync, no_subtree_check)

The "rw, sync, no_subtree_check" permissions defined in this file mean that clients can perform:

rw: read and write operations

sync: write any changes to disk before applying them

no_subtree_check - Prevents subtree check

After doing all the above configurations on the host system, now it is time to export the shared directory:

sudo exportfs -a

Finally, For all settings to take effect, restart the NFS kernel server as follows:

sudo systemctl restart nfs-kernel-server

An important step is to verify that the server's firewall is open to clients so that they can access the shared content.

sudo ufw allow from ip/rango to any port nfs

Remaining something like this:

sudo ufw allow from 192.168.1.1/24 to any port nfs

Now when you check the status of your Ubuntu firewall via the following command, you will be able to see the Action status as "Allow" for the client IP.

sudo ufw status

Your host server is now ready to export the shared folder to the specified clients through the NFS kernel server.

Configuring the client machine

Now is the time to do some simple configurations on the client machine, so that the shared folder from the host can be mounted on the client and then accessed without problems.

For this we are going to install the NFS client with the following command:

sudo apt-get install nfs-common

Your client's system needs a directory where all content shared by the host server can be accessed in the export folder.

You can create this folder anywhere on your system.

sudo mkdir -p carpeta-cliente

Now the folder you created in the previous step is just 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 to mount the shared folder from the host to a mount folder on the client:

sudo mount IPdelserivdor:/ruta/de/la/carpeta-compartida /ruta/carpeta-cliente

The command is more or less as follows:

sudo mount 192.168.1.1:/home/servidor/carpeta-compartida /home/cliente/carpeta-cliente

Now it is time to test the connection by going to the folder from the client machine or machines and verify that the shared content is there.


The content of the article adheres to our principles of editorial ethics. To report an error click here!.

4 comments, leave yours

Leave a Comment

Your email address will not be published.

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Luis said

    Which protocol is faster for file transfer? NFS or samba

  2.   Luis said

    which protocol is faster for file transfer? NFS or samba

  3.   Javier Jimeno-Suarez said

    Hi Luis, the speed really depends on your network.

    Samba and NFS are two different protocols.

    Samba is used to share folders that can be accessed from any other system (Android, windows, linux, etc)

    NFS is a protocol that is installed in server mode on the machine where you have the folder you want to share and as a client on the Linux machine where you want to mount it as if it were a local filesystem (you can mount it in each session or configure it in the fstab file so that it is mounted every time you start).

    I hope I have clarified the difference a bit.

  4.   Pedro said

    It gives me an error, you have not put examples, syntax error. You leave wrong spaces so I don't know where the errors are.
    It is no use to me.