How to Share Files Between Linux Computers Using NFS

Nearly all Linux distributions come with the ability to set up a Network File System (NFS) that allows the different Linux computers on the network to easily share files. NFS is only suitable for networks comprised entirely of Linux computers and servers, but works on the system level for fast, efficient transfers between computers.

Creating the Server

Use NFS (Network File System) to share files between Linux computers on a local network.

If you need to share files with Windows or Mac computers, you will be much more successful using Samba.

Understand how NFS works.

When sharing files with NFS, there are two side: the server and the clients. The server is the computer that is actually storing the files, while the clients are the computers that are accessing the shared folder by mounting the shared folder as a virtual drive. NFS will need to be configured on both the server and any client that wants to connect.

Open the terminal on the server computer.

This is the computer that will be hosting the shared files. The server computer will need to be turned on and logged in in order for clients to mount the shared folder. NFS requires using the terminal to install and configure both the server and client.

Type .

sudo apt-get install nfs-kernel-server nfs-common portmap ↵ Enter This will begin downloading and installing the NFS files on your computer.

After installation, type .

dpkg-reconfigure portmap Select “No” from the menu that appears. This will enable other computers on the network to connect to your shared folder.

Type .

sudo /etc/init.d/portmap restart This will ensure that your changes take effect.

Make a dummy directory that will be used to share the data.

This is an empty directory that will direct the clients to the actual shared directory. This will allow you to change the shared directory on your server later without having to make any changes to the clients.

  • Type mkdir -p /export/dummyname and press . This will create a directory named dummyname that the clients will see.

Type pico /etc/fstab and press ↵ Enter.

This will open the /etc/fstab file and allow you to automatically mount the shared drive whenever the server boots up.

Add .

sharedpath dummypath none bind 0 0 Replace sharedpath with the location of the shared drive, and replace dummypath with the location of the dummy directory you created earlier.

  • For example, to share the /dev/sdb drive with the clients using the dummy directory created earlier, you would type /dev/sdb /export/Shared none bind 0 0. Save the changes to the file.

Open the .

/etc/exports You will need to add your dummy directory as well as the IPs that are allowed to access it to this file. Use the following format to share with all the IP addresses on your local network: /export/dummyname,no_root_squash,async).

Use the .

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

Connecting the Client Computers

Open the terminal on the client computer.

Type .

sudo apt-get install portmap nfs-common ↵ Enter

Create the directory that the shared files will be mounted in.

You can name this whatever you’d like. For example, you can type mkdir /sharedFiles to create a folder called “sharedFiles”.

Type .

pico /etc/fstab /etc/fstab

Add .

serverIP:sharedDirectory nfs rsize=8192,wsize=8192,timeo=14,intr Replace serverIP with the IP address of the NFS server computer. Replace sharedDirectory with the dummy directory you created on the NFS server and the local directory you just created. Leave the rest of the values as they are for now.

  • Using the above examples, the line might look like: /sharedFiles nfs rsize=8192,wsize=8192,timeo=14,intr.

Type .

sudo /etc/init.d/portmap restart The drive will automatically mount each time the computer reboots.

Test the drive by manually mounting it before restarting.

Type mount -a and then ls /sharedFiles to see if the shared files are displayed.

Repeat this process for each connecting computer.

You should be able to enter the same settings and successfully connect.

Leave a Comment