The objective is to configure the NFS server on one of the servers in the LAB.
Creating the NFS client-server setup is a simple task that can be performed in a few steps – installation, export, mounting, and access.
On the server install the required package
apt install -y nfs-kernel-server
Create a directory that gets shared with the clients.
To allow all clients access permission to the export directory, we need to remove restrictive permissions.
chown nobody:nogroup /mnt/nfs chmod 755 /mnt/nfs
Create the NFS server configuration file /etc/exports, with contents as below, configuration for sharing the shared folder created above. In my case wanted to share with clients from two different subnets.
# /etc/exports: the access control list for filesystems which may be exported # to NFS clients. See exports(5). # # Example for NFSv2 and NFSv3: # /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check) # # Example for NFSv4: # /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check) # /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check) # /mnt/nfs 10.0.1.0/24(rw,sync,no_subtree_check) /mnt/nfs 10.0.2.0/24(rw,sync,no_subtree_check)
Note : rw: read and write operations sync: write any change to the disc before applying it no_subtree_check: no subtree checking
Export the shared directory listed in /etc/exports
On the client’s side install the required package
apt-get install nfs-common
Create a folder to be used as a mount point to mount the shared NFS folder
mkdir -p /mnt/nfs
Mount the shared folder
mount 10.0.1.1:/mnt/nfs /mnt/nfs
We need to mount this folder every time the VM starts – Add the following entry in /etc/fstab as follows
root@test:~# cat /etc/fstab # /etc/fstab: static file system information. # # Use 'blkid' to print the universally unique identifier for a # device; this may be used with UUID= as a more robust way to name devices # that works even if disks are added and removed. See fstab(5). # # systemd generates mount units based on this file, see systemd.mount(5). # Please run 'systemctl daemon-reload' after making changes here. # # <file system> <mount point> <type> <options> <dump> <pass> # / was on /dev/vda1 during installation UUID=e8272e4a-5782-4500-9e91-2bfe3c9da8fd / ext4 errors=remount-ro 0 1 # swap was on /dev/vda5 during installation UUID=f0f2cd7b-2c15-4bde-a3dc-ab2e1653ec56 none swap sw 0 0 /dev/sr0 /media/cdrom0 udf,iso9660 user,noauto 0 0 10.0.1.1:/mnt/nfs /mnt/nfs nfs4 defaults,user,exec,_netdev 0 0 root@test:~#