Hey everyone and welcome back. Now in the previous nugget we had just introduced the
concept of NFS, we learned how it was different although maybe similar to SAMBA, in that we
can ultimately share resources but what we're going to be focusing on is actually sharing
file systems and we understood that within this architecture we would have to configure
an NFS server. That is exactly what we're going to be focusing on in this nugget right
here. So with that said let's roll up our sleeves and dig in then share with. So what
I will do here is I will clear my screen right now and the very first thing which I am going
to do is I am going to install a particular package. Now this package here I'm going to
say sudo and I will say apt install and I will say nfs- and I was going to say server
it's not server it's hyphen kernel hyphen server. I'm getting myself confused here.
If I hit enter and I type in my password right here all I'll do is say yes and hit enter and
the installation should now begin. Okay so as we can see here everything has installed
correctly. Now that we have this the very first thing which I want to draw your attention
to and if I just clear my screen right now the very first thing is going to be in the
etsy directory there is going to be a file called exports. This is going to be the main
configuration file for NFS. As per usual with respect to the LPIC2 examination remembering
this location is certainly going to serve you well. Really within this configuration
file this is where we are going to specify what it is we want to share and who we want
to grant access to this share as well as like I say the permissions of what that particular
client can do with that particular share. All of that specified within this etsy export
file right here and in fact I've just caught myself that should be etsy exports with an
s on the end so really just remember that there almost made that mistake myself. So
check this out then if I clear my screen once again and I go into my etsy directory I do
an LS and I grant for exp. We can see we have indeed this file right here within the etsy
directory so let's go in and edit this file so we'll go into the etsy directory and open
exports. Now we can see here this is going to be the access control list for file systems
which may actually be exported when you're using NFS ultimately dictating what our NFS
clients can actually have access to. So remember as I mentioned what we want to do here is
we want to specify what it is you want to share who we want to share that with and then
in the brackets we want to specify the rules for that share i.e. what that person can actually
do with that share. Now with respect to what we can actually specify within this configuration
file there are a few different things. We can specify a particular hostname of a device
i.e. we had a particular hostname on our network we wanted to grant access to we could actually
use that hostname and grant that particular access. We could also specify something let's
say the domain i.e. the particular domain name for a group of devices maybe we've got a domain
such as CBTNuggets.com and we want to grant access to all machines within that domain we could
specify that domain within this configuration file or alternatively if we so wish we could specify
a particular network say for example we want to allow everyone within 192.168.1.0 slash 24 we
wanted to grant them particular access we could do so and within here we can also specify should
the share be ro i.e. should that share be read only meaning that the people can read the information
that we're sharing but they cannot create new files nor can they modify existing files or
alternatively you guessed that we could specify rw access read and write access meaning that we can
read and we can also create and modify files. Now we can also specify if we want to sync our
changes this means that whatever changes happen to be made within the share they are going to be
synced and written to the hard disk without any delay at all they're going to happen immediately
so those changes get synced quickly however we can specify a sync which means that changes to a
file system will not be made immediately instead those changes will be held in RAM now the advantage
here is that this is going to give you better performance it's going to be less taxing on the
machine to be writing and reading data from the disk just by holding it in memory the issue as you
can probably imagine is that when you hold data within RAM that data happens to be volatile i.e.
if the machine happened to crash and not correctly shut down or save the information which was held
in RAM can ultimately be wiped meaning that those changes can be lost this is a trade-off that we
have to consider do we want to have our changes be synced and immediately written to disk or do we
want to prefer the performance boost which may be valuable if we happen to have a large distributed
network all accessing a particular share maybe we want to aim for performance but run the risk of
potentially losing that data or losing some of that data whilst it is temporarily held in RAM
these are different options that we can consider now one big option we really want to be aware of
and we'll get to see this in a little bit more detail a little bit later on but ultimately we
have this problem here imagine we have our server here okay and then we have a client machine all
the way over here now as you know on your machine you're going to have a default root user this is
the super user who can do absolutely everything to that particular machine and likewise on the server
we're going to have that default root user too think about this when this server here is sharing
out a particular file system let's just maybe say within the mount directory we've got a file
system called i don't know fs1 whatever it may be doesn't actually matter this file system fs1 is going
to be transparently available on this machine right here it's going to appear like it actually exists
on the client even though it's been reached over the network now we know we have this root user here
on this machine now the question is the files within this particular directory here actually
physically exist on this machine where we have another root user now the question is do we want
this root user to have the exact same level of access and control as the actual root user on the
server now typically most people want to say no most people will pretty much say that okay we have
a root user on this machine here but we don't want to just transfer that ability of total power
to be able to execute within that share on the local system we want to have the root user on the
server itself still maintain that control in which case we actually have two different options here
and these are options again that we specify within this particular file those options happen to be
the first one is something called root squash so really if you do not want the remote root user
to have the same access as the root user within the local server you actually want to configure
this option i like to try to remember this as we are squashing the ability of the
remote client root user from being able to have total access however if we actually do want to
synchronize these root users i.e. we want the root user and the clients to be able to act with the
same type of authority as the local root account on the server itself we can synchronize these
root accounts so to speak and we can do so by specifying the option no underscore root underscore
squash so we can either squash the ability of the remote root user on the client or we can say we
do not want to squash that ability we can give them full access and full control all of these
options that we've seen here again specified within this file right here so with that said
let's actually create our own little share and begin using nfs then so what i will do here is i'm
going to create a share and i'll just call this my share again you know me never ever in danger of
being creative so so what i will do is i will move on over and what i now want to specify is who can
actually have access so what i can do here is i could say 192 168 maybe 0.100 let's say this was
a particular machine on the network and i wanted to allow access to that particular machine so what
i could do here is within brackets i could specify my permission so i could say that machine is allowed
to have read only access and when that machine connects i want to implement the root squash option
i.e the root user of that machine will not be able to execute within this particular directory as if
it was the root user of the local machine where the physical data actually resides let me just close
that space here so that is one way we could specify some information now let's say we wanted to add
additional information so right now we have rules for this particular host right here remember we
can specify a host but we can also specify as we discussed other things such as a particular network
so let's maybe say i wanted to say 192 168 50.0 slash 24 anyone on this network they are also going
to get access but people on that network are going to get read write access so they can actually make
changes not only that but also can specify in this case here we'll say no root squash i.e the root
users will be able to operate like they were the root user on the local server and again as we can
see here the format as i specify this is the share this is who is allowed to access the share
and under what conditions can they access that share again who can access and what conditions
they have access to this share now one thing to say here is that this is not the only way we can
specify particular access we can actually access or allow access by using things such as wildcards
so what i could even do here is i could just specify a star for example in fact let me just
not mash the keypad and just do a star and within here i can say rw and root squash for example so
all i am actually saying here is that anyone who tries to access this particular share i'm going
to allow it and i'm going to allow them to do so with read write access but invoke the root squash
option so understand we can specify hosts we can specify networks we can even use wildcards lots
of flexibility right here but for now what i will do here is i will allow access to anyone within the
192 1680.0 network which is my own network with a slash 24 and i'll grant access to my share so i
actually have to be able to create this so i'll save this and exit out and just like we saw with
respect to our samba configuration let's go back to the home directory in fact i'll go into the root
directory because that's what it's going to be i'll say sudo mkdir and i will create my share type in
my password right here to an ls-l we can now see my share let's actually grant the full permission
so we'll say all the sevens on my share so now what i want to do is i want to start up this server
i will say sudo system ctl and i will start the nfs kernel hyphen server and i will now say sudo
system ctl status of the nfs kernel server we can now see that this is active now what i want to show
you is a very very important command this is a command we absolutely want to be remembering for
the purposes of the examination and this is the export fs command what this is going to do is going
to allow us to see what the server actually is sharing so if i say man export fs we can see here
this is going to maintain a table of the exported nfs file systems so if i scroll on down we can see
these different options we have available to us notice here that if i use the dash a flag we're
going to either export or unexport all the directories we can use the dash o option to specify a list
of export options we can actually choose to ignore the contents of our exports file but one i want
to really look at is this dash r flag this is going to allow me to reread ultimately what is
within the contents of the xa exports file ie the changes we just made we can reread them in
and then they should be shared out so if i say sudo exports fs we don't actually see anything right
now but if i reread that file in and use dash r the file has now been read in we now see we actually
have a configuration for my share the share that we just created okay and we're actually granting
access to this particular network so if i rerun this command we can now see indeed
that this particular share is accessible to this particular network or devices within
that particular network similarly what i could also say is sudo show mounts and use dash e to
show my exports and then i can specify my own ip address so in fact let me just double check my
ip address right here happens to be 192 1680.44 so i'll say sudo show mount dash e on my address
0.44 and we can actually see here the export list for this particular server here is the share and
here is who is allowed to access that share this particular network now another command we want to
be aware of is the nfs stat command so if i go in and do man nfs stat we can see here this is going
to allow us to see nfs statistics and we can see here we have different options we can do dash s
to see only server side stats or dash c to see client side stats and a whole bunch of other
options say for example the dash m option or dash dash mounts ie this will print information about
every one of those mounted nfs file systems or as we can see dash r to see the rpc statistics this
is the remote procedure call which is facilitating this communication and there are more options to
see yet again so if i say sudo nfs stat dash s we can see server stats again nothing has actually
been happening or dash c we do not have any client statistics but understand that when we happen to
be using this particular feature i.e we are getting particular calls to the server these
values will increment and then when we happen to have actual clients making these requests we can
actually query these particular client statistics as of right now we do not have any clients in
action so for now that is our basic configuration for our nfs server like i say we do not have any
client configuration up and running quite just yet that is what we're going to be looking at in the
very next nuggets i hope this has been informative for you and i'd like to thank you for viewing
you