NFS on Ubuntu

A very condensed post about setting up an example NFS server 192.0.2.1 and client 192.0.2.16. All actions as root.

Courtesy…

Configure the server 192.0.2.1

1
2
3
4
5
6
sudo su
apt update
apt install nfs-kernel-server
systemctl start nfs-kernel-server.service
mkdir -p /data/acme
nano /etc/exports

And add this to file exports:

1
/data/acme *(rw,sync,no_subtree_check)

Next:

1
2
3
exportfs -a
ufw status
ufw allow from 192.0.2.16 to any port nfs
  • ufw status numbered list rules. To remove a rule – say number 5 – do ufw delete 5.
  • ufw enable starts UFW when you get: “Status: inactive”.
    • In that case you want to allow ssh too: ufw allow ssh

Configure the client 192.0.2.16

1
2
3
4
5
sudo su
apt update
apt install nfs-common
mkdir -p /data/nfs/acme
nano /etc/fstab

In fstab, add:

1
192.0.2.1:/data/acme  /data/nfs/acme  nfs  defaults  0 0

Additional information

NFS can be hard to configure. Links below and specific searches can help.

One thing is important, communication between guest and host is based on user and group information and it is important to understand that uid and gid play a role here, they should be the same on host and guest. You have to retrieve them from a guest station (“id -u UserName” and “id -g UserName” returning for example 1003 and 1005) and a line in /etc/exports on the server can look like:

1
/data/acme 192.0.2.16(rw,sync,all_squash,anonuid=1003,anongid=1005,no_subtree_check)

More

Leave a comment