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
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.
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.
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.
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.
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.
Step 6. Type
sudo /etc/init.d/portmap restart to restart the portmap service.
This is to ensure changes can be applied correctly.
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.
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.
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
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).
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
Step 1. Open a terminal on the client computer
Step 2. Type
sudo apt-get install portmap nfs-common and press Enter to mount the NFS client files.
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".
Step 4. Type
pico /etc/fstab to open file /etc/fstab.
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
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.
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.
Step 8. Repeat this process to connect each computer
Use the same settings and the computer will connect.