NFS
Setup guide for sharing files using NFS between Ubuntu systems.
Server
-
Install
Install the NFS server package to enable file sharing.
Terminal window sudo apt update && sudo apt install nfs-kernel-server -y -
Add export
Define the directory to share and specify client access in the NFS exports file.
Terminal window echo "{{NFS_SHARE_VAR}} {{CLIENT_IP_VAR}}(rw,sync,no_subtree_check)" | sudo tee -a /etc/exports -
Apply export
Reload the NFS exports to apply the changes.
Terminal window sudo exportfs -ra -
Allow through firewall (optional)
Open the NFS port to allow access from the specified client IP.
Terminal window sudo ufw allow from {{CLIENT_IP_VAR}} to any port nfs
Client
-
Install
Install the NFS client package to enable mounting remote shares.
Terminal window sudo apt update && sudo apt install nfs-common -y -
Create mount point
Make a local directory where the shared files will be mounted.
Terminal window mkdir -p {{NFS_MOUNT_VAR}} -
Manual mount
Mount the shared directory manually from the server to the local mount point.
Terminal window sudo mount {{SERVER_IP_VAR}}:{{NFS_SHARE_VAR}} {{NFS_MOUNT_VAR}} -
Automount
Add an entry to
/etc/fstab
to mount the share automatically on boot.Terminal window sudo nano /etc/fstabTerminal window {SERVER_IP_VAR}:{{NFS_SHARE_VAR}} {{NFS_MOUNT_VAR}} nfs noauto,x-systemd.automount,_netdev,nofail,timeo=5,retrans=2 0 0