Skip to main content

Network File Systems

Hands-On Lab

 

Photo of Rob Marti

Rob Marti

Linux Training Architect I in Content

Length

00:30:00

Difficulty

Intermediate

Implementing network fileshares Linux servers and clients is a key skill for any experienced system administrator. In this activity, we will be working to set up both a Linux Samba fileshare and an NFS fileshare that can then be used by a remote client to store files on. Once you complete this activity, you will understand how to configure network filesystems.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Network File Systems

Introduction

Implementing network fileshares Linux servers and clients is a key skill for any experienced system administrator. In this activity, we will be working to set up both a Linux Samba fileshare and an NFS fileshare that can then be used by a remote client to store files on. Once you complete this activity, you will understand how to configure network filesystems.

The Scenario

We need to set two servers up so that they can share files over both NFS and SMB. The shares need to be writable on both ends, and we can't use no_root_squash on the NFS server.

Get logged in

Use the credentials and server IP in the hands-on lab overview page to log into our lab server. Since we'll need to be root for the all of the commands, we'll run a quick sudo -i as soon as we're in. Once that's done, we can get moving.

Set up the Samba Server

First we need to install the Samba packages:

[root@smb_server]# yum install samba -y

Then we need to edit /etc/samba/smb.conf (with whichever text editor you choose) and add the following section at the bottom:

[share]
browsable = yes
path = /smb
writable = yes

To see whether or not our changes are good, we can run testparm and look at the output for errors and OK messages.

Samba Share User

The client is going to be connecting with a username, so we've got to create that user on the server, and give it a password:

[root@smb_server]# useradd shareuser
[root@smb_server]# smbpasswd -a shareuser

We'll need to enter and confirm a password at the prompts.

The Shared Directory

We need to create the path that we specified in the configuration file, and make sure (with chmod) that the client can write to it:

[root@smb_server]# mkdir /smb
[root@smb_server]# chmod 777 /smb

Start It Up

Now we can fire up the Samba daemon with

[root@smb_server]# systemctl start smb

Set Up the Samba Client

Now, let's open up a new terminal and get into what's going to be the client (and what will also be our NFS server later). We need to install software:

[root@nfs_server]# yum install cifs-utils -y

Make a Mount Point

This will create a place for mounting the share:

[root@nfs_server]# mkdir /mnt/smb

The Mount

And now we can do the actual mounting. Grab the server's ip address (run ip a s on it in the other terminal window -- we're looking for the inet address on eth0) and use it in a mount command on the client, along with the password we set with the smbpasswd command.

[root@nfs_server]# mount -t cifs //&ltSERVER_IP>/share /mnt/smb -o username=shareuser,password=&ltSMBPASSWD_PASS>

Now if we run a quick mount, we should see it listed. We should also be able to create a file in it:

[root@nfs_server]# cd /mnt/smb
[root@nfs_server]# touch file
[root@nfs_server]# ls

We should see a new file, called file, sitting in the directory.

Great. We're halfway there.

Mount Point at /smb on the samba-server and share it out using the samba service. Mount it on the nfs-server at /mnt/smb and make sure the mount point is writable.

Set up the NFS Share

We've got some software to install on the NFS server too:

[root@nfs_server]# yum install nfs-utils -y

We need to create the directory that will be shared out:

[root@nfs_server]# mkdir /nfs

Now, we edit /etc/exports (with your preferred text editor) to configure the sharing. Add a line that looks like: /nfs *(rw).

Edit permissions, to make sure it's going to be writable, on the shared directory with:

[root@nfs_server]# chmod 777 /nfs

To implement what we've configured in /etc/exports, run this:

[root@nfs_server]# exportfs -a

Now we need to start the required services, and actually start sharing, with this:

[root@nfs_server]# systemctl start {rpcbind,nfs-server,rpc-statd,nfs-idmapd}

We can test with a showmount command:

[root@nfs_server]# showmount -e localhost

While we're here, let's grab the NFS server's IP. We're going to need it in a minute. Run ip a s just like we did earlier on the Samba server.

Set up the NFS Client

We should still have our first terminal window open, and are sitting in the Samba server. This is our NFS client. To get things rolling, we need to install some software:

[root@smb_server]# yum install nfs-utils -y

Then we'll need to create a mount point:

[root@smb_server]# mkdir /mnt/nfs

To see what's being shared out on the NFS server, run this:

[root@smb_server]# showmount -e <NFS_SERVER_IP>

To be able to mount NFS shares, we need a daemon running. Start it with this:

[root@smb_server]# systemctl start rpcbind

Mount the NFS Share

Finally, we can mount it up with thie command:

[root@smb_server]# mount -t nfs <NFS_SERVER_IP>:/nfs /mnt/nfs

Just like with the Samba setup, we can run a quick mount and we should see it listed. We should also be able to create a file in it:

[root@smb_server]# cd /mnt/nfs
[root@smb_server]# touch file
[root@smb_server]# ls

We should see a new file, called file, sitting in the directory.

Conclusion

We did it. There are two servers set up that share files back and forth. One is using Samba to share, the other is doing it with NFS. Congratulations!