1 00:00:00,000 --> 00:00:10,400 In this video, we'll talk about the NFS file services. 2 00:00:10,400 --> 00:00:16,360 NFS is a service that can be used to export directories to NFS clients. 3 00:00:16,360 --> 00:00:21,480 It is a UNIX native file sharing protocol that has been around for a long time. 4 00:00:21,480 --> 00:00:26,879 And it's fast and simple because it is implemented at a Linux kernel level. 5 00:00:26,879 --> 00:00:32,799 In NFS, shares are defined in the etc exports directory, and the NFS server service offers 6 00:00:32,799 --> 00:00:35,919 access to these shares. 7 00:00:35,919 --> 00:00:43,439 Common NFS is using version 4 and later, which offers NFS access on TCP port 2049. 8 00:00:43,439 --> 00:00:50,799 NFS version 3 was taking a different approach, but that is really very old and is deprecated 9 00:00:50,799 --> 00:00:54,560 since the early 2000s. 10 00:00:54,560 --> 00:01:00,040 In legacy NFS, they were using dynamic ports, and these dynamic ports made it harder to 11 00:01:00,040 --> 00:01:02,400 allow it through a firewall. 12 00:01:02,400 --> 00:01:08,800 NFS client uses show mount minus E command to discover shares on the server. 13 00:01:08,800 --> 00:01:14,120 An NFS client can use mount with the optional minus T NFS to identify the mount type as 14 00:01:14,120 --> 00:01:21,559 NFS, followed by server name colon share name on slash mount point, which is the local mount 15 00:01:21,559 --> 00:01:24,839 point for the NFS share. 16 00:01:24,839 --> 00:01:29,680 If you want to allow NFS traffic through the firewall, in many cases, just opening port 17 00:01:29,680 --> 00:01:33,160 2049, surprisingly, is not enough. 18 00:01:33,160 --> 00:01:39,160 And that is because many NFS-related client utilities are still using older components. 19 00:01:39,160 --> 00:01:45,559 And that is why on a firewall, you need to add a couple of services, including RPC bind, 20 00:01:45,559 --> 00:01:47,599 mount D, and NFS. 21 00:01:47,599 --> 00:01:50,720 Let me show you how to set up an NFS server. 22 00:01:50,720 --> 00:01:57,279 So first thing is to install it, dnfsrc, NFS is a good way to get started. 23 00:01:57,279 --> 00:01:59,360 And here you can see all the packages. 24 00:01:59,360 --> 00:02:04,000 Now for the client as well as the server, the packages you need is NFS utils. 25 00:02:04,000 --> 00:02:09,440 So dnfsrc install minus Y NFS utils is taking care of that. 26 00:02:09,440 --> 00:02:11,800 Then you need to create an export. 27 00:02:11,800 --> 00:02:15,639 And let me create this etc exports file. 28 00:02:15,639 --> 00:02:19,919 And in this etc exports file, I'm defining what I want to export. 29 00:02:19,960 --> 00:02:23,759 I'm going to export a random directory, let's say var. 30 00:02:23,759 --> 00:02:27,000 Next, I need to specify to whom I'm exporting it. 31 00:02:27,000 --> 00:02:28,520 And I'm using star. 32 00:02:28,520 --> 00:02:31,639 NFS is doing host-based access control. 33 00:02:31,639 --> 00:02:35,479 And if I'm using star, then any host can access. 34 00:02:35,479 --> 00:02:39,720 Rw is for read-write, so the client has read-write access. 35 00:02:39,720 --> 00:02:47,839 And no root squash means that if the client user is a user root, that is OK and will still be the 36 00:02:47,839 --> 00:02:50,279 user root on the remote host. 37 00:02:50,279 --> 00:02:56,320 So now that I have my etc exports, I can use systemctl start nfs. 38 00:02:56,320 --> 00:03:04,039 And what we need here, I'm using tab completion, as you can see, is the nfsserver.service. 39 00:03:04,039 --> 00:03:05,679 Then we go for the firewall. 40 00:03:05,679 --> 00:03:16,759 So firewallcmd minus minus add service, nfs minus minus permanent. 41 00:03:16,759 --> 00:03:24,479 Also, we need to add rpcbind. 42 00:03:24,479 --> 00:03:27,880 And we need to add mountd. 43 00:03:27,880 --> 00:03:31,520 That was a typo, it's not mount, it's mountd. 44 00:03:31,520 --> 00:03:34,119 So I've added them in the permanent configuration. 45 00:03:34,119 --> 00:03:39,240 So I'm using firewallcmd minus minus reload to reload the firewall. 46 00:03:39,240 --> 00:03:45,119 And I'm going for a simple test on my local machine, show mount minus e local host. 47 00:03:45,119 --> 00:03:48,080 And there we can see that the mounts are working. 48 00:03:48,080 --> 00:03:53,880 Now that they are working on a local host, I can access them from a remote host as well. 49 00:03:53,880 --> 00:03:56,880 So I need to go to 29.1.11. 50 00:03:56,880 --> 00:04:02,039 So now I'm on my client machine, and there I'm going to use mount of what? 51 00:04:02,039 --> 00:04:11,720 Well, 192.168.29.1.11 colon slash var, and I'm going to mount it on slash mnt. 52 00:04:11,720 --> 00:04:13,479 Oh, I'm a student user. 53 00:04:13,479 --> 00:04:15,839 Let's do this with sudo privileges. 54 00:04:15,839 --> 00:04:25,079 So I need sudo dnf install nfs utils, because that is required also for client functionality. 55 00:04:25,079 --> 00:04:34,359 Next, from a sudo shell, I'm going to use show mount minus e on 192.168.29.1.11. 56 00:04:34,359 --> 00:04:36,799 And that's showing the mount, so that's good news. 57 00:04:36,799 --> 00:04:44,559 And I'm going to use mount 192.168.29.1.11 colon slash var on mnt. 58 00:04:44,559 --> 00:04:48,079 I'm just making a temporary mount, and that is OK. 59 00:04:48,079 --> 00:04:54,480 And you can see that in the mnt directory, I now have access to the nfs shared directory. 60 00:04:54,480 --> 00:04:57,920 And mount on the bottom line of the output is confirming this as well. 61 00:04:57,920 --> 00:05:00,079 So it's working.