Installing NFS Components on the host
- On your NFS server, install NFS server:
sudo apt update
sudo apt install nfs-kernel-server
Create the Share Directories on the Host
- Create the share directory:
sudo mkdir /media/storage -p
Since we have created it with sudo
, the directory is owned by the host’s root
user:
ls -la /media/storage
# Example output=
total 8
drwxr-xr-x 2 root root 4096 Nov 14 18:21 .
drwxr-xr-x 3 root root 4096 Nov 14 18:21 ..
- As a security measure, NFS will translate any
root
operations on the client to thenobody:nogroup
credentials. Therefore, we need to change the directory ownership to match that
sudo chown nobody:nogroup /media/storage
Configuring the NFS Exports on the Host
- Open the
/etc/exports
file in your text editor withroot
privileges
sudo nano /etc/exports
- The configuration syntax needs to look something like this:
#/media/storage 10.0.0.0/24(rw,sync,no_subtree_check)
/media/storage *(rw,sync,no_subtree_check,insecure)
/media/storage
– the directory path of the folder you want to share over the network.10.0.0.0/24
– the IP address of clients/network pool and subnet mask which the NFS share export rule aply to. you can use “*
“ to allow everyoneno_subtree_check
- This option is used to disable subtree checking in file systems. Normally, the host system checks if a file is still available in the exported directory for every access request. This can cause issues, particularly if a file is renamed while a client uses it. Disabling subtree checking, which is generally recommended and avoids these problems.insecure
- To connect to the NFS share with MacOS, the share must be defined with theinsecure
flag. This allows a connection from a nonstandard port (which macOS uses)
- Save the file and exit. Then run the commands to load the configuration we set:
# reload export file
sudo exportfs -ra
# restart the NFS server
sudo systemctl restart nfs-kernel-server.service
- If a folder was created by a root user or with a user with sudo privileges, there may be read-and-write issues when accessing the folder from a client machine with a non-root account. In that case, change the shared directory permissions and ownership on the NFS server like so:
sudo chown -R nobody:nogroup /media/storage
# Give write access to so now others have full access
sudo chmod -R o+w /media/storage
- Firewall. If you’re using a
ufw
firewall on your server, it’s necessary to add a firewall rule to access the shared folder from the client machine. Execute the following command for theufw
firewall:
sudo ufw allow from 192.168.100.0 to any port nfs
NFS Client configurations
- On a Debian based client machine you can install the NFS client with this package:
sudo apt update
sudo apt install nfs-common
- On Fedora, CentOS, AlmaLinux, and other RHEL-based distros, you can install the NFS client with this package:
sudo dnf install nfs-utils
- Show mounts on local NFS Server
showmount -e 127.0.0.1
# Example output
Export list for 127.0.0.1:
/media/storage *
- Show mounts on a remote NFS server
# using IP or DNS
#showmount -e 172.16.222.2
showmount -e nfs.example.com
# Example output
Export list for nfs.example.com
/media/storage *
If you get an error: “mount: RPC: Timed out
”, you can try to restart the client-side component
# On the client reporting a timeout error
sudo /etc/init.d/nfs-common restart
- Create a mount point on the client machine
sudo mkdir /mnt/nfs-share
- Temporarily mount our NFS network share folder
#sudo mount 192.168.100.119:/media/storage /mnt/nfs-share
sudo mount nfs.example.com:/media/storage /mnt/nfs-share
- Permanent Mount The Debian NFS Share On Boot by adding at the end of the
/etc/fstab
file:
echo "nfs.lab.armand.nz:/media/storage /mnt/nfs-share nfs rw,soft,noatime,x-gvfs-show" | sudo tee -a /etc/fstab > /dev/null
- Explanation of the
fstab
settings can be found here
- To execute the
fstab
you just edited and refreshsystemd
’s view of the world, including changes to/etc/fstab
, run
sudo mount -a
sudo systemctl daemon-reload
MacOS
MacOS - when connecting from mac (especially on nfsv3) you have to connect to a specific exported folder rather than the root folder or just the IP.
nfs://10.0.0.100/media/storage