NFS (Network File System) lets a client mount a directory from a server and use it like a local one. It is common between Linux and Unix systems.
Server setup
Install nfs-kernel-server on Debian and Ubuntu, or nfs-utils on Fedora and RHEL. Create a directory and describe the share in /etc/exports:
/srv/share 192.168.1.0/24(rw,sync,no_subtree_check)The line gives the directory, the allowed clients, and options in brackets. rw allows writing (ro is read-only), and sync replies only after changes reach stable storage.
Do not put a space before the bracket. 192.168.1.0/24 (rw) means the network gets default options and everyone else gets rw.
Apply and check:
$ sudo exportfs -ra
$ sudo exportfs -v-r re-exports according to the file and -a means all. Make sure the service runs: nfs-kernel-server on Debian, nfs-server on Fedora and RHEL.
Client side
Install nfs-common (Debian and Ubuntu) or nfs-utils, then mount:
$ sudo mkdir -p /mnt/share
$ sudo mount -t nfs 192.168.1.10:/srv/share /mnt/share
$ df -h /mnt/share
$ sudo umount /mnt/shareTo mount at boot, add a line to /etc/fstab:
192.168.1.10:/srv/share /mnt/share nfs defaults,_netdev 0 0_netdev marks it as needing the network.
Permissions
With the usual sys security, NFS trusts the numeric user and group IDs sent by the client. The same name with a different UID on each machine causes surprising "Permission denied" errors.
By default, root_squash maps the client's root user to an unprivileged account, usually nobody. Avoid no_root_squash unless you have a clear reason.
Because of this trust, export only to hosts you control, and allow it through the firewall only for them. NFSv4 uses TCP port 2049.
Review ownership basics in the permissions lab.
Try it
- In two virtual machines, export
/srv/shareread-only withro. - Mount it on the client and list the files.
- Try to create a file and note the error.
Check your understanding
NFS
All 5 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.