Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Linux NFS Server Setup for Your Home Network

· 6 min read · Home Networking

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

Setting up an NFS (Network File System) server on a Linux machine lets you share folders with other computers on your home network as if they were local drives. It's fast, native to Linux, and ideal for media libraries, backups, or shared documents. This guide walks you through the setup on a Debian/Ubuntu-based server (the steps are similar on other distros with slightly different package commands). You'll need a Linux machine with a static IP (or a DHCP reservation) and at least one client that supports NFS (Linux, macOS, or Windows with extra software).

What You'll Need

  • A Linux machine (the server) with root or sudo access
  • A second device to test the connection (Linux, macOS, or Windows)
  • A network with both devices on the same subnet
  • Optional: a fixed IP address for the server (set in your router's DHCP settings)

Step-by-Step

  1. Install the NFS server package. On Debian/Ubuntu, run: sudo apt update && sudo apt install nfs-kernel-server. On Fedora/RHEL, use sudo dnf install nfs-utils. This installs the server daemon and supporting tools.
  2. Create the directory you want to share. For example, sudo mkdir -p /srv/nfs/media. Make sure the folder has appropriate permissions; you may want to set ownership to a user that will write to it: sudo chown nobody:nogroup /srv/nfs/media (on Debian/Ubuntu) or sudo chown nobody:nobody (on Fedora).
  3. Edit the exports file. Open /etc/exports with a text editor (e.g., sudo nano /etc/exports). Add a line that defines the share and which clients can access it. For example, to allow any device on your local 192.168.1.0/24 network read-write access:
    /srv/nfs/media 192.168.1.0/24(rw,sync,no_subtree_check)
    Replace the IP range with your own. If you want read-only, use ro instead of rw. You can also specify a single IP like 192.168.1.50.
  4. Apply the exports. Run sudo exportfs -ra to reload the configuration. Then verify with sudo exportfs -v to see the active shares.
  5. Start and enable the NFS service. On systemd systems, run sudo systemctl enable --now nfs-server (on Debian/Ubuntu) or sudo systemctl enable --now nfs-server (on Fedora, the service name might be nfs-server as well). Check its status with sudo systemctl status nfs-server.
  6. Configure the firewall (if enabled). If you use UFW (Ubuntu), allow NFS traffic: sudo ufw allow from 192.168.1.0/24 to any port nfs. If you use firewalld (Fedora), run sudo firewall-cmd --permanent --add-service=nfs and sudo firewall-cmd --reload. NFS uses port 2049 by default; you may also need to allow portmapper (111) and rquotad, but most modern setups work with just the NFS service.
  7. Test the share locally. On the server, mount the share to a temporary directory to verify it works: sudo mount -t nfs localhost:/srv/nfs/media /mnt. If that succeeds, unmount with sudo umount /mnt.
  8. Connect from a client. On a Linux client, install the NFS client package if needed (sudo apt install nfs-common on Debian/Ubuntu). Then create a mount point and mount: sudo mkdir -p /mnt/media and sudo mount -t nfs 192.168.1.100:/srv/nfs/media /mnt/media (replace the IP with your server's IP). You should now see the shared files.
  9. Make the mount permanent (optional). Add an entry to /etc/fstab on the client: 192.168.1.100:/srv/nfs/media /mnt/media nfs defaults,timeo=50,retrans=2 0 0. Test with sudo mount -a.

Common Mistakes

  • Wrong IP range in exports. If you use a subnet mask like /24 but your network is actually /16, clients will be denied. Check your router's subnet.
  • Forgetting to restart the service after editing exports. Always run sudo exportfs -ra after changes.
  • Permission errors. If the client can't write, the folder ownership and permissions on the server may be too restrictive. Use chmod and chown appropriately.
  • Firewall blocking. Many home routers have a built-in firewall; if the client can't connect, check both the server's firewall and the router's settings.
  • Using a hostname instead of an IP. If your server's hostname isn't resolvable from the client, the mount will fail. Use the IP address.

Tips

  • Set a static IP for your server via your router's DHCP reservation to avoid IP changes breaking mounts.
  • Use no_subtree_check to improve performance, but be aware it reduces some security checks (acceptable on a trusted home network).
  • For large media libraries, consider enabling async in the exports options for better write performance, but know that a crash could cause data loss. Use sync for critical data.
  • If you have multiple clients, you can specify multiple IPs or subnets in the exports file by repeating the path with different options.
  • Test with a small file first to verify read/write permissions before moving bulk data.

Troubleshooting

Client cannot mount: First, check if the server is reachable with ping. Then verify the NFS service is running on the server (sudo systemctl status nfs-server). Check the exports list with sudo exportfs -v on the server. On the client, try mounting with verbose output: sudo mount -v -t nfs server:/share /mnt to see error messages.

Permission denied: Check the folder permissions on the server. If the client user is not mapped to a user on the server, you may need to use anonuid and anongid in the exports options to map anonymous users to a specific UID/GID. For example: rw,sync,no_subtree_check,anonuid=1000,anongid=1000.

Slow performance: Try adding rsize=8192,wsize=8192 to the mount options on the client. Also check network cables or Wi-Fi signal strength.

Mount hangs: This often indicates a firewall blocking port 2049. On the server, ensure the firewall allows NFS. On the client, try adding timeo=50,retrans=2 to the mount options to reduce timeout delays.

If nothing works: Restart the NFS service on the server (sudo systemctl restart nfs-server). Also, check the server's logs with sudo journalctl -u nfs-server for clues.

Frequently Asked Questions

Can I use NFS on Windows?

Yes, Windows 10/11 Pro and Enterprise include a built-in NFS client. You can enable it via 'Optional Features' in Settings, then mount with mount -o anon \\server\share Z: from Command Prompt. It's less stable than Samba, so for Windows-heavy networks, Samba is often better.

Is NFS faster than Samba?

Generally, NFS has lower overhead and better performance for Linux-to-Linux transfers. Samba (SMB) is more compatible with Windows and often easier to set up for mixed networks. On a home network, the difference is usually negligible.

How do I share a folder with only one specific client?

In /etc/exports, replace the subnet with the client's IP address, e.g., /srv/nfs/media 192.168.1.50(rw,sync,no_subtree_check).

Can I mount NFS over the internet?

Technically yes, but it's insecure and not recommended. NFS has no encryption by default. Use a VPN or SSHFS instead for remote access.

How do I unmount a share?

On the client, run sudo umount /mnt/media. If it says the target is busy, close any open files or use sudo umount -l to lazy unmount.

What does 'sync' mean in the exports options?

It means the server writes data to disk before replying to the client's write request, ensuring data integrity. The alternative, async, can be faster but risks data loss on a power failure.