How to Share Files Between Linux Computers Using NFS

Table of contents:

How to Share Files Between Linux Computers Using NFS
How to Share Files Between Linux Computers Using NFS
Anonim

Almost all Linux distributions come with the ability to create an NFS (Network File System) server that allows computers connected to a network to share files with each other. Using an NFS to share files is only suitable for networks consisting of computers and servers running the Linux operating system. However, it ensures fast and efficient data transfer.

Steps

Part 1 of 2: Create the Server

Share Files Between Linux Computers Using NFS Step 1
Share Files Between Linux Computers Using NFS Step 1

Step 1. Use a Network File System (NFS) server to share files between Linux computers connected to a local LAN

If you need to share data with Windows or Mac systems, the best option is to use Samba.

Share Files Between Linux Computers Using NFS Step 2
Share Files Between Linux Computers Using NFS Step 2

Step 2. Understand how an NFS server works

When sharing files using an NFS server, communication occurs between two components: the server and the clients. The server represents the computer on which the files to be shared are physically stored, while the clients represent the computers that will have access to the server's shared folder by mounting it as a virtual disk drive. The NFS system must therefore be configured on both the server and client sides to allow communications.

Share Files Between Linux Computers Using NFS Step 3
Share Files Between Linux Computers Using NFS Step 3

Step 3. Open a "Terminal" window on the computer that will act as the server

This is the machine that will host all the files to be shared on the network. The NFS server must be running and connected to the network to allow clients to mount the network folder that contains the data to be shared. The configuration of the NFS system requires the use of the Linux "Terminal" window in order to install and configure both the server and the clients.

Share Files Between Linux Computers Using NFS Step 4
Share Files Between Linux Computers Using NFS Step 4

Step 4. Type the command

sudo apt-get install nfs-kernel-server nfs-common portmap and press the button Enter.

This way the files needed to use the NFS system will be downloaded and installed on your computer.

Share Files Between Linux Computers Using NFS Step 5
Share Files Between Linux Computers Using NFS Step 5

Step 5. Once the installation is complete, type the command

dpkg-reconfigure portmap.

Select the "No" option from the menu that will appear. This will allow other computers connected to the network to have access to the shared folder of the NFS server.

Share Files Between Linux Computers Using NFS Step 6
Share Files Between Linux Computers Using NFS Step 6

Step 6. Type the command

sudo /etc/init.d/portmap restart restart the "portmap" service.

This way you can be sure that the configuration changes will be saved and applied.

Share Files Between Linux Computers Using NFS Step 7
Share Files Between Linux Computers Using NFS Step 7

Step 7. Create a virtual directory that will be used to share data

This is an empty folder that is used to redirect clients to the real shared directory. In this way you have the possibility to change at any time the folder that contains the files to be shared, without however having the need to reconfigure all the clients.

  • Type the command.mkdir -p / export / virtual_folder_name and press the button Enter.

    This will create a folder that will have the name you entered instead of the virtual_folder_name parameter that will be visible to all clients on the network.

Share Files Between Linux Computers Using NFS Step 8
Share Files Between Linux Computers Using NFS Step 8

Step 8. Type the command pico / etc / fstab and press the Enter key

The contents of the "/ etc / fstab" file will be displayed so that you can configure the auto-mount of the real shared folder to the virtual one when starting the NFS server.

Share Files Between Linux Computers Using NFS Step 9
Share Files Between Linux Computers Using NFS Step 9

Step 9. Add the line of text

shared_drive virtual_folder none bind 0 0 at the end of the file.

Replace the shared_drive parameter with the path of the drive to be shared, then replace the virtual_folder parameter with the path to the folder you created in the previous steps.

For example, to share the memory drive / dev / sdb of the NFS server with all clients on the network using the virtual directory you created earlier, you will need to use the following line of code / dev / sdb / export / Shared none bind 0 0. Save changes made to the "fstab" file

Share Files Between Linux Computers Using NFS Step 10
Share Files Between Linux Computers Using NFS Step 10

Step 10. Edit the contents of the file

/ etc / exports.

To complete the server configuration, you must add the link to the virtual directory you created earlier and the IP addresses of all the clients that will be able to access it in the file in question. Use the following code to share this folder with all IP addresses on your local LAN: / export / virtual_folder 192.168.1.1/24(rw, no_root_squash, async).

Share Files Between Linux Computers Using NFS Step 11
Share Files Between Linux Computers Using NFS Step 11

Step 11. Use the command

sudo /etc/init.d/nfs-kernel-server restart to restart the NFS server.

Part 2 of 2: Connecting the Clients

Share Files Between Linux Computers Using NFS Step 12
Share Files Between Linux Computers Using NFS Step 12

Step 1. Open the "Terminal" window on a client computer

Share Files Between Linux Computers Using NFS Step 13
Share Files Between Linux Computers Using NFS Step 13

Step 2. Type the command

sudo apt-get install portmap nfs-common and press the button Enter to install the NFS client files.

Share Files Between Linux Computers Using NFS Step 14
Share Files Between Linux Computers Using NFS Step 14

Step 3. Create the directory where the server shared folder will be mounted

You can use whatever name you want, for example run the mkdir / SharedFile command to create a new folder called "SharedFile".

Share Files Between Linux Computers Using NFS Step 15
Share Files Between Linux Computers Using NFS Step 15

Step 4. Type the command

pico / etc / fstab to be able to modify the contents of the configuration file / etc / fstab.

Share Files Between Linux Computers Using NFS Step 16
Share Files Between Linux Computers Using NFS Step 16

Step 5. Add the line of text

server_IP_address: shared_folder client_folder nfs rsize = 8192, wsize = 8192, timeo = 14, intr at the end of the file in question.

Replace the server_IP_address parameter with the network IP address of the computer hosting the NFS server, then replace the shared_folder parameter with the path to the dummy folder you created on the NFS server and the client_folder parameter with the directory path you just created on the client. Do not change the rest of the parameters in the command for now.

Using the same information as in the previous example, the line of text you need to add to the "fstab" file should look like this: 192.168.1.5:/export/Shared / FileShare nfs rsize = 8192, wsize = 8192, timeo = 14, intr

Share Files Between Linux Computers Using NFS Step 17
Share Files Between Linux Computers Using NFS Step 17

Step 6. Type the command

sudo /etc/init.d/portmap restart to restart the "portmap" service to use the new configuration settings.

The drive that will allow you to have access to the shared folder of the NFS server will be mapped automatically each time the computer is started.

Share Files Between Linux Computers Using NFS Step 18
Share Files Between Linux Computers Using NFS Step 18

Step 7. Before rebooting the client computer, manually test the mount command to make sure it works

Type mount code -a, then add the ls / SharedFiles parameter to verify that shared files are displayed on the NFS server.

Share Files Between Linux Computers Using NFS Step 19
Share Files Between Linux Computers Using NFS Step 19

Step 8. Repeat this procedure on each of the computers you want to connect to the NFS server

Using the same parameters you used for the first client, you should be able to correctly configure all the others as well.

Recommended: