Introduction to Network File System (NFS)
From the NFS curriculum
Introduction to Network File System (NFS)
TL;DR
NFS lets you share files and directories over a network, making them appear as if they're on your local computer. It simplifies data access and management by centralizing storage. You can mount remote file systems and work with them just like local ones.
1. The Mental Model
Think of NFS as a magic cable that lets one computer (the client) access files stored on another computer (the server) as if those files were physically attached to the client. You don't need to copy files back and forth; you just use them directly.
2. The Core Material
Network File System (NFS) is a distributed file system protocol that allows a user on a client computer to access files over a computer network much like local storage is accessed. It's really useful for situations where multiple machines need to access the same data.
Here's how it generally works:
NFS Server Setup

Photo by panumas nikhomkhai on Pexels
First, you need a server that will share its files. This involves:
- Installing NFS packages: You'll install software like
nfs-kernel-serveron Linux. -
Configuring exports: You decide which directories on the server you want to share and with whom. This is done in a file, typically
/etc/exports. Each line specifies a directory, the client(s) allowed to access it, and options (like read-only or read-write access).- Example
/etc/exportsentry:
/data/shared_files 192.168.1.0/24(rw,sync,no_subtree_check) /home/user/docs client_hostname.example.com(ro,sync)rw: read/write accessro: read-only accesssync: changes are written to disk before the server replies (safer)async: server replies before changes are written (faster, riskier)no_subtree_check: avoids issues when a subdirectory of an exported file system is moved.
- Example
-
Starting NFS services: You start the NFS server daemon (e.g.,
nfs-kernel-serverornfsd).
NFS Client Setup

Photo by Vitaly Gariev on Pexels
Next, you need a client machine to access those shared files:
- Installing NFS packages: You'll install software like
nfs-commonon Linux. - Mounting the remote share: You tell your client machine to connect to the server's shared directory and make it available at a specific local directory (called a mount point).
- You can mount it temporarily with the
mountcommand:
bash sudo mount 199.10.1.5:/data/shared_files /mnt/nfs_share
Here,199.10.1.5is the server's IP,/data/shared_filesis the exported directory on the server, and/mnt/nfs_shareis where it will appear on your client. - For permanent mounts (after reboot), you add an entry to
/etc/fstab:
199.10.1.5:/data/shared_files /mnt/nfs_share nfs defaults 0 0
- You can mount it temporarily with the
How NFS Operates

Photo by Zafer Erdoğan on Pexels
When you try to access a file in /mnt/nfs_share on the client, your operating system intercepts the request. Instead of looking on the local disk, it sends the request over the network to the NFS server. The server then performs the requested operation (read, write, list directory) on its local storage and sends the result back to the client.
graph TD
Client["NFS Client (Your PC)"] --> |Request (Read/Write file)| Server["NFS Server (File Host)"]
Server --> |Accesses local disk| ServerDisk["Server's Local Disk"]
ServerDisk --> |Returns file data/status| Server
Server --> |Response (File data/Status)| Client
Client --> |Presents file as local| ClientApp["Applications on Client"]
3. Worked Example
Let's say you have an NFS server with IP 192.168.1.100 and you want to share a directory /srv/nfs/general with your client machine.
On the NFS Server (192.168.1.100):
- Create the directory to share:
bash sudo mkdir -p /srv/nfs/general sudo chmod 777 /srv/nfs/general # For basic testing, often more restrictive for production echo "Hello from NFS server!" | sudo tee /srv/nfs/general/hello.txt - Edit
/etc/exports:
bash sudo nano /etc/exports
Add this line:
/srv/nfs/general *(rw,sync,no_subtree_check,no_root_squash)*: allows access from any client (usually you'd use specific IPs or subnets).no_root_squash: allows therootuser on the client to have root privileges on the shared directory (be careful with this!).
- Export the shares and restart NFS:
bash sudo exportfs -a sudo systemctl restart nfs-kernel-server
You can check the exports withshowmount -e.
On the NFS Client:
- Create a mount point:
bash sudo mkdir -p /mnt/nfs_mount - Mount the share temporarily:
bash sudo mount 192.168.1.100:/srv/nfs/general /mnt/nfs_mount - Verify access:
bash ls /mnt/nfs_mount cat /mnt/nfs_mount/hello.txt
You should seehello.txtand its content. You can also try creating a new file:
bash echo "Client test file" > /mnt/nfs_mount/client_test.txt
This file will now exist on the server in/srv/nfs/general. - For persistent mounts, add to
/etc/fstab:
bash sudo nano /etc/fstab
Add this line:
192.168.1.100:/srv/nfs/general /mnt/nfs_mount nfs defaults 0 0
Then, you can test it by unmounting and remounting:
bash sudo umount /mnt/nfs_mount sudo mount -a # Mounts all entries in fstab ls /mnt/nfs_mount
4. Key Takeaways
- NFS lets you access files on a remote server as if they're on your local machine.
- The server exports directories, defining what clients can access and with what permissions.
- Clients mount these exported directories at a local mount point.
- NFS simplifies data sharing and centralizes storage for multiple clients.
- Permissions and security on NFS are crucial, often involving IP-based access control.
Common Mistakes:
- Firewall issues: Forgetting to open NFS ports (2049, 111, plus dynamic ports for rpcbind) on both server and client.
- Incorrect /etc/exports syntax: Small typos or wrong options can prevent shares from working.
- Permissions on the server: The shared directory on the server must have appropriate permissions for NFS users (often nobody or specific UIDs/GIDs).
- Not restarting NFS services: After changing /etc/exports, you must restart or reload the NFS server.
- Forgetting sudo: Most NFS commands require superuser privileges.
5. Now Try It
Set up a simple NFS share between two of your virtual machines or two Linux machines if you have them. Configure one as the NFS server to export a small directory (e.g., /var/nfsshare) and the other as the NFS client to mount it. Create a file on the server in the shared directory, then verify you can see and read it from the client. Then, create a new file from the client and verify it appears on the server.
Success looks like: You can ls the mounted directory on the client, see a file created on the server, and successfully create a new file from the client that appears on the server.
Frequently asked about Introduction to Network File System (NFS)
Get the full NFS curriculum
Clone the complete plan to your dashboard for unlimited AI-generated notes, practice quizzes, and a personalised revision schedule.
Create Free Account