1 Goals

1.1 Notes:

2 Exercises

2.1 Update your software package repository

Connect to your virtual machine (hostX.campusY.ws.nsrc.org) as the user sysadm and then from the command line:

$ sudo apt-get update

This might take a few moments if everyone in class is doing this at the same moment.

2.2 Install the "nano" editor package:

$ sudo apt-get install nano

The nano editor package is simpler to use than vi. Try using the editor to create a new file in your sysadm home directory:

$ cd
$ nano newfile.txt

Type in some text for practice. You can type "ctrl-g" to see a list of nano editor commands, that is "press the ctrl key and the g key. You need to press 'ctrl-x' to exit the help screen.

You can save and exit from the file by typing "ctrl-x, then y" and <ENTER> to accept the file name..

2.3 Setting time to UTC, Updating time and install Network Time Protocol service

In order to manage and monitor your network it is critical that all devices and servers maintain the same, consistent time. To achieve this you can, for example, select a single time zone, use the ntpdate command to set your server's clock exactly and install the NTP (Network Time Protocol) service to maintain your server's clock with precise time.

First, let's set your server's clock to use UTC time (Coordinated Universal Time). At the command line type:

$ sudo dpkg-reconfigure tzdata

Now your server is using UTC time. Next be sure the time is precise by using ntpdate. First install ntpdate:

$ sudo apt-get install ntpdate

Now we'll update our local time against a remote time server:

$ sudo ntpdate -s ntp.ubuntu.com

You can always type:

$ date

to see your server's current timezone (UTC, which is technically a standard), date and time.

Finally, let's install the NTP service to ensure that our server's clock maintains precise time.

$ sudo apt-get install ntp ntpstat

At this point the default configuration should be acceptable for our case. You may wish to read up on ntp upon returning home and edit the file /etc/ntp.conf to select different time servers, or update settings to your local ntp service configuration.

In addition, ntp has been part of several security warnings the past few years. You should sign up for the Ubuntu Security mailing list at:

https://lists.ubuntu.com/mailman/listinfo/ubuntu-security-announce

You should do this whether you run ntp or not. And, as ntp is so critical to proper network instrumentation, this is one service that should be run on any server that will be running network monitoring or management software or that will be monitored and on all your network devices.

If you would like to see the status of your local ntp service you can type:

$ sudo ntpq -p

and you should see something like:

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 0.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 1.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 2.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 3.ubuntu.pool.n .POOL.          16 p    -   64    0    0.000    0.000   0.000
 ntp.ubuntu.com  .POOL.          16 p    -   64    0    0.000    0.000   0.000
-195.50.171.101  145.253.3.52     2 u   30   64    1  255.854   16.381   7.499
+ntp2.wiktel.com 212.215.1.157    2 u   29   64    1  136.275   -4.204   4.065
-85.199.214.99 ( .GPS.            1 u   30   64    1  300.455  -27.752  11.031
*1.time.dbsinet. 146.186.222.14   2 u   31   64    1  139.864    3.986   4.574
+grampus.irb.hr  132.163.4.102    2 u   29   64    1  258.139    4.099   2.264
-202.65.114.202  203.160.128.66   2 u   31   64    1  377.008  -30.861   3.544

For a reasonable discussion of what this output means see:

http://tech.kulish.com/2007/10/30/ntp-ntpq-output-explained/

To see the status of your time synchronization process type:

$ ntpstat

If your clock is properly synchronized you sould see something like:

synchronised to NTP server (91.234.160.19) at stratum 3
   time correct to within 193 ms
   polling server every 64 s

Your machine will now update it's time against a known good source on a regular basis.

2.4 Install the postfix mailerver software and some mail utilities

At the command line type:

$ sudo apt-get install postfix mutt mailutils

This might take a moment to complete.

You will be prompted for the type of installation you wish to perform. First press <ENTER  and then you will see a screen like this:

      Postfix Configuration
General type of mail configuration:
Internet Site
Internet with smarthost
Satellite system
Local only

<Ok>             <Cancel>

Select Internet Site, then press TAB to highlight the <Ok> item and then press <ENTER>.

Next you will be asked for your System mail name. You should see something like:

hostX.campusY.ws.nsrc.org

...assuming this is what is shown, then press TAB to highlight the <Ok> item and then press <ENTER>.

If you did not see something like the above, let your classroom instructor or assistant know.

Several tools will use the postfix mailserver during the week. In addition, we will use a number of the mail utilities (such as mail) and you will use the mutt email reader later in the week.

For fun you can practice restarting a service by restarting the postfix mailserver. Note that the service was started as soon as installation was completed:

$ sudo systemctl restart postfix

You might do this if you changed a postfix configuration file.

To see the status of the running postfix service do:

$ sudo systemctl status postfix

You should see something like this:

* postfix.service - LSB: Postfix Mail Transport Agent
   Loaded: loaded (/etc/init.d/postfix; bad; vendor preset: enabled)
  Drop-In: /run/systemd/generator/postfix.service.d
           |_50-postfix-$mail-transport-agent.conf
   Active: active (running) since Sun 2018-02-18 20:06:57 UTC; 9s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 17634 ExecStop=/etc/init.d/postfix stop (code=exited, status=0/SUCCESS)
  Process: 17661 ExecStart=/etc/init.d/postfix start (code=exited, status=0/SUCCESS)
    Tasks: 3
   Memory: 2.0M
      CPU: 252ms
   CGroup: /system.slice/postfix.service
           |_17777 /usr/lib/postfix/sbin/master
           |_17778 pickup -l -t unix -u -c
           |_17779 qmgr -l -t unix -u

With the last few lines that are log file notices for the postfix mail service.

Press 'q' to exit from the status screen.

2.5 Deliver an Email to Yourself

To verify that your mail server is working (at least locally) you can do the following:

$ echo "My first email" | mail -s "First email" sysadm@hostX.campusY.ws.nsrc.org

(Replace 'X' and 'Y' with your specific virtual machine information).

And, then to view your email type:

$ mutt

You may see the following:

/home/sysadm/Mail does not exist. Create it? ([yes]/no):

Type "yes" and press <ENTER> to continue.

Press <ENTER> to view the email. To exit type "q" two times to quit.

If for some reason you do not see the mail you can try to do the following and then send the mail message again:

$ sudo touch /var/mail/sysadm
$ sudo chown sysadm:mail /var/mail/sysadm

It's important that mail is working on your system as this will be used throughout the week by the network monitoring and management software that you install. If you did not get mail to work please let your instructor know so that the issue can be resolved right away.

2.6 Viewing log files in real time

Log files are critical to solve problems. They reside (largely) in the /var/log/ directory.

Some popular log files include:

and many more.

To view the last entry in a log file, such as the system log file, type:

$ tail /var/log/syslog

Some log files may require that you use "sudo tail logfilename" to view their contents.

What's more effective is to watch a log file as you perform some action on your system. To do this open another ssh session to your server now, log in as user sysadm and in that other window type:

$ tail -f /var/log/syslog

Now in your other window try restarting the ntp service you recently installed:

$ sudo systemctl restart ntp

You should see quite a few log messages appear in your other ssh window. These are real-time messages coming from the ntp service. We'll talk about logging more later in the week, but viewing your log files to debug issues is often the only way to solve a problem.

In the window where you typed "sudo tail -f /var/log/syslog" you can press ctrl-c to exit from the tail command.

2.7 Practice using the man command

to get help on command you can use the man command ("man" is short for manual). For instance, to learn more about the ssh command you could do:

$ man ssh

Now you can move around the help screen quickly by using some editing tricks. Note that these tricks work if you are using the less command as well.

Try doing the following: