Network File System (NFS) is a distributed file system protocol that allows you to share directories and files between Linux systems over a network. In this guide, we will walk you through how to install and configure both the NFS server and client on Ubuntu 20.04 LTS. Whether you're using a Windows VPS UK or another server, NFS provides a simple way to share files between multiple systems.
Prerequisites
Before starting, ensure you have the following:
- Two Ubuntu 20.04 LTS servers: one for the NFS server and one for the NFS client. These servers could be hosted on a UK Windows VPS, Windows Virtual Private Servers, or another Windows VPS Hosting UK solution.
- Root or sudo privileges on both servers.
Step 1: Install NFS Server
On the server machine, install the NFS server package:
sudo apt update
sudo apt install nfs-kernel-server -y
Step 2: Create a Directory to Share
Create a directory that will be shared with the NFS client. For example, we will create a directory called /srv/nfs_share
:
sudo mkdir -p /srv/nfs_share
Set the appropriate permissions for the directory:
sudo chown nobody:nogroup /srv/nfs_share
sudo chmod 755 /srv/nfs_share
Step 3: Configure NFS Exports
Edit the /etc/exports
file to define the shared directory and the client that will be allowed to access it:
sudo nano /etc/exports
Add the following line, replacing client_ip
with the IP address of the client machine:
/srv/nfs_share client_ip(rw,sync,no_subtree_check)
This configuration grants read and write access to the client with IP client_ip
to the /srv/nfs_share
directory. Save and close the file.
Step 4: Export the Shared Directory
Export the shared directory to make it available to clients:
sudo exportfs -a
To apply the changes, restart the NFS server:
sudo systemctl restart nfs-kernel-server
Step 5: Install NFS Client
On the client machine, install the NFS client package:
sudo apt update
sudo apt install nfs-common -y
Step 6: Mount the Shared Directory on the Client
Create a mount point on the client where the NFS share will be mounted. For example, create a directory called /mnt/nfs_share
:
sudo mkdir -p /mnt/nfs_share
Next, mount the shared directory from the NFS server:
sudo mount server_ip:/srv/nfs_share /mnt/nfs_share
Replace server_ip
with the IP address of the NFS server. The shared directory should now be accessible on the client machine at /mnt/nfs_share
.
Step 7: Verify the NFS Share
To verify that the NFS share is mounted, use the df -h
command to check the mounted file systems:
df -h
You should see an entry showing that the NFS share from the server is mounted on /mnt/nfs_share
.
Step 8: Make the Mount Permanent (Optional)
If you want the NFS share to be automatically mounted at boot, you can add an entry to the /etc/fstab
file on the client machine:
sudo nano /etc/fstab
Add the following line at the end of the file:
server_ip:/srv/nfs_share /mnt/nfs_share nfs defaults 0 0
This will ensure the NFS share is mounted every time the client reboots.
Conclusion
By following these steps, you have successfully installed and configured NFS server and client on Ubuntu 20.04 LTS. NFS provides a simple way to share files between multiple Linux systems over a network, whether you're using a Windows VPS UK, Windows VPS Italy, or another Windows Virtual Private Server Hosting solution.