Skip to content

Instantly share code, notes, and snippets.

@swagfin
Last active November 3, 2024 14:08
Show Gist options
  • Save swagfin/eb8177a2811365d8e1edaf9fb916396a to your computer and use it in GitHub Desktop.
Save swagfin/eb8177a2811365d8e1edaf9fb916396a to your computer and use it in GitHub Desktop.
How to Set Up NFS Server on Ubuntu

How to Set Up NFS Server on Ubuntu

Install NFS Server

First, install the NFS kernel server:

sudo apt install nfs-kernel-server

Start the NFS service:

sudo systemctl start nfs-kernel-server.service

Configure Access Policy

Edit the /etc/exports file to define shared directories:

sudo nano /etc/exports

Example

# Publicly accessible directory
/srv/nfs/public *(rw,sync,no_subtree_check)

# Directory accessible only to internal IP addresses (example: 192.168.1.0/24 subnet)
# Replace with your actual internal IP range
/srv/nfs/private 192.168.1.0/24(rw,sync,no_subtree_check)

#or set of IPs
# Allow access to two specific IPs for the /srv/nfs/private folder
/srv/nfs/private 192.168.1.10(rw,sync,no_subtree_check) 192.168.1.20(rw,sync,no_subtree_check)

Example flags

/srv/nfs/public is the directory being shared, 192.168.1.0/24 is the subnet of IP addresses allowed to access, rw is Read and write access, sync is data is written to disk before responding & no_subtree_check Improves performance by not checking if the file being accessed is within a subdirectory of the exported directory.

Apply Configuration

sudo exportfs -a

Allow Port for Firewall (Optional)

Make sure to allow port 2049, which is the main port used by NFS for file sharing.

sudo ufw allow 2049/tcp comment "NFS Server"

Install NFS Common on Client Machines

On other Ubuntu machines (worker nodes) that need to mount the NFS shares, install the NFS common package:

sudo apt install nfs-common

Now your worker nodes can mount the NFS shares!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment