Open main menu

CDOT Wiki β

Changes

OPS535-online-L5

2,708 bytes added, 15:51, 21 July 2023
m
Protected "OPS535-online-L5": OER transfer ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite))
[[Category:OPS535]][[Category:rchan]]
'''Draft - This lab is still under construction.'''
=Overview=
Postfix is a complete MTA (Mail Transport Agent) package which replaced Sendmail. Postfix uses several different programs to implement the MTA functionality. Postfix is considered to be more secure than Sendmail as it requires a separate user ID for running each module. Postfix uses plain text parameters and value names in its configuration files. The Postfix program plays a variety of roles:
Understanding how Postfix handles the tasks listed above is essential in keeping the email service running properly for your users.
 
= Objectives =
In this lab, we will focus on the followings:
* Configure Postfix services to bind to specific network interface(s) for incoming SMTP connections
* Study and review the SMTP protocol
* Understand and configure mail aliases and mailing list
* Configure and manage Postfix's outgoing mail queue
* Setup appends mail to files option in Postfix
= Pre-requisites =
** all your four VMs have network connectivity to each other via the ens224 network interfaces.
** your VMs have the proper FQDN which can be resolved by your authoritative DNS server(s).
* Install the nmap-ncat, tree, and mailx packages on your host (optinally, install it on your other VMs as well).
* Install postfix if it is not installed.
= Investigation 1: SMTP Postfix package =
== Perform the following steps on your VM2 (pri-dns)==
:* login to your VM2 as the student user. :* Find out the version of the postfix rpm installed on the available to your CentOS 8.x system with one of the following commands and keep a record of it.
<pre>
rpm -q postfix
yum info postifx
</pre>
:* SMTP servers use one of the well-known ports, you can find out the port number used by the smtp protocol with the following command:
<pre>
grep -w smtp /etc/services
</pre>
:* Note that the file /etc/services is used on a Linux system to resolve TCP/UDP service names to TCP/UDP port numbers.* Make sure that the postfix.service is running on your VM2, if not, start the postfix.service and confirm that it is running properly.:* Beside the systemctl command, there are two more places (or commands) you can use to confirm whether there is a an SMTP server running on your system: the "ss -at" and "ps -ef" command::* Try the following command pipe line and look for the SMTP port number under the "Local Address" column and record the line(s) for future reference.
<pre>
ss -at | grep -e "Local Address" -e "smtp"
ss -atn | grep -e "Local Addres" -e [smtp port number]
</pre>
:* Note that if the Local Address shown is 127.0.0.1 only, your SMTP server will not be reachable by other machines.:* Run the following command pipe line and study the output carefully:
<pre>
[instructor@pri-dns ~]$ ps -ef | grep -v grep | grep postfix
postfix 122216 122055 0 20:33 ? 00:00:00 pickup -l -t unix -u
</pre>
:* Look up the man page for "qmgr", "tlsmgr", and "pickup", and find out the purpose of those processes.
== Investigation 2: The SMTP Protocol=== SMTP protocol: clear text commands/responses ==:* As a regular user on VM2, execute the commands given in the "Command" column and record the output in the corresponding "Response" column for future reference. Do not proceed if the first command does not establish a connection to the SMTP port on the local host.{| class="wikitable" cellspacing="0" width="90%" cellpadding="5" border="1" style="text-align: left; vertical-align: top; background: #3333ff; border-spacing: 2px; border: 1px solid darkgray; background: #a0a0a0"
|+ SMTP command / Response
|- style="vertical-align: top; background: #a0a0a0"
! - - - Command - - -
! - - - - - - - - - - - - Response - - - - - - - - - - - -
| nc localhost 25
| 220 pri-dns.gbecker.ops ESMTP Postfix
|- style="vertical-align: top; background: #ffffccccffcc"
| HELO seneca.ops
| <br> <br> <br>
| ELHO seneca.ops
| <br> <br> <br>
|- style="vertical-align: top; background: #ffffccccffcc"
| NOOP
| <br> <br>
|RSET
|<br>
|- style="vertical-align: top; background: #ffffccccffcc"
|VERB
|<br>
|EXPN ops535m
|<br>
|- style="vertical-align: top; background: #ffffccccffcc"
|VRFY root
|<br>
|VRFY nobody
|<br>
|- style="vertical-align: top; background: #ffffccccffcc"
|HELP
|<br>
|}
== postfix main configuration filePostfix service binding: /etc/postfix/main.cf ==:* Login to your VM1, and run the following nc command to try to connect to the SMTP server on your VM2:
<pre>
nc 192.168.x.2 25 (replace x with your network number)
</pre>
:* You may get one of the following responses:
<pre>
[instructor@router ~]$ nc 192.168.2.2 25
Ncat: Connection refused.
</pre>
:* The 1st problem is due to the firewalld configuration on your VM2. You need to enable the smtp service.:* The 2nd problem is due to the configuration of postfix, its default configuration is just bind to the loop back interface.:* Switch back to VM2, backup the file /etc/postfix/main.cf to /etc/postfix/main.cf.org as root or by sudo.:* Study the contents of the file /etc/postfix/main.cf. (Look for the parameters you learned about in OPS335):* Edit the file "/etc/postfix/main.cf" with the following changes:
<pre>
comment out the line "inet_interfaces = localhost"
uncomment the line "inet_interfaces = all"
</pre>
:* Save the changes, and run the "diff" command on /etc/postfix/main.cf and /etc/postfix/main.cf.org and make sure you get something similar to the following:
<pre>
[instructor@pri-dns ~]$ diff /etc/postfix/main.cf.org /etc/postfix/main.cf
> #inet_interfaces = localhost
</pre>
:* 132c132 means line 132 in /etc/postfix/main.cf.org has been changed to line 132 in /etc/postfix/main.cf and 135c135 means similarly.:* Restart "postfix" service on VM2.:* Check to confirm that postfix is listening on smtp port on all network interface (i.e. with local address 0.0.0.0):
<pre>
[instructor@pri-dns ~]$ ss -at
</pre>
:* Switch to VM1, and login as a regular user. Execute the commands given in the "Command" column and record the output in the corresponding "Response" column for future reference. Do not proceed if the first command does not establish a connection to the SMTP port on the VM2, replace the place holder [VM2-IP-ADDR] with your VM2's actual IP address.
{| class="wikitable" cellspacing="0" width="90%" cellpadding="5" border="1" style="text-align: left; vertical-align: top; border-spacing: 2px; border: 1px solid darkgray"
|+ SMTP command / Response
| HELO seneca.ops
| <br> <br> <br>
|- style="vertical-align: top; background: #FFCCCCe0e0e0"
| ELHO seneca.ops
| <br> <br> <br>
| NOOP
| <br> <br>
|- style="vertical-align: top; background: #ffcccce0e0e0"
|RSET
|<br>
|EXPN ops535m
|<br>
|- style="vertical-align: top; background: #ccffcce0e0e0"
|VRFY ops535m
|<br>
|- style="vertical-align: top; background: #ffccccccffcc"
|QUIT
|<br>
|}
  = Investigation 23: mail aliases and mailing list (on postfix) =
== Files from the postfix rpm package ==
* Postfix keeps its configuration files in the /etc/postfix directory. Postfix's two main configuration files are /etc/postfix/main.cf and /etc/postfix/master.cf. On a CentOS 8.x system, you can use the "rpm -ql" command to get a list of all the files in the posftfix rpm package. You may notice that the postfix rpm package contains a few files named or partly named as "sendmail". You can get a list of those files with the following command:
! - - - Command - - -
! - - - - - - - - - - - - Response - - - - - - - - - - - -
|- style="vertical-align: top; background: noneccffcc"
| nc [IP-Addr] 25
| 220 pri-dns.gbecker.ops ESMTP Postfix
|- style="vertical-align: top; background: #CCffCCe0e0e0"
| HELO seneca.ops
| <br> <br> <br>
|- style="vertical-align: top; background: #FFCCCCccffcc"
|EXPN ops535m
|<br>
|- style="vertical-align: top; background: #ccffcce0e0e0"
|VRFY ops535m
|<br>
|VRFY smtp-lab
|<br>
|- style="vertical-align: top; background: #ffcccce0e0e0"
|QUIT
|<br>
:* Study the /etc/aliases file on VM2.
= Investigation 34: Postfix's outgoing mail queues (on postfix) =
== Perform the following steps as root on your VM2 ==
* Run the following command and record the ouitput:
* Issue the command /usr/sbin/sendmail -bp and compare the output to the command mailq.
* Remove both "./defer/B/B75BF20A6D85" "./deferred/B/B75BF20A6D85" and run the mailq command again.
 
= Investigation 5: Appends mail to files =
The Postfix aliases file supports an option to append mail message addressed to a real user or virtual user to an external file. In this investigation, we are going to use a real email user named "rchan", and a virtual email user named "ops535" as the email recipients. The following are the steps to configure Postfix to append email addressed to these two email users to the file 'tmp/ops535.mail' and 'tmp/rchan.mail'.
* First, confirm that your system has the real user 'rchan' (replace with the real user name on your system) only:
<pre>
[instructor@pri-dns lab5]$ id rchan
uid=1002(rchan) gid=1002(rchan) groups=1002(rchan)
[instructor@pri-dns lab5]$ id ops535
id: ‘ops535’: no such user
</pre>
* Add the following two lines to the /etc/aliases files:
<pre>
rchan: "/tmp/ops535.mail"
ops535: "/tmp/rchan.mail"
</pre>
* Run the newaliases command to update the aliases database file.
* The above steps create a virtual email user (or mail alias) "ops535", and all the email messages addressed to "ops535" will be appended to the file "/tmp/ops535.mail".
* As a regular user on your VM2, create a file named "test.mesg" with the following contents:
<pre>
Postfix is a Mail Transport Agent (MTA),
supporting LDAP, SMTP AUTH (SASL), TLS
</pre>
* Run the following two commands to send the same message to both the real email user "rchan" and virtual email user "ops535":
<pre>
/usr/sbin/sendmail -v ops535 < test.mesg
/usr/sbin/sendmail -v rchan < test.mesg
</pre>
* Go to the /tmp directory, and search for the files named "ops535.mail", and "rchan.mail". [Hint: you have to look deeper into the /tmp directory]
* Get the locations (i.e. path names), owners, permission settings, and contents of the above two files for lab submission.
= Completing the Lab =
Please download the [https://raw.githubusercontent.com/rayfreeping/ops535/master/labs/labcheck5.bash check lab script named labcheck5.bash] to your VM2, run the script under the 'student' user with sudo privilege and capture the output to a file and named it as lab5_vm3.txt:
<pre>
[student@pri-dns labs]$ sudo bash labcheck5.bash > lab5_vm2.txt
</pre>
 
Upload the file "lab5_vm2.txt" to Blackboard by the posted lab5 due date.
= Review Questions =