How to configure NFS on Ubuntu?
To set up NFS (Network File System) on Ubuntu, you need to follow these steps:
- Install NFS server software package:
Open the terminal and run the following command to install the NFS server software package: - Update the system using ‘sudo apt update’ and then install the NFS kernel server with ‘sudo apt install nfs-kernel-server’.
- Create a shared directory:
Create a shared directory on the NFS server, where you can choose a custom directory path. For example, create a directory named /nfs/share. - Create a directory named “share” in the “nfs” directory with full read, write, and execute permissions for all users.
- Set up NFS sharing:
Open and edit the /etc/exports file, and add the following content: - Allow all users to read and write to the NFS share with synchronous access and no subtree checking.
- This will allow all clients to access the /nfs/share directory with read and write permissions.
- Reload NFS configuration by running the following command:
- Execute the command “sudo exportfs -a” and then restart the NFS kernel server using “sudo systemctl restart nfs-kernel-server”.
- Setting up NFS Client:
Once the NFS server is configured, you need to set up the NFS client to access the shared directory. - Install the NFS client software package:
Open the terminal on the NFS client and run the following commands to install the NFS client software package:
sudo apt update
sudo apt install nfs-common - Mounting NFS shared directory:
To mount NFS shared directory, run the following command (for example, mount the shared directory to /mnt/nfs):
sudo mkdir -p /mnt/nfs
sudo mount:/nfs/share /mnt/nfs Please replace
with the IP address of the NFS server. - Automatically mount NFS shares:
If you want to automatically mount NFS shared directories at system startup, you can edit the /etc/fstab file and add the following line:
:/nfs/share /mnt/nfs nfs defaults 0 0 After saving and closing the file, run the following command to test the automatic mounting:
sudo mount -a
Now, you have successfully configured NFS on Ubuntu. The NFS server will share directories with NFS clients, allowing them to access and share files.