Creating a NFS server
In this tutorial you will learn how to set up a NFS server (NFSv4).
Table of Contents
- Install NFS server utilities
- Add a network share (a shared folder)
- Reload NFS server
- NFS client
Install NFS server utilities
The required package names depends on the Linux distribution:
nfs-utilsin Arch Linux.
Add a network share (a shared folder)
/etc/exports with a root user or sudo. Add a line for every network share you want to add:
# An example: /srv/nfs 192.168.1.0/24(ro)
- You can add several hostnames (separated by spaces). Every hostname will need its options.
- Some options you can use are:
rw: write permissions.
no-root-squash: root user on the client will have same permissions as root user on the server. Use with caution.
root-squash: root user on the client is assigned UID of
nfsnobodyuser on the server, so they will not have special permissions on the server.
all_squash: NFS assigns UID for the user on the client (including root) to the UID of
nfsnobodyusers on the server, so the client does not have special permissions if the UID on the client and the server are the same.
When adding a shared folder, it is recommended to use a bind mount instead of share the file directly. For example, if you want to share
# as root mkdir /srv/nfs/music mount --bind /home/user/music /srv/nfs/music
# /etc/exports /srv/nfs/music 192.168.1.0/24(rw)
Reload NFS server
nfs-server service. Some systems don’t start and enable the service when nfs package is installed:
systemctl reload nfs-server
# Arch Linux systemctl start nfs-server systemctl enable nfs-server
Check if your OS requires a package to be installed in order to be able to mount NFS shares (like
nfs-utils in Arch Linux).
You can mount a NFS share like any other device:
# as root mkdir /mnt/nfs mount 192.168.1.8:/srv/music /mnt/nfs
If you need to access your NFS server outside your local network, you need to open port 2049 (TCP) on the server network.