How to Install and Configure an NFS Server on Ubuntu 18.04?

Network File System (NFS) is a distributed file system protocol that enables remote clients to access shared files over a network as if they were stored locally. Installing and configuring an NFS server on Ubuntu 18.04 allows you to create centralized file storage for multiple Linux systems on your network.

Prerequisites

Before proceeding, ensure you have root privileges or sudo access on your Ubuntu 18.04 system. You should also know the IP addresses of client machines that will access the NFS shares.

Step 1: Update System Packages

First, update your system's package repository and upgrade existing packages to ensure compatibility ?

sudo apt update && sudo apt upgrade -y

Step 2: Install NFS Server

Install the NFS kernel server package, which provides the core NFS functionality ?

sudo apt install nfs-kernel-server -y

Step 3: Create and Configure Export Directory

Create a directory to share and set appropriate permissions ?

sudo mkdir -p /var/nfs/general
sudo chown nobody:nogroup /var/nfs/general

Now configure the NFS exports by editing the /etc/exports file ?

sudo nano /etc/exports

Add the following export configuration ?

/var/nfs/general    192.168.1.0/24(rw,sync,no_subtree_check,no_root_squash)
/home               192.168.1.0/24(rw,sync,no_root_squash,no_subtree_check)

Export Options Explained

Option Description
rw Read and write access to the share
sync Ensures changes are written to disk before replying to requests
no_subtree_check Disables subtree checking for better reliability
no_root_squash Allows root user on client to access files as root

Step 4: Export NFS Shares

Apply the export configuration and make the shares available ?

sudo exportfs -a
sudo systemctl restart nfs-kernel-server

Step 5: Configure Firewall Rules

Allow NFS traffic through the firewall for your client network ?

sudo ufw allow from 192.168.1.0/24 to any port nfs
sudo ufw allow from 192.168.1.0/24 to any port 2049

Step 6: Enable NFS Services

Start and enable the NFS server to run automatically at boot ?

sudo systemctl start nfs-kernel-server
sudo systemctl enable nfs-kernel-server
sudo systemctl status nfs-kernel-server

Step 7: Verify NFS Configuration

Check that your exports are properly configured and accessible ?

sudo exportfs -v
showmount -e localhost

Expected output should list your configured exports ?

Export list for localhost:
/home               192.168.1.0/24
/var/nfs/general    192.168.1.0/24

Client-Side Mounting

On client machines, install NFS utilities and mount the shares ?

sudo apt install nfs-common
sudo mkdir -p /mnt/nfs/general
sudo mount -t nfs 192.168.1.10:/var/nfs/general /mnt/nfs/general

To make the mount permanent, add an entry to /etc/fstab ?

192.168.1.10:/var/nfs/general /mnt/nfs/general nfs defaults 0 0

Security Considerations

  • Network Restriction ? Limit access to specific IP ranges using CIDR notation in exports

  • User Mapping ? Use root_squash (default) to map root user to nobody for better security

  • Kerberos Authentication ? For enhanced security, consider implementing Kerberos authentication

  • VPN Tunneling ? Use VPN to encrypt NFS traffic over untrusted networks

Performance Optimization

Parameter Optimization Impact
rsize/wsize Increase read/write buffer sizes Better throughput for large files
nfsvers Use NFSv4 for better performance Enhanced security and features
proto Use TCP instead of UDP More reliable over WAN

Troubleshooting Common Issues

Check NFS server status and logs if you encounter problems ?

sudo systemctl status nfs-kernel-server
sudo journalctl -u nfs-kernel-server
tail -f /var/log/syslog | grep nfs

Conclusion

NFS provides an efficient way to share files between Linux systems on a network. By following these installation and configuration steps, you now have a functional NFS server on Ubuntu 18.04. Remember to implement proper security measures and monitor performance to ensure optimal operation for your specific use case.

Updated on: 2026-03-17T09:01:38+05:30

6K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements