In this video, we'll talk about the NFS file services.
NFS is a service that can be used to export directories to NFS clients.
It is a UNIX native file sharing protocol that has been around for a long time.
And it's fast and simple because it is implemented at a Linux kernel level.
In NFS, shares are defined in the etc exports directory, and the NFS server service offers
access to these shares.
Common NFS is using version 4 and later, which offers NFS access on TCP port 2049.
NFS version 3 was taking a different approach, but that is really very old and is deprecated
since the early 2000s.
In legacy NFS, they were using dynamic ports, and these dynamic ports made it harder to
allow it through a firewall.
NFS client uses show mount minus E command to discover shares on the server.
An NFS client can use mount with the optional minus T NFS to identify the mount type as
NFS, followed by server name colon share name on slash mount point, which is the local mount
point for the NFS share.
If you want to allow NFS traffic through the firewall, in many cases, just opening port
2049, surprisingly, is not enough.
And that is because many NFS-related client utilities are still using older components.
And that is why on a firewall, you need to add a couple of services, including RPC bind,
mount D, and NFS.
Let me show you how to set up an NFS server.
So first thing is to install it, dnfsrc, NFS is a good way to get started.
And here you can see all the packages.
Now for the client as well as the server, the packages you need is NFS utils.
So dnfsrc install minus Y NFS utils is taking care of that.
Then you need to create an export.
And let me create this etc exports file.
And in this etc exports file, I'm defining what I want to export.
I'm going to export a random directory, let's say var.
Next, I need to specify to whom I'm exporting it.
And I'm using star.
NFS is doing host-based access control.
And if I'm using star, then any host can access.
Rw is for read-write, so the client has read-write access.
And no root squash means that if the client user is a user root, that is OK and will still be the
user root on the remote host.
So now that I have my etc exports, I can use systemctl start nfs.
And what we need here, I'm using tab completion, as you can see, is the nfsserver.service.
Then we go for the firewall.
So firewallcmd minus minus add service, nfs minus minus permanent.
Also, we need to add rpcbind.
And we need to add mountd.
That was a typo, it's not mount, it's mountd.
So I've added them in the permanent configuration.
So I'm using firewallcmd minus minus reload to reload the firewall.
And I'm going for a simple test on my local machine, show mount minus e local host.
And there we can see that the mounts are working.
Now that they are working on a local host, I can access them from a remote host as well.
So I need to go to 29.1.11.
So now I'm on my client machine, and there I'm going to use mount of what?
Well, 192.168.29.1.11 colon slash var, and I'm going to mount it on slash mnt.
Oh, I'm a student user.
Let's do this with sudo privileges.
So I need sudo dnf install nfs utils, because that is required also for client functionality.
Next, from a sudo shell, I'm going to use show mount minus e on 192.168.29.1.11.
And that's showing the mount, so that's good news.
And I'm going to use mount 192.168.29.1.11 colon slash var on mnt.
I'm just making a temporary mount, and that is OK.
And you can see that in the mnt directory, I now have access to the nfs shared directory.
And mount on the bottom line of the output is confirming this as well.
So it's working.