Setting Up NFS Server on Ubuntu 24.04
Setting up an NFS server on Ubuntu 24.04 involves installing the `nfs-kernel-server` package and then telling the server which folders you want to share.
Network File System (NFS) is a system that lets computers share files over a network. Think of it like plugging a USB drive into another computer, but without the physical drive – the files just appear as if they are on your own PC. This is super useful for sharing data between your Ubuntu server and other machines, like your Windows computers, on the same home or office network.
You share folders from your Ubuntu machine by “exporting” them. This makes specific folders available for other computers to connect to and use. This makes managing shared files easy and lets you control who can access what.
Install the `nfs-kernel-server` package using `sudo apt install nfs-kernel-server`. Then, export your desired directory by editing `/etc/exports` and restart the service with `sudo systemctl restart nfs-server`.
Install NFS Server
Setting up an NFS server on Ubuntu 24.04 lets your computer share files with other devices on your network. You need the ‘nfs-kernel-server’ package for this. To install it, open your terminal and run ‘sudo apt update’ followed by ‘sudo apt install nfs-kernel-server’.
Run the command below to install the [nfs-kernel-server] package.
sudo apt update
sudo apt install nfs-kernel-server
sudo nano /etc/idmapd.conf
Uncomment and change the highlighted line to match your domain name.
[General]
Verbosity = 0
# set your own domain here, if it differs from FQDN minus hostname
Domain = example.com
[Mapping]
Nobody-User = nobody
Nobody-Group = nogroup
Save and exit the file.
Export NFS Share
Exporting an NFS share on Ubuntu 24.04 makes a folder on your server ready for other computers to access. For this guide, we’ll share a folder called ‘/home/nfsshare’ from your home directory. To start, open the NFS exports file using the command: ‘sudo nano /etc/exports’.
For this tutorial, we will be exporting a folder in our home directory [/home/nfsshare].
To do that, run the command below to open the NFS exports config file.
sudo nano /etc/exports
Then, add a line to export the directory mentioned.
# /etc/exports: the access control list for filesystems which may be exported
# Example for NFSv4:
# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)
#
#
/home/nfsshare 192.168.156.0/24(rw,no_root_squash)
Additional options one can use with NFS exports.
| Option | Description |
| no_root_squash | It will enable only read requests on a NFS volume. |
| rw | It allows both read and write requests on a NFS volume. |
| ro | It will enable only read requests on an NFS volume. |
| sync | It replies to requests only after the changes have been committed to stable storage. (Default) |
| root_squash | It maps requests from uid/gid 0 to the anonymous uid/gid. |
| async | This option allows the NFS server to violate the NFS protocol and reply to requests before any changes made by that request have been committed to stable storage. |
| secure | This option requires that requests originate on an Internet port less than IPPORT_RESERVED (1024). (Default) |
| insecure | This option accepts all ports. |
sudo mkdir /home/nfsshare
sudo systemctl restart nfs-server
Setup NFS Client
Setting up the NFS client on Ubuntu 24.04 is necessary to connect to your NFS server. You need to install the ‘nfs-common’ package, which allows your computer to access shared files. If it’s not already installed, run the command: ‘sudo apt install nfs-common’.
If you haven’t done so, run the command below to install the NFS server client packages on the client computer.
sudo apt install nfs-common
After installation, please open the configuration file below and add your domain name.
sudo nano /etc/idmapd.conf
Uncomment and change the highlighted line to match your domain name.
[General]
Verbosity = 0
# set your own domain here, if it differs from FQDN minus hostname
Domain = example.com
[Mapping]
Nobody-User = nobody
Nobody-Group = nogroup
Save and exit the file.
Mount NFS share on client
Mounting an NFS share on your client computer lets you access files from the Ubuntu 24.04 server by connecting the shared folder to a local directory. Use the command: ‘sudo mount -t nfs srv1.example.com:/home/nfsshare /mnt’ to mount it. You can check if it worked with ‘df -hT’.
sudo mount -t nfs srv1.example.com:/home/nfsshare /mnt
To view your file system, run the command below.
df -hT
You should see output similar to the one below.
Filesystem Type Size Used Avail Use% Mounted on
tmpfs tmpfs 336M 2.1M 334M 1% /run
/dev/sda2 ext4 49G 9.5G 37G 21% /
tmpfs tmpfs 1.7G 0 1.7G 0% /dev/shm
tmpfs tmpfs 5.0M 8.0K 5.0M 1% /run/lock
srv1.example.com:/home/nfsshare nfs4 40G 9.8G 28G 27% /mnt
If you want to mount the NFS share automatically every time, open the /etc/fstab file.
sudo nano /etc/fstab
Add a new line at the end of the file.
# /etc/fstab: static file system information.
#
# <file system> <mount point> <type> <options> <dump> <pass>
# / was on /dev/sda2 during curtin installation
/dev/disk/by-uuid/3fe5d1b3-fd02-4c71-80df-eaf44cbec7d5 / ext4 defaults 0 1
/swap.img none swap sw 0 0
srv1.example.com:/home/nfsshare /mnt nfs defaults 0 0
Save and exit.
Mount with AutoFS
Using AutoFS on your Ubuntu 24.04 client automatically mounts NFS shares whenever you need them, ensuring constant access. First, install the tool by running: ‘sudo apt install autofs’. Then, open its main configuration file with: ‘sudo nano /etc/auto.master’.
Run the command below to install the tool.
sudo apt install autofs
Once installed, open its master file.
sudo nano /etc/auto.master
Then, add a new line at the end of the file.
/- /etc/auto.mount
Save and exit.
Next, open the [auto.mount] config file.
sudo nano /etc/auto.mount
Then, add a new line to the file.
# [mount point] [option] [location]
/mnt -fstype=nfs,rw srv1.example.com:/home/nfsshare
Save and exit.
Restart AutoFS services.
sudo systemctl restart autofs
Verify the mount.
df -hT /mnt
You should see an output similar to the one below.
Filesystem Type Size Used Avail Use% Mounted on
srv1.example.com:/home/nfsshare nfs4 40G 9.8G 28G 27% /mnt
That should do it!
Conclusion:
In conclusion, setting up an NFS server on Ubuntu 24.04 enables efficient file sharing across a network. Following the outlined steps, you can successfully configure the server and client. Here are the key takeaways:
- NFS Overview: The network file system (NFS) allows files and directories to be shared over a network.
- Installation Steps: Use
sudo apt install nfs-kernel-serverto install the NFS server. - Configuration: Modify the
/etc/idmapd.conffile to set your domain name and manage user permissions effectively. - Exporting Shares: Edit the
/etc/exportsfile to export specific directories, controlling access with various options. - Client Setup: Install NFS client packages (
nfs-common) and configure the client to access the server shares. - Mounting NFS Shares: Use commands like
mountor modify/etc/fstabfor automatic mounting. - AutoFS Tool: For automatic mounts accessible to all users, install and configure AutoFS.
These steps ensure a secure and efficient NFS setup on your Ubuntu system.
Does Ubuntu support NFS?
Ubuntu 22.04 LTS (“Jammy”) and later have a new configuration file format for the NFS packages. Instead of multiple files sourced by startup scripts from /etc/default/nfs-* , there is one main configuration file in /etc/nfs.
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.
[…] How to install and export NFS share on Ubuntu […]