← ../

Network File System Protocol (v4)

some prerequisites and pitfalls to avoid :

Firewall : the port TCP/2049 should allow inbound connections on the server (in prior versions of NFS, this was more complicated.)

UID/GID : in this setup, everyone can write files, but the standard unix permissions still apply. you may want to make consistent UID/GID either manually, or map them with with idmapd or with setgid etc

Server Configuration :

the nfs-server package (on debian) or the nfs-utils package (centos) needs to be installed

we can then create a directory that we will share with nobody as an owner, nogroup as group, and allow others to create files

mkdir -p /srv/nfs/data
sudo chown nobody:nogroup /srv/nfs/data
sudo chmod o+w /srv/nfs/data

the nfs mounts are defined in the /etc/exports file as such (edit file as root)

/srv/nfs/data 192.168.0.0/24(rw,sync,no_subtree_check)

entry meaning
/srv/nfs/data the folder we want to export (share)
192.168.0.0/24 the hosts that are allowed to access it (the clients)
(rw,sync,no_subtree_check) the nfs options for this mount (refer to the man page of exports for the full list of options

for the mounts that we created in /etc/exports to take effect, you need to issue the following command as root

exportfs -a

Client Configuration :

to mount manually :

sudo mkdir /mnt/data
sudo mount -t nfs 192.168.0.56:/srv/nfs/data /mnt/data/

entry meaning
-t nfs the type of the filesystem to mount
192.168.0.56 ip of the server
:/srv/nfs/data the shared directory path on the server
/mnt/data/ local directory on the client

to achieve the same thing in /etc/fstab (edit as root) :

192.168.0.56:/srv/nfs/data /mnt/data nfs defaults 0 0