Hardware

Nfs: share folders on linux

Table of contents:

Anonim

NFS of the English term Network File System, which means Network File System. It is the acronym for identifying the native system used by Linux to share folders on a network. And as a result, these shared folders can be accessed from other users' computers as if they were on the hard drive itself.

Therefore, we could say that, NFS allows computers using Linux to connect and share folders with each other. Additionally, in Linux there are other alternatives to share resources such as Samba, FTP, SSH, but the recommended thing to do to share resources in a Linux network is NFS.

NFS: Sharing folders on Linux

NFS installation

In order to use the service, we need to previously install the NFS package for the corresponding distribution. Typically, most computers already contain the package, as you may need to share a folder at any time. However, the fact that a computer has the package installed does not mean that it is already sharing its file system on the network. For this, it requires a configuration and a previous start of the service.

To proceed with the installation of the NFS and we want to obtain the latest version, we use the apt-get command from the console:

apt-get install nfs-common nfs-kernel-server

NFS server configuration

Before starting the services, it is required to specify which folders you want to share and define under what type of permissions will the access be: read only or read and write. On the other hand, it is also possible to establish which computers can connect to these folders. All these options can be configured from the file: / etc / exports

In the configuration file, in each line we can specify several points:

  • The folder we want to share. The permissions under which it is shared (read only: 'ro' or read and write: 'rw'). What are the machines that are allowed access. It can be a name, an IP address or a range of IP addresses.

When using NFS for sharing, we recommend that you set the maximum permission restrictions. For example, if users do not require writing to files, we must set the 'read only' permission.

NFS manual start and stop

For the NFS server services to work, the first step is to start the portman service, therefore the first thing we must execute is:

sudo /etc/init.d/portmap start

If we want to start the NFS service or every time we make modifications to the / etc / exports file, it is necessary to execute the following command:

sudo /etc/init.d/nfs-kernel-server restart

Otherwise, that is, stopping the service, we use:

sudo /etc/init.d/nfs-kernel-server stop

You may be interested in reading: ownCloud: How to have your own cloud in Ubuntu

NFS shared folder access

In order to access a folder shared by NFS, the first steps to take are the installation of the portman and nfs-commons packages. For this we execute:

sudo apt-get install portmap nfs-common sudo /etc/init.d/portmap restart

At this point, we will already be able to mount the shared folder on our system. Therefore, the entry is as if it were any other folder within our file system on the hard drive.

For example, if we have a folder inside the NFS server, suppose that a server shares a folder called / photos by NFS. On the client PC we can create a folder called / photos-server and on it mount a shared folder on the server. The instruction to execute in the console would be:

sudo mount -t nfs server-ip: / photos / server-photos

From this moment, we can already verify the contents of the folder and if the permissions are available, even make modifications. It is important to note that the assembly must be done on a folder within our system, otherwise the remote files will not be displayed.

WE RECOMMEND YOU Mark Shuttleworth will again be the CEO of Canonical

On the other hand, to unmount the folder, we execute in console the command umount and followed by the name of the folder in which it is mounted, for example:

sudo umount / photos-server

Problems when mounting

When mounting an NFS folder, any of these 3 errors can occur: Network problems, Server problems or Client problems.

To rule out whether the problem is from the server or not, we can try mounting the folder on the server itself using IP 127.0.0.1. If it works, the problem is on the network or on the client.

On the other hand, if pinging from the server to the client shows no firewall, then the problem is with the client.

If this is a problem that occurs in the client, we can try to reinstall the client or execute these commands on the client:

apt-get install nfs-common nfs-kernel-server /etc/init.d/portmap restart /etc/init.d/nfs-kernel-server restart

And finally try to mount the folder.

Shared folders

If we want to configure that a folder shared by NFS is mounted automatically when we start our Linux system, we can make a modification in the / etc / fstab file, the line to add would be like the following:

server-ip: / photos / server-photos nfs

In this way, when we start our machine, the folder / photos on the server will automatically be mounted on our folder / photos-server.

Furthermore, it is recommended that the data of each user on the network be stored centrally in a server space. This will provide several various advantages, such as:

  • The user will be given the possibility of accessing their files, even accessing from an unusual computer. For the administrator, it will be much easier to make backup copies and if the user's machine fails, they will not lose their information.

To achieve this, the server must have centralized user accounts and clients must be configured to authenticate when connecting.

Hardware

Editor's choice

Back to top button