TechTorch

Location:HOME > Technology > content

Technology

Guidance on Sharing Files Between Linux Computers Using NFS

February 14, 2025Technology3381
Guidance on Sharing Files Between Linux Computers Using NFS Network Fi

Guidance on Sharing Files Between Linux Computers Using NFS

Network File System (NFS) is a widely used protocol for sharing files between multiple computers in a network. This guide provides a step-by-step walkthrough on how to set up an NFS server and client on Linux systems, facilitating seamless file sharing.

Understanding NFS

Before proceeding, it's important to understand how NFS works. NFS involves a server and multiple clients. The server stores the shared files, while the clients access these files by mounting the shared folder as a virtual drive. This setup requires configuring both the server and the clients using the terminal to handle the installations and configurations.

Setting Up the NFS Server

This section covers the configuration needed to set up an NFS server on a Linux system, particularly on Ubuntu distributions.

Step 1: Open the Terminal

The server computer, used to host the shared files, must be logged in and turned on. Use the terminal to install and configure the necessary packages for NFS.

Step 2: Install Required Packages

Run the following command to install the required NFS components:

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

This will initiate the download and installation of the NFS files on your computer.

Step 3: Restart the Portmap Service

After installation, restart the portmap service:

sudo /etc/init.d/portmap restart

This ensures that the recent changes are effectively applied.

Step 4: Create a Dummy Directory

Create an empty directory to redirect client access to the actual shared directory. This allows you to change the shared directory later without modifying the clients.

mkdir -p /export/dummyname

Replace dummyname with the desired directory name you wish to use.

Step 5: Configure /etc/fstab

Edit the /etc/fstab file to allow for auto-mounting of the shared drive:

pico /etc/fstab

Add the line:

sharedpath dummypath none bind 0 0

Replace sharedpath with the actual path of the shared drive and dummypath with the path of the dummy directory created earlier.

Step 6: Edit the /etc/exports File

Open the /etc/exports file and add the dummy directory and the IP addresses allowed to access it, using the following format:

/export/dummyname 192.168.1.1/24 rw,no_root_squash,async

Replace 192.168.1.1/24 with your local network range and rw,no_root_squash,async to ensure the correct permissions and access modes.

Step 7: Restart the NFS Server

Restart the NFS kernel server to apply the changes manually:

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

Setting Up the NFS Client

Follow these steps to set up an NFS client that can access the shared files via the NFS server.

Step 1: Install Required Packages

On the client computer, install the necessary NFS client tools:

sudo apt-get install portmap nfs-common

This command begins the installation process for the NFS client packages.

Step 2: Create a Mount Directory

Create a directory on the client where the shared files will be mounted:

mkdir /sharedFiles

Replace /sharedFiles with any desired directory name.

Step 3: Configure /etc/fstab

Edit the /etc/fstab file to allow for auto-mounting at boot:

pico /etc/fstab

Add the line:

serverIP:sharedDirectory /sharedFiles nfs rsize8192,wsize8192,timeo14,intr

Replace serverIP with the IP address of the NFS server and sharedDirectory with the dummy directory specified on the server's /etc/exports.

Step 4: Restart the Portmap Service

Restart the portmap service on the client to apply the changes:

sudo /etc/init.d/portmap restart

This command restarts the necessary portmap service to ensure the settings are correctly applied.

Step 5: Test the Connection

Test the connection by mounting the share manually and checking if the files are accessible:

mount -als /sharedFiles

This sequence of commands will mount the shared drive and list the files in the specified directory. If everything is correctly set up, you should see the shared files.