Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
Vaardigheden in dit hoofdstuk
- NFS-shares koppelen met de hand, in fstab en met autofs
Know NFS
The server exports folders. The client mounts them. RHEL uses NFSv4 (version 4.2) by default: one TCP port (2049), good security and locking.
server2 (NFS server) server1 (client)
/srv/nfs/shared ── export ──► network ──► mount on /mnt/sharedOn the client you need the package nfs-utils:
dnf install nfs-utilsFind the exports of a server
List what a server shares. With NFSv4 you can also mount the root of the server and look around.
Mount a share by hand
mount SERVER:/PATH FOLDER mounts until the next reboot. Check the NFS version and options with nfsstat -m or findmnt.
mkdir -p /mnt/shared
mount -t nfs server2:/srv/nfs/shared /mnt/shared
mount -t nfs -o vers=4.2,rw,sync server2:/srv/nfs/shared /mnt/shared
findmnt /mnt/shared
TARGET SOURCE FSTYPE OPTIONS
/mnt/shared server2:/srv/nfs/shared nfs4 rw,relatime,vers=4.2,rsize=262144,wsize=262144,hard,proto=tcp,...
nfsstat -m
umount /mnt/shared| Option | Meaning |
|---|---|
rw / ro | Read-write / read-only |
vers=4.2 | Force an NFS version |
sync | Write at once (safer, slower) |
hard (default) | Retry forever when the server is gone — programs wait |
soft | Give up after a time with an error (data risk on writes) |
sec=krb5p | Kerberos login and encryption (needs a Kerberos setup) |
Mount at boot with fstab
An fstab line with the type nfs mounts the share at every boot. _netdev tells systemd to wait for the network.
Mount on demand with autofs
autofs watches a folder. When somebody opens a name in it, autofs mounts the share; after some minutes without use, it unmounts it.
dnf install autofs
vim /etc/auto.master.d/shares.autofs
vim /etc/auto.shares
systemctl enable --now autofs
ls /shares
ls /shares/work
findmnt /shares/work/shares /etc/auto.shares --timeout=300work -rw,sync server2:/srv/nfs/shared
public -ro server2:/srv/nfs/public- The master map (
/etc/auto.master.d/*.autofs) says: the folder/sharesis managed by the map/etc/auto.shares. - The map has one line per key: name, options,
server:/path. ls /sharesis empty at first.ls /shares/workmounts it.
Onthoud
Do not create /shares/work yourself — autofs makes and removes it. /shares itself is created by autofs too.
Mount every home folder with a wildcard
With * and &, one line mounts the home folder of every user: * = any key, & = the same key in the path.
/home/remote /etc/auto.home* -rw,sync server2:/srv/nfs/home/&systemctl reload autofs
ls /home/remote/anna
findmnt /home/remote/anna
TARGET SOURCE FSTYPE OPTIONS
/home/remote/anna server2:/srv/nfs/home/anna nfs4 rw,relatime,...Examentip
"The home folders of the NFS users must be mounted on /home/remote/USER when used" = an autofs wildcard map. Test with one user name.
Use a direct map
A direct map mounts a share on an exact, full path (not inside a managed folder). The master map uses the key /-.
/- /etc/auto.direct/srv/reports -ro server2:/srv/nfs/reports| Map type | Master line | Key in the map | Mounts on |
|---|---|---|---|
| Indirect | /shares /etc/auto.shares | work | /shares/work |
| Wildcard | /home/remote /etc/auto.home | * with & | /home/remote/NAME |
| Direct | /- /etc/auto.direct | /srv/reports (full path) | /srv/reports |
Find NFS problems
Check the network, the server's export, and the client config — in this order.
ping -c1 server2
nc -zv server2 2049
showmount -e server2
journalctl -u autofs -n 20
automount -m | head -20
systemctl status autofs| Error | Likely cause |
|---|---|
access denied by server | The client's address is not in the server's export list |
No route to host / timeout | Firewall on the server: open the nfs service |
Folder in /shares does not appear | Typo in the map, or autofs not reloaded |
Permission denied on files | UID of the user differs between client and server |
More: the RHCSA NFS chapter.