Linux Hands-On Lab - Testing DNS Resolution, Monitoring Network Access and Network Filesystems
Linux Learning Path for Cloud and DevOps Engineers
Table of contents
- 📝Introduction
- 📝Log in to the AWS Management Console
- 📝Review Current DNS Configuration
- 📝Configure Your System to Use Your Network's DNS
- 📝Install Client Utilities
- 📝Create the Traffic Log File
- 📝Listen for Traffic
- 📝Send Some Traffic
- 📝Examine the Log
- 📝Set Up the Samba Server
- 📝Samba Share User
- 📝Start It Up
- 📝Set Up the Samba Client
- 📝Make a Mount Point
- 📝Mount the share
- 📝Set Up the NFS Share
- 📝Set Up the NFS Client
- 📝Mount the NFS Share
📝Introduction
In this lab, we will utilize the nmcli
utility to configure our DNS resolution in Linux, use the netcat
(nc
) utility to generate network traffic between two servers and view that traffic's appearance in a tool called iptraf-ng
, and 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.
A Linux system administrator is expected to know how to configure a system's DNS settings, monitor the network and implement network fileshares.
These are the objectives of this lab:
Review current DNS configuration
Configure your system to use your network's DNS
Install Client Utilities
Create the Traffic Log File
Set Up a Samba Share
Set Up the NFS Share
📝Log in to the AWS Management Console
Using your credentials, make sure you're using the right Region. In my case, I am using AWS as my cloud provider and chose us-east-1
. However, you can choose any cloud provider and create your Linux Servers VMs (I am using a CentOS 7 distro) for this hands-on lab.
📌Note: You must create the AWS Access Key and AWS Secret Access Key and configure the AWS CLI in the terminal to use it.
You can use link1 and link2 for it.
📝Review Current DNS Configuration
See if the system can resolve hostnames to IP addresses:
host www.google.com
📌Note: that the command times out.
Check to see what DNS server entries we have in the
/etc/resolv.conf
file:cat /etc/resolv.conf
📌Note: that we do not have any DNS entries listed.
Review your network connections:
nmcli con show
📌Note: In my case, it is called
System ens5
.Check your default connection name. Review your DNS IP settings:
nmcli -f ipv4.dns con show "System ens5"
This system does not have any DNS servers configured for use.
📝Configure Your System to Use Your Network's DNS
Modify the system's default connection to use the network's DNS server:
sudo nmcli con mod "System ens5" ipv4.dns "10.0.0.2"
📌Note: In my case, my DNS server has an IP
10.0.0.2
.Verify the settings using the
nmcli
command and then check the/etc/resolv.conf
file:nmcli -f ipv4.dns con show "System ens5" cat /etc/resolv.conf
We need to reactivate the system's network connection for the change to take effect:
sudo nmcli con up "System ens5"
Verify our settings once more:
cat /etc/resolv.conf
Now, attempt to resolve a hostname to an IP address:
host www.google.com
Our system should be able to resolve an IP address for the domain name.
📝Install Client Utilities
We'll have to install the tools we need and create traffic on port 2525 from server2
to server1
. We want to get all network traffic sent to /home/cloud_user/traffic_log.txt
.
📌Note - We're going to be root
right off, so as soon as we get logged in we'll want to run a quick sudo su
in each one.
We've got to install the two packages that we will use to generate and monitor traffic. Let's use YUM to get it done on both servers:
[root@server1]# yum install iptraf-ng nc -y
[root@server2]# yum install iptraf-ng nc -y
📝Create the Traffic Log File
On the first server, let's run iptraf-ng
and go under Configure...
In the menu, don't forget this isn't a menu we control with a mouse -- it's all keyboard. Make sure Logging
is toggled to On
. Set the log file path to a specific path /home/<user>/traffic_log.txt
. Then go into the IP traffic monitor. In the next menu, select eth0
(in my case it isens5
). Once we press Enter the logging will start.
📝Listen for Traffic
Let's open a second terminal into server1
and run sudo su
right off. Once we're there, we're going to start netcat
listening on post 2525 with this:
[root@server1]# nc -l 2525
📝Send Some Traffic
Now, let's start talking. Back in the server2
window we've got open, send netcat traffic to server1
with this (where x.x.x.x
is the internal IP of server1
that we'll see on the hands-on lab overview page):
[root@server2]# nc x.x.x.x 2525
We'll just land at a blinking cursor below the prompt, but we can type a message there and press Enter. Once we do, it will show up back in the window we're listening in on server1
. A bunch of messages sent from server2
would look like this:
[root@server2]# nc x.x.x.x 2525
New test
Demo test
Testing traffic log
On server1
, they would look like this when they arrive:
[root@server1]# nc -l 2525
New test
Demo test
Testing traffic log
That should be enough traffic for what we're doing. On server2
, press Ctrl + C to kill the nc
command we've got running and flip back over to the terminal we were running iptraf-ng
in. Press x to stop the monitoring and get out, then choose Exit from the main menu.
📝Examine the Log
On server1
, if we run ls /home/<user>
we should see traffic_log.txt
listed in the output. Read that to see if it was capturing what we need:
[root@server1]# ls /home/cloud_user/
[root@server1]# less /home/cloud_user/traffic_log.txt
We should see some log entries showing traffic going from server2
to server1
on port 2525.
📝Set Up the Samba Server
Log in to the Samba server using the credentials provided:
ssh <user>@<SAMBA_SERVER_IP_ADDRESS>
Become
root
:[cloud_user@samba-server]$ sudo -i
Create the
/smb
path:[root@samba-server]# mkdir /smb
Make sure the client can write to the path:
[root@samba-server]# chmod 777 /smb
Install the Samba packages:
[root@samba-server]# yum install samba -y
Open
/etc/samba/smb.conf
:[root@samba-server]# vim /etc/samba/smb.conf
Add the following section at the bottom:
[share] browsable = yes path = /smb writable = yes
Save and exit the file by pressing Escape followed by
:wq
.Check that our changes saved correctly:
[root@samba-server]# testparm
📝Samba Share User
Create the user on the server:
[root@samba-server]# useradd shareuser
Give it a password:
[root@samba-server]# smbpasswd -a shareuser
Enter and confirm a password you'll easily remember (e.g.,
123456
), as we'll need to reenter it later.
📝Start It Up
Start the Samba daemon:
[root@samba-server]# systemctl start smb
📝Set Up the Samba Client
Open up a new terminal.
Log in to the NFS server and become
root
:ssh <user>@<NFS_SERVER_IP_ADDRESS> sudo -i
Install Samba client software:
[root@nfs-server]# yum install cifs-utils -y
📝Make a Mount Point
Create a place for mounting the share:
[root@nfs-server]# mkdir /mnt/smb
📝Mount the share
In the Samba server terminal, get its IP address:
[root@samba-server]# ip a s
Copy the private
inet
address oneth0
(in my case it isens5
) and paste it into a text file, as we'll need it next.In the NFS terminal, run the following command, replacing
<SERVER_IP>
with the IP you just copied and<SMBPASSWD_PASS>
with the password you created earlier:[root@nfs-server]# mount -t cifs //<SERVER_IP>/share /mnt/smb -o username=shareuser,password=<SMBPASSWD_PASS>
Make sure you see it listed when you run:
[root@nfs-server]# mount
Change directory:
[root@nfs-server]# cd /mnt/smb
Create a file:
[root@nfs-server smb]# touch file
List the contents:
[root@nfs-server smb]# ls
We should see the new file called
file
.
📝Set Up the NFS Share
Install NFS software on
NFS server
:[root@nfs-server smb]# yum install nfs-utils -y
Create the directory that will be shared out:
[root@nfs-server smb]# mkdir /nfs
Open
/etc/exports
:[root@nfs-server smb]# vim /etc/export
Add the following line:
/nfs *(rw)
Save and exit the file by pressing Escape followed by
:wq
.Edit permissions, to make sure it's going to be writable, on the shared directory:
[root@nfs-server smb]# chmod 777 /nfs
Implement what we've configured in
/etc/exports
:[root@nfs-server smb]# exportfs -a
Start the required services:
[root@nfs-server smb]# systemctl start {rpcbind,nfs-server,rpc-statd,nfs-idmapd}
Verify it:
[root@nfs-server smb]# showmount -e localhost
Run the following to get the NFS server's IP:
[root@nfs-server smb]# ip a s
Copy the
inet
address oneth0
(in my case it isens5
) and paste it into a text file, as we'll need it shortly.
📝Set Up the NFS Client
In the Samba server terminal, install software:
[root@samba-server]# yum install nfs-utils -y
Create a mount point:
[root@samba-server]# mkdir /mnt/nfs
Check to see what's being shared out on the
NFS server
, replacing<NFS_SERVER_IP>
with the IP you copied earlier:[root@samba-server]# showmount -e <NFS_SERVER_IP>
To be able to mount NFS shares, we need start a daemon:
[root@samba-server]# systemctl start rpcbind
📝Mount the NFS Share
Mount it, replacing
<NFS_SERVER_IP>
with the IP you copied earlier:[root@samba-server]# mount -t nfs <NFS_SERVER_IP>:/nfs /mnt/nfs
Make sure you see it listed after running:
[root@samba-server]# mount
Change directory:
[root@samba-server]# cd /mnt/nfs
Create a file:
[root@samba-server nfs]# touch file
List the contents:
[root@samba-server nfs]# ls
We should see the new file, called
file
.
There are two servers set up that share files back and forth. One is using Samba to share, and the other is using NFS.
📌Note - At the end of each hands-on Lab, always clean up all the resources previously created to avoid being charged if you used a Cloud Provider to provision them.
Congratulations — you have completed this hands-on lab covering the basics of utilizing the nmcli
utility to configure our DNS resolution, monitoring the network access and creating network Filesystems in Linux.
Thank you for reading. I hope you understood and learned something helpful from my blog.
Please follow me on CloudDevOpsToLearn and LinkedIn, franciscojblsouza