Logo

Armand.nz

Home / About / Linkedin / Github

NFS Share on Debian

#debian #linux #nfs |

Installing NFS Components on the host

  1. On your NFS server, install NFS server:
sudo apt update
sudo apt install nfs-kernel-server

Create the Share Directories on the Host

  1. 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 ..
  1. As a security measure, NFS will translate any root operations on the client to the nobody: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

  1. Open the /etc/exports file in your text editor with root privileges
sudo nano /etc/exports
  1. 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)
  1. 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
  1. 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
  1. 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 the ufw firewall:
sudo ufw allow from 192.168.100.0 to any port nfs

NFS Client configurations

  1. On a Debian based client machine you can install the NFS client with this package:
sudo apt update
sudo apt install nfs-common
  1. On Fedora, CentOS, AlmaLinux, and other RHEL-based distros, you can install the NFS client with this package:
sudo dnf install nfs-utils
  1. Show mounts on local NFS Server
showmount -e  127.0.0.1

# Example output
Export list for 127.0.0.1:
/media/storage *
  1. 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
  1. Create a mount point on the client machine
sudo mkdir /mnt/nfs-share
  1. 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
  1. 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
  1. To execute the fstab you just edited and refresh systemd’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
comments powered byDisqus

Copyright © Armand