Chapter 19: Network file systems and autofs
Exercise: NFS and autofs review
Serve two directories from serverb, mount one permanently on servera, write a file across the network, and give servera an on-demand, read-only view of the other with an autofs wildcard map.
NFS and autofs review
- Export directories, start the server and open the firewall.
- Mount an export permanently with fstab and _netdev.
- Serve a read-only wildcard autofs map.
Before you start: reset the servers and complete this chapter's lessons. serverb is the server and servera the client; lab start and lab grade run on workstation.
- On both servers install
nfs-utilsif needed. On serverb, create/srv/projects(owned by student) and/srv/archive/2025/notes.txt. - Export
/srv/projectsread-write and/srv/archiveread-only to your lab network. - Start and enable
nfs-serverand open thenfsfirewall service permanently. - On servera, mount
serverb:/srv/projectson/mnt/projectsthrough fstab with_netdev. - As student on servera, write
written from serverainto/mnt/projects/from-client.txt. - On servera, install and enable autofs and serve
/remote/archive/KEYfromserverb:/srv/archive/KEYread-only with one wildcard line. - On workstation, fill in
answers.txt.
Start the exercise
[student@workstation ~]$ lab start sa-nfs-reviewThe server
[student@workstation ~]$ ssh student@serverb
[student@serverb ~]$ sudo -i
[root@serverb ~]# dnf install -y nfs-utils > /dev/null
[root@serverb ~]# mkdir -p /srv/projects /srv/archive/2025
[root@serverb ~]# chown student:student /srv/projects
[root@serverb ~]# echo "old notes" > /srv/archive/2025/notes.txt
[root@serverb ~]# cat > /etc/exports <<'EOT'
/srv/projects 172.25.250.0/24(rw,sync)
/srv/archive 172.25.250.0/24(ro,sync)
EOT
[root@serverb ~]# systemctl enable --now nfs-server
[root@serverb ~]# firewall-cmd --permanent --add-service=nfs; firewall-cmd --reload
success
success
[root@serverb ~]# exportfs -v | cut -c1-55
/srv/projects 172.25.250.0/24(sync,wdelay,hide,no_subtree_check,
/srv/archive 172.25.250.0/24(sync,wdelay,hide,no_subtree_check,On the lab, replace the network with the one your servers use (ip -br addr); the lab's own network may differ from the printed one.
The permanent mount and a write
[student@workstation ~]$ ssh student@servera
[student@servera ~]$ sudo -i
[root@servera ~]# dnf install -y nfs-utils > /dev/null
[root@servera ~]# mkdir -p /mnt/projects
[root@servera ~]# echo 'serverb:/srv/projects /mnt/projects nfs defaults,_netdev 0 0' >> /etc/fstab
[root@servera ~]# systemctl daemon-reload; mount -a
[root@servera ~]# findmnt /mnt/projects -o TARGET,SOURCE,FSTYPE
TARGET SOURCE FSTYPE
/mnt/projects serverb:/srv/projects nfs4
[root@servera ~]# su - student -c 'echo "written from servera" > /mnt/projects/from-client.txt'
[root@servera ~]# ls -l /mnt/projects
-rw-r--r--. 1 student student 21 Oct 3 19:20 from-client.txtautofs
[root@servera ~]# dnf install -y autofs > /dev/null
[root@servera ~]# echo '/remote/archive /etc/auto.archive' > /etc/auto.master.d/archive.autofs
[root@servera ~]# echo '* -ro,sync serverb:/srv/archive/&' > /etc/auto.archive
[root@servera ~]# systemctl enable --now autofs
[root@servera ~]# cat /remote/archive/2025/notes.txt
old notes
[root@servera ~]# touch /remote/archive/2025/x
touch: cannot touch '/remote/archive/2025/x': Read-only file systemGrade
On workstation, fill in answers.txt and grade:
Check your work with lab grade sa-nfs-review, then put the exercise away with lab finish sa-nfs-review.