Sendmail Lab Part 2 - Seneca

advertisement
School of Computer Studies – Seneca College
Name: _______________________
Student ID: _______________________ Check: ____________
Sendmail Lab – Part 2
Objectives:
(1) Create a Sendmail configuration from scratch to study how sendmail perform address
rewrite.
(2) Study and explorer the SENDMAIL macro configuration file (/etc/mail/sendmail.mc)
supplied by Red Hat Linux.
(3) Use SENDMAIL to send electronic messages to remote users (ie users on other
SMTP server).
(4) Explore and manage SENDMAIL's mail statistics.
Prerequisite:
Complete Sendmail Lab Part 1.
In order to use the m4 macro processor to generate Sendmail configuration file, you
must have the sendmail-cf package installed on your Linux host.
Reference: /usr/share/sendmail-cf/README
Important:
Some of the commands in this lab must be executed as “root”.
Please login as a regular user and “su” to root when necessary.
(1) Version Information:
Program/Package Name
Red Hat Linux
sendmail rpm
sendmail-cf rpm
Sendmail-doc rpm
Version
(2) Login as a regular user and create an empty file called “mysmcfg.cf” in the user's
home directory.
(3) Execute the sendmail program and direct it to use the newly created file “mysmcfg.cf”
as the configuration file using the following command:
/usr/sbin/sendmail -Cmysmcfg.cf -bt
The -C command line flag tells sendmail to use a specify configuration file in place of
the system configuration file (/etc/mail/sendmail.cf – RedHat Linux 9.0). The -bt flag
tells sendmail to run in rule-testing mode. Since there is nothing in the file, your
sendmail will probably complain about it. Record the exact message (word by word,
character by character) generate by sendmail:
Raymond.Chan@Seneca College
Fall 2003
Page 1 of 6
OPS535 Lab - Sendmail
School of Computer Studies – Seneca College
Name: _______________________
Student ID: _______________________ Check: ____________
/usr/sbin/sendmail -Cmysmcfg.cf -bt
(4) Add the following information to the file “mysmcfg.cf”: (all in one line)
Mlocal,
P=/usr/bin/procmail, F=lsDFMAw5:/|@qSPfhn9,
S=EnvFromL/HdrFromL, R=EnvToL/HdrToL, T=DNS/RFC822/X-Unix,
A=procmail -t -Y -a $h -d $u
(5) Execute the following command to add queue directory information to the new
configuration file:
grep QueueDirectory /etc/mail/sendmail.cf >> mysmcfg.cf
(6) Repeat step 3 again and record the exact output:
(7) Most likely, sendmail still complains. Press control-D to get out and add the word
“V10” to the top of the new configuration. If you repeat step 3 again, you should see
the following message:
$/usr/sbin/sendmail -Cmysmcfg.cf -bt
ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
Enter <ruleset> <address>
(8) One of the major strengths of the sendmail configuration file is that it allows text
strings to be refereneced symbolically and to be defined in one central place using
macros. The sendmail program internally defines many macros for you. To display all
the macros defined by sendmail internally, execute the following command:
/usr/sbin/sendmail -d35.9 -Cmysmcfg.cf -bt < /dev/null
Record the following macros defined by sendmail's internal process:
Macro
Value
Meaning
n
v
w
j
m
k
b
Raymond.Chan@Seneca College
Fall 2003
Page 2 of 6
OPS535 Lab - Sendmail
School of Computer Studies – Seneca College
Name: _______________________
Student ID: _______________________ Check: ____________
(9) Try the following command and study the output:
/usr/sbin/sendmail -Cmysmcfg.cf -d0.1 -bt < /dev/null
What information do you get from the above command?
(10) Append the following to your “mysmcfg.cf” file:
Dwmyhost.mydomain.com
Repeat the command in step 8 and compare their outputs. Did you notice any
difference? Record any difference introduced by the addition of the above line to the
configuration file.
(11) Sendmail address rewrite rule sets. Your “mysmcfg.cf” file contains no rule-set
definition yet. To observe the effect of non-existent rule, try the following
command: (type in the one in bold and italic)
$/usr/sbin/sendmail -Cmysmcfg.cf -bt
ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
Enter <ruleset> <address>
0 myname@senecac.on.ca
(12) Add the following two lines as ruleset 0 to your configuration file:
S0
Rleft.hand.side
new.stuff.here
(note: add a tab between the word “side” and “new”)
(13) Run the command in bold and italic and record their output:
Raymond.Chan@Seneca College
Fall 2003
Page 3 of 6
OPS535 Lab - Sendmail
School of Computer Studies – Seneca College
Name: _______________________
Student ID: _______________________ Check: ____________
$/usr/sbin/sendmail -Cmysmcfg.cf -bt
ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
Enter <ruleset> <address>
=S0
0 user@domain.com
0 left.hand.side
(13) Add the following two lines as ruleset 1 to your configuration file:
S1
R$* left<hand.side>$new<$1.$2>here
(note: add a tab between the token
“$-” and “new”)
(15) Run the command in bold and italic and record their output:
$/usr/sbin/sendmail -Cmysmcfg.cf -bt
ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
Enter <ruleset> <address>
=S1
1 user@domain.com
1 left<hand.side>
1 left<hand.side>stuff
1 far left<hand.side>stuff
(16) Create ruleset 9 to rewrite address in the form
lastname.firstname@host.senecac.on.ca to lastname.firstname@senecac.on.ca where
lastname, firstname, and host and have any values. For example
Input address
Rewritten to
Ray.Chan@cs.senecac.on.ca
Chan.Ray@senecac.on.ca
Green.Brown@matrix.senecac.on.ca Brown.Green@senecac.on.ca
Raymond.Chan@Seneca College
Fall 2003
Page 4 of 6
OPS535 Lab - Sendmail
School of Computer Studies – Seneca College
Name: _______________________
Student ID: _______________________ Check: ____________
Lines for your ruleset 9:
S9
R
Test your ruleset 9 and make sure that it produce the correct output.
(17) Create ruleset 10 to rewrite address according to the following:
Input address
Rewritten to
Ray.Chan@cs.senecac.on.ca
Chan@senecac.on.ca
Ray@matrix.senecac.on.ca
Ray@senecac.on.ca
Brown@matrix.cs.senecac.on.ca
Brown@senecac.on.ca
Lines for your ruleset 10:
S10
R
(18) Now we are going to make change to the actual sendmail configuration file
(/etc/mail/sendmail.cf). Before you do that, backup the original file.
Name of the backup file: /etc/mail/sendmail.cf.org
Execute the following command to regenerate the sendmail configuration file from
the macro sendmail configuration file /etc/mail/sendmail.mc:
su (type in root's password)
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
diff /etc/mail/sendmail.cf.org /etc/mail/sendmail.cf
exit
(19) You should see only small difference between the original sendmail configuration
file and the newly generated one. The orginal configuration only enable sendmail to
listen on the loopback interface, IP 127.0.0.1. To enable sendmail to listen on the
NIC interface and to make sendmail to accept mail from other SMTP server, you
have to comment out a line in the sendmail macro configuration file
/etc/mail/sendmail.mc. Copy the file /etc/mail/sendmail.mc to /etc/mail/sendmail1.mc. Modify sendmail-1.mc and comment out the DAEMON_OPTIONS line.
How did you comment out that line?
Raymond.Chan@Seneca College
Fall 2003
Page 5 of 6
OPS535 Lab - Sendmail
School of Computer Studies – Seneca College
Name: _______________________
Student ID: _______________________ Check: ____________
(20) To generate a new sendmail configuration file to enable sendmail to listen on NIC
interface, what command should you use:
Restart sendmail to use the new configuration file.
(21) What command would you use to confirm that sendmail is indeed listen on the NIC
interface? What information should be expected on the output of the said command?
Command:
Expected output:
(23) Use telnet to port 25 of the IP on your NIC to send a email manually to a user on
your host. Debug and fix it if there is any problems.
(24) Once your group partners are ready, use the mail command to send at least one email
to any regular users on their host using the following fomat (note: all the involved
host name must be resolvable to IP using DNS):
mail -v -s”Subject line” username@hostname.podx.com < message_file
(25) Check your mail server mail statistics with the “mailstats” command.
(26) Check your mail server mail transaction with the “hoststat” command.
(27) Show your “mailstats” and “hoststat” to your instructor to check off your lab.
Raymond.Chan@Seneca College
Fall 2003
Page 6 of 6
OPS535 Lab - Sendmail
Download