Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
Examendoelen in dit hoofdstuk
- Netwerkbestandssystemen met NFS koppelen en ontkoppelen
- autofs instellen
Understand NFS and its security
An NFS server exports folders; clients mount them like a local disk. RHEL uses NFSv4 by default (one TCP port: 2049).
- By default (
sec=sys) the server trusts the UID and GID the client sends. Users need the same UIDs on all systems (or central users from IdM/LDAP). - root_squash (default) maps root on the client to the user
nobody, so client root is not root on the share. - For real security use Kerberos (
sec=krb5p: authentication and encryption).
Set up an NFS server
Install nfs-utils, write the exports, start the service and open the firewall.
- Install and create the folder to share.
- Describe the exports./etc/exports
/nfsdata 192.168.122.0/24(rw,sync) /home/ldap 192.168.122.0/24(rw,sync,no_root_squash) - Start the server and open the firewall.
systemctl enable --now nfs-server firewall-cmd --add-service={nfs,mountd,rpc-bind} --permanent firewall-cmd --reload - Check the exports.
| Export option | Meaning |
|---|---|
rw / ro | Read-write / read-only |
sync | Write to disk before answering (safe) |
root_squash | Client root → nobody (default) |
no_root_squash | Client root stays root (only for trusted clients) |
all_squash | Every user → nobody |
Notitie
mountd and rpc-bind are only needed for NFSv3 and for showmount. Pure NFSv4 needs only the nfs service.
Mount an NFS share
See what the server offers, then mount it like a disk with type nfs.
dnf install -y nfs-utils
showmount -e server1
Export list for server1:
/home/ldap 192.168.122.0/24
/nfsdata 192.168.122.0/24
mkdir /mnt/data
mount -t nfs server1:/nfsdata /mnt/data
findmnt /mnt/data
umount /mnt/dataOnthoud
With NFSv4 you can also mount the server root and browse: mount server1:/ /mnt shows all exports as folders.
Mount NFS through fstab
For a share that must always be there, add it to /etc/fstab with _netdev, so it is mounted after the network is up.
Understand autofs
autofs mounts a share only when someone opens its folder, and unmounts it after some idle minutes. No boot problems when the server is away, and no need to mount many home folders.
Define an indirect autofs mount
An indirect map creates subfolders under a base folder: /shares/data is mounted when someone opens it.
- Add a line to the master map./etc/auto.master.d/shares.autofs
/shares /etc/auto.shares - Create the map: key, mount options, source./etc/auto.shares
data -rw server1:/nfsdata - Restart autofs and open the folder.
Notitie
The folder /shares/data appears only when you open it (ls /shares can be empty before). Do not create it yourself.
Use wildcards for home folders
With * as the key and & in the source, one line serves every user: /home/ldap/lisa mounts server1:/home/ldap/lisa.
/home/ldap /etc/auto.home* -rw server1:/home/ldap/&Use a direct autofs mount
A direct map mounts at a full path anywhere in the file system. In the master map the base is /-.
Remember the main points
The most important facts of this chapter, in short.
- NFS shares folders over the network. RHEL uses NFSv4 by default (port 2049).
- Server: install
nfs-utils, write the share in/etc/exports, runexportfs -r,systemctl enable --now nfs-server, open the servicesnfs(andmountd,rpc-bindfor showmount). - Client:
showmount -e SERVERlists shares;mount SERVER:/path /mntmounts one. - At boot: an fstab line with type
nfsand the option_netdev. - autofs mounts shares only when a user opens the folder and unmounts them later.
- Master map
/etc/auto.master.d/NAME.autofs; the map file lists the keys and shares. - An indirect map mounts under one base folder; a wildcard map (
* -rw server:/home/&) works for all user folders; a direct map uses full paths (/-).
Learn the key terms
The words of this chapter in simple English.
| Term | Meaning |
|---|---|
| NFS | Network File System: share folders between Linux systems. |
| Export | A folder that the NFS server shares. |
| /etc/exports | The list of exports and who may use them. |
| showmount | A tool that lists the exports of a server. |
| _netdev | An fstab option: wait for the network before mounting. |
| autofs | A service that mounts shares when they are used. |
| Master map | The autofs file that points to the map files. |
| Indirect map | A map with keys under one base folder. |
| Direct map | A map with full mount paths. |
| Wildcard map | A map with * and & that works for many folders. |
Check what you learned
Think about the answer first, then open it.
1How do you see the shares of server2?
2Write an fstab line that mounts server2:/data on /mnt/data at boot.
server2:/data /mnt/data nfs defaults,_netdev 0 0.
3Which file shares /data with the network 192.168.122.0/24, read-write?
/etc/exports with the line /data 192.168.122.0/24(rw).
4How do you load a changed /etc/exports without a restart?
5Home folders of LDAP users must appear under /home/remote when they are used. Which autofs lines do you write?
/home/remote /etc/auto.remote in a file in /etc/auto.master.d/, and * -rw server:/home/remote/& in /etc/auto.remote.
6What does & mean in an autofs map?
It is replaced by the key (the folder name the user opened).
7Which service must run for autofs?
autofs (systemctl enable --now autofs).
8Why does ls /home/remote show nothing before a user logs in?
autofs mounts a folder only when it is opened by its name.