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

Video: How to Share Files Between Linux Computers Using NFS

Video: How to Share Files Between Linux Computers Using NFS
Video: 3 Tips to Write Blogs & Emails That Get Attention 2024, December
Anonim

Almost all types of Linux have the ability to set up a Network File System (NFS) which allows Linux computers on the same network to share files. Although NFS is only suitable for networks consisting of computers and Linux servers, it works at the system level for fast and efficient file transfers between computers.

Step

Part 1 of 2: Creating a Server

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

Step 1. Use NFS to share files between Linux computers on the local network

If you want to share files with a Mac or Windows computer, use Samba.

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

Step 2. Know how NFS works

When sharing files using NFS, there are two parties: the server and the client. The server is the computer that stores the files, while the client is the computer that accesses the shared folder by mounting it as a virtual drive. NFS must first be configured on the server and client computers you want to use.

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

Step 3. Open a terminal on the server computer

This is the computer that stores the shared files. You must turn on and log on to the server computer before the client can mount the shared folder on its computer. Use the terminal to configure NFS on server and client computers.

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

Step 4. Type

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

The NFS file will be downloaded and installed on the 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

dpkg-reconfigure portmap.

Select "No" in the menu that appears. Now computers that are on the network can connect to the shared folder.

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

Step 6. Type

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

This is to ensure changes can be applied correctly.

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

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

This empty directory will redirect the client to the actual shared directory. This will make it easier for you if you want to change the shared directory on the server later without having to make changes on the client computer.

  • Type.mkdir -p /export/dummyname and press Enter.

    A directory named dummyname will be created and the client can view it.

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

Step 8. Type pico /etc/fstab and press Enter

The /etc/fstab file will open and allow you to automatically mount the shared drive when the server computer starts up.

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

Step 9. Add

sharedpath dummypath none bind 0 0 at the end of the file.

Change the sharedpath to the shared drive location and change the dummypath to the dummy directory location you created earlier.

For example, if you want to share the /dev/sdb drive with a client using the created dummy directory, you would type /dev/sdb /export/Shared none bind 0 0. Save the file changes

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

Step 10. Open the

/etc/exports.

You must add a dummy directory and IP address that is allowed to access the file. Use the following format to share with all IP addresses on your local network: /export/dummyname 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 Client Computers

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

Step 1. Open a terminal on the client computer

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

Step 2. Type

sudo apt-get install portmap nfs-common and press Enter to mount 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 a directory where the shared files will be mounted

You can name it anything. For example, you can type mkdir /sharedFiles to create a folder called "sharedFiles".

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

Step 4. Type

pico /etc/fstab to open file /etc/fstab.

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

Step 5. Add

serverIP:sharedDirectory nfs rsize=8192, wsize=8192, timeo=14, intr at the end of the file.

Change serverIP to the IP address on the server's NFS computer. Change the sharedDirectory with the dummy directory you have created on the NFS server and the local directory you have created. For now, you don't need to change any other variables.

Using the example above, the command line would look like: 192.168.1.5:/export/Shared /sharedFiles 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

sudo /etc/init.d/portmap restart to restart portmap and apply the new settings.

The shared drive will be installed automatically each time the computer is turned on.

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

Step 7. Try installing the drive before restarting the computer

Type mount -a then ls /sharedFiles and see if the shared files appear on the screen.

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

Step 8. Repeat this process to connect each computer

Use the same settings and the computer will connect.

Recommended: