How to Install NFS Server on Ubuntu 21.04

Installing NFS Server

# Include prerequisites
sudo apt update -y # Run updates prior to installing
sudo apt install nfs-kernel-server # Install NFS Server
sudo systemctl enable nfs-server # Set nfs-server to load on startups
sudo systemctl status nfs-server # Check its status

# check server status
root@worker03:/home/brucelee# sudo systemctl status nfs-server
‚óŹ nfs-server.service - NFS server and services
     Loaded: loaded (/lib/systemd/system/nfs-server.service; enabled; vendor preset: enabled)
     Active: active (exited) since Fri 2021-08-13 04:25:50 UTC; 18s ago
    Process: 2731 ExecStartPre=/usr/sbin/exportfs -r (code=exited, status=0/SUCCESS)
    Process: 2732 ExecStart=/usr/sbin/rpc.nfsd $RPCNFSDARGS (code=exited, status=0/SUCCESS)
   Main PID: 2732 (code=exited, status=0/SUCCESS)

Aug 13 04:25:49 linux03 systemd[1]: Starting NFS server and services...
Aug 13 04:25:50 linux03 systemd[1]: Finished NFS server and services.

# Prepare an empty folder
sudo su # enter root
mkdir $nfsShare # create folder if it doesn't exist
chown nobody: $nfsShare
chmod -R 777 $nfsShare # not recommended for production

# Edit the nfs server share configs
vim /etc/exports
# add these lines
/nfs-share x.x.x.x/24(rw,sync,no_subtree_check,no_root_squash,no_all_squash,insecure)

# Export directory and make it available
sudo exportfs -rav

# Verify nfs shares
sudo exportfs -v

# Enable ingress for subnet
sudo ufw allow from x.x.x.x/24 to any port nfs

# Check firewall status - inactive firewall is fine for testing
root@worker03:/home/brucelee# sudo ufw status
Status: inactive

How to Install NFS Client on Ubuntu 21.04

# Install prerequisites
sudo apt update -y
sudo apt install nfs-common

# Mount the nfs share
sudo mkdir -p $localMount
sudo mount $remoteShare $localMount

# Unmount
sudo umount $localMount
Posted on Categories Linux

Leave a Reply

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