Quick Guide – NFS Server Install on Ubuntu Linux

Linux

You can deploy an NFS server onto an Ubuntu Linux server to allow you to provide NFS exports to other machines on your network. The documentation below provides a very quick guide on how to do this.

It assumes you have a Ubuntu Linux 22.04 LTS machine with some storage attached that you want to export to the network for use by other client machines.

Install NFS Server

Firstly, perform an update of the system.

sudo apt update

Install the NFS server:

sudo apt install nfs-kernel-server

Create Export

Make an export directory, in this example we’ll be creating an export directory called “export”. We’ll then set the owner to a particular user and group, if you not sure what set this to root:root. Then we set the “sticky bit” with the chmod command, the Sticky bit is a permission bit that is set on a file/directory that only lets the owner of the file/directory or the root user to delete or rename the file.

mkdir /mydata/export
chown <user>:<group> /mydata/export
chmod 2775 /mydata/export

Edit /etc/exports file. We’re setting an fsid of 399, this should be unique for every export on this host. This configures the NFS Server with the export it should be providing.

/mydata/export *(rw,no_subtree_check,no_root_squash,fsid=399)

Then apply the settings with:

/usr/sbin/exportfs -r

Restart the NFS server to take settings and start exporting the export.

systemctl restart nfs-kernel-server

Configure Firewall

You might find you can’t access the NFS server, so we need to configure the firewall to allow NFS through, as we are working with Ubuntu Linux 22.04, we’ll need to follow these steps.

First disable the firewall with:

ufw disable

Before going any further we need to verify that we can mount the export from another machine, so using the section below “Test Access from Another Machine” verify you can successfully access the export as you expect; if you can’t your NFS server isn’t exporting correctly, or you have some permissions set incorrectly.

If you can access NFS exports as expected, now run this command to open a firewall port:

sudo ufw allow from 0.0.0.0/0 to any port nfs comment 'Allow NFS Access'

Re-enable the firewall:

ufw enable

Test Access from Another Machine

Verify you can access the export from a remote machine.

mkdir /mnt/export
sudo mount nfsserver.domain.com:/mydata/export /mnt/export

Image Attribution

Leave a Reply

Your email address will not be published. Required fields are marked *