Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Learn how to configure an Ubuntu Network File System (NFS) server, export shared directories, connect Ubuntu clients, configure persistent mounts, secure access and troubleshoot common NFS problems.
NFS allows an Ubuntu server to export directories over the network so authorized Linux clients can mount those directories and work with remote files as though they were part of the local filesystem.
$ sudo apt install nfs-kernel-server $ sudo exportfs -ra $ sudo mount 192.168.1.10:/srv/nfs /mnt/nfs
Install the Ubuntu NFS server package and create the directory you want to share.
Use /etc/exports to define which clients can access
the exported directory.
Install NFS client utilities and mount the remote export on the Ubuntu client.
Configure /etc/fstab so the NFS share can be mounted
automatically after reboot.
Network File System (NFS) is a network filesystem protocol that allows one Linux system to share directories with other systems over a network. On Ubuntu, an NFS server exports a directory, while an NFS client mounts that export into its local filesystem.
This makes NFS useful for centralized storage, Linux home directories, application data, virtualization environments, development labs, backup repositories and shared files between Ubuntu servers.
In this tutorial, we will build a complete Ubuntu NFS environment using one Ubuntu server and one Ubuntu client. The example configuration uses a private network and restricts access to the client subnet rather than exposing the share to every host.
Ubuntu Network File System refers to using NFS on Ubuntu systems to provide network-based filesystem access. The server makes a directory available through an NFS export, and the client mounts that export at a local directory.
After mounting, applications on the client can normally access the remote directory using standard filesystem operations such as reading, writing, creating and deleting files, subject to the permissions configured on both systems.
| Component | Purpose | Ubuntu Package / Configuration |
|---|---|---|
| NFS Server | Exports directories to authorized clients. | nfs-kernel-server |
| NFS Client | Mounts and accesses remote NFS exports. | nfs-common |
| Export Configuration | Defines which clients can access shared directories. | /etc/exports |
| Persistent Mounts | Mounts NFS shares automatically through system configuration. | /etc/fstab |
The basic NFS architecture is simple: the server owns the physical data and exports a directory, while the client connects to that export and mounts it locally.
In this example, the server address is
192.168.1.10 and the client address
is 192.168.1.20. These are examples;
replace them with the addresses used in your own environment.
Before configuring NFS, prepare two Ubuntu systems that can communicate with each other over the network.
/etc/fstab may no longer be
able to mount the share.
sudo apt update
sudo apt install nfs-kernel-server
Ubuntu’s current server documentation uses
nfs-kernel-server for installing
the NFS server functionality.
sudo systemctl status nfs-server
If required, start the service with:
sudo systemctl start nfs-server
The /etc/exports file defines the
directories exported by the NFS server and the clients or networks
allowed to access them.
Open the file:
sudo nano /etc/exports
Add an entry similar to the following:
/srv/nfs 192.168.1.0/24(rw,sync,no_subtree_check)
In this example, clients on the
192.168.1.0/24 network are allowed
read/write access.
| Option | Purpose |
|---|---|
rw |
Allows clients to read and write data. |
ro |
Exports the directory as read-only. |
sync |
Requests synchronous writes and is a common conservative choice for shared data. |
no_subtree_check |
Disables subtree checking for the export. |
root_squash |
Maps remote root access to an anonymous identity rather than granting remote root the same root privileges on the server. |
no_root_squash simply to make permissions
problems disappear. It can grant remote root users powerful access
to files on the NFS server. Use it only when a specific, understood
requirement justifies it.
After modifying /etc/exports, reload
the export configuration with:
sudo exportfs -ra
The -r option re-exports directories,
while -a applies the operation to
all exports.
Verify the active exports:
sudo exportfs -v
You should see the exported directory together with the configured client restrictions and options.
If a firewall is active on the NFS server, allow NFS traffic from the client network rather than opening the service broadly to untrusted networks.
For an NFSv4-focused deployment, TCP port
2049 is the important NFS service
port. Ubuntu’s documentation also notes that NFS-related services and
configuration can vary depending on the Ubuntu release and NFS setup.
With UFW, an example restricted rule is:
sudo ufw allow from 192.168.1.0/24 to any port 2049 proto tcp
Check the resulting firewall configuration:
sudo ufw status
Move to the Ubuntu client machine and install
nfs-common.
sudo apt update
sudo apt install nfs-common
The package provides the client-side NFS utilities required to mount network filesystems.
Create a mount point on the client:
sudo mkdir -p /mnt/nfs
Mount the server’s exported directory:
sudo mount 192.168.1.10:/srv/nfs /mnt/nfs
Verify the mounted filesystem:
df -h /mnt/nfs
Then list its contents:
ls -la /mnt/nfs
You should see the test.txt file
created earlier on the server.
If the export and filesystem permissions allow writing, test the connection from the client:
echo "Created from NFS client" | sudo tee /mnt/nfs/client-test.txt
Check the server’s /srv/nfs directory
to confirm the file has been created.
A manually mounted NFS filesystem normally needs to be mounted again
after a reboot. You can configure a persistent mount through
/etc/fstab.
Open the client configuration:
sudo nano /etc/fstab
Add:
192.168.1.10:/srv/nfs /mnt/nfs nfs defaults,_netdev 0 0
The _netdev option identifies the
filesystem as network-dependent. This helps the system treat the mount
as dependent on network availability.
After editing /etc/fstab, reload
systemd’s configuration:
sudo systemctl daemon-reload
Test the configuration without rebooting:
sudo umount /mnt/nfs
sudo mount -a
df -h /mnt/nfs
/etc/fstab can affect system mounting
behavior. Testing with mount -a before rebooting gives you
an opportunity to identify problems.
One of the most common sources of confusion with NFS is the difference between an NFS export permission and the Linux filesystem permission.
An export can permit a client to access a directory with read/write privileges, but the underlying Unix ownership and mode bits still affect what users can actually do.
| Layer | Example | What It Controls |
|---|---|---|
| NFS Export | rw |
Whether the authorized NFS client can perform read/write operations through the export. |
| Linux Ownership | user:group |
Which Unix user and group own files and directories. |
| Linux Permissions | 755, 775, etc. |
Read, write and execute permissions for owner, group and others. |
| Identity Mapping | UID/GID | How user and group identities are interpreted between systems. |
NFS should normally be deployed on a trusted network or protected network segment. Do not treat NFS as an Internet-facing file-sharing protocol.
root_squash rather than disabling root squashing without a specific reason.
Ubuntu’s current server documentation describes Kerberos-backed NFS
configurations using security modes such as krb5,
krb5i and krb5p, with
krb5p providing authentication, integrity and privacy
protection.
If the client receives a permission error, check both the export and the filesystem permissions.
sudo exportfs -v
ls -ld /srv/nfs
Confirm that the client’s address is allowed by
/etc/exports and reapply the export:
sudo exportfs -ra
First test basic network connectivity:
ping 192.168.1.10
Then verify that the NFS service is running on the server:
sudo systemctl status nfs-server
Also check firewall rules and confirm that TCP port 2049 is reachable from the client when using the NFSv4 workflow described here.
On the server, inspect the active exports:
sudo exportfs -v
Re-read the export configuration:
sudo exportfs -ra
Make sure the client mount directory exists and is not being used as a location for important local files.
sudo mkdir -p /mnt/nfs
ls -la /mnt/nfs
Test the entry manually:
sudo umount /mnt/nfs
sudo mount -a
If the command returns an error, correct the
/etc/fstab entry before rebooting.
| Command | Purpose | Run On |
|---|---|---|
systemctl status nfs-server |
Check the NFS server service. | Server |
exportfs -v |
Display active NFS exports. | Server |
exportfs -ra |
Reapply export configuration. | Server |
showmount -e SERVER_IP |
Query exported filesystems where supported by the server/client setup. | Client |
mount | grep nfs |
Display currently mounted NFS filesystems. | Client |
df -h |
Display mounted filesystem capacity. | Client |
nfsstat -c |
Display NFS client statistics. | Client |
nfsstat -s |
Display NFS server statistics. | Server |
This NFS tutorial can serve as part of a broader VMoreCloud Ubuntu and Linux infrastructure topic cluster. Continue with related storage, networking, firewall and Ubuntu Server guides.
NFS, or Network File System, allows an Ubuntu server to share directories over a network so authorized clients can mount and access those directories as part of their local filesystem.
The standard Ubuntu NFS server package is
nfs-kernel-server.
Ubuntu clients use the nfs-common package for NFS client
functionality.
The primary export configuration is stored in
/etc/exports. After changing it, use
exportfs -ra to apply the export configuration.
Add the NFS server path, mount point and filesystem type to
/etc/fstab. Using _netdev identifies the
filesystem as network-dependent.
Standard NFS deployments do not automatically provide encrypted application data simply because NFS is being used. For environments requiring stronger authentication, integrity and privacy protections, Ubuntu supports Kerberos-based NFS security configurations.
Windows versions and editions have varied in their NFS client/server capabilities. If the primary clients are Windows systems, SMB is often the more natural file-sharing protocol. For Linux-to-Linux infrastructure, NFS is a common choice.
Setting up an Ubuntu Network File System (NFS) provides a straightforward way to centralize shared Linux storage and make it available to authorized systems across a network.
The basic workflow is:
nfs-kernel-server on the Ubuntu server./etc/exports.exportfs.nfs-common on the client./etc/fstab for persistent mounts.For a small Linux lab, this setup can provide a useful centralized storage layer. In larger environments, combine NFS with appropriate storage architecture, identity management, monitoring, backups and security controls.
Continue exploring practical Ubuntu Server, Linux networking, storage, virtualization and infrastructure administration guides from VMoreCloud.
Explore More Linux & Cloud GuidesWe have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.