由 nobody_am 在 07-17-2003 06:47 发表:
用实验快速学习sendmail[原创]
前言:mail配置比较复杂,本文用实验的方法尽量以最通俗的方式,让读者学习sendmail
配置。
[实验目的]
1.安装sendmail。
2.在sendmail中使用假名。
3.用m4改变中转行为。
4.安装和配置POP服务器和客户端。
[实验要求]
1.两台RH8.0机器互连。
2.机器1已配置好DNS,具体要求:机器1的IP:192.168.0.254,host:server1.andsky.com
机器2的IP:192.168.0.2,host:station2.andsky.com
[实验步骤]
1.安装sendmail。
- 在机器1和机器2上检查下列包是否安装
sendmail
sendmail-cf
sendmail-doc
m4
procmail
缺什么,装什么。
- 编辑机器1和机器2的/etc/mail/sendmail.mc
去掉下列行的dnl
dnl DAEMON_OPTIONS('Port=smtp,Addr=127.0.0.1,Name=MTA')
作用是:使得可以接受其他域的mail。
- 机器1和机器2上,产生新的配置文件,最好先备份/etc/mail/sendmail.cf
cp /etc/mial/sendmail.cf /etc/mail/sendmail.cf.BAK
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
- 机器1和机器2上,重新启动sendmail.
service sendmail restart
chkconfig sendmail on
2.检测sendmail是否正常,及模拟sendmail操作。
- 检测sendmail是否可识别你的域名。
sendmial -d0 < /dev/null
Version 8.12.5
Compiled with: DNSMAP HESIOD HES_GETMAILHOST LDAPMAP LOG MAP_REGEX
MATCHGECOS MILTER MIME7TO8 MIME8TO7 NAMED_BIND NETINET NETINET6
NETUNIX NEWDB NIS PIPELINING SASL SCANF STARTTLS TCPWRAPPERS
USERDB USE_LDAP_INIT
============ SYSTEM IDENTITY (after readcf) ============
(short domain name) $w = station2
(canonical domain name) $j = station2.andsky.com
(subdomain name) $m = andsky.com
(node name) $k = station2
========================================================
Recipient names must be specified
如果显示localhost的话,检查/etc/hosts 去掉除127.0.0.1以外的行。如果还有问题,
查看是否在/etc/sysconfig/network中设置了HOSTNAME
- 模拟sendmail的操作。
echo “hello server1” | mail -v -s hello root@server1
root@server1... Connecting to localhost.localdomain. via relay...
220 station2.andsky.com ESMTP Sendmail 8.12.5/8.12.5; Thu, 17 Jul 2003 05:18:42 +0800
>>> EHLO station2.andsky.com
250-station2.andsky.com Hello localhost.localdomain [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-DELIVERBY
250 HELP
>>> MAIL From:
1<[email protected]> SIZE=47
2
3250 2.1.0 <[email protected]>... Sender ok
4
5>>> RCPT To:<[email protected]>
6
7>>> DATA
8
9250 2.1.5 <[email protected]>... Recipient ok
10
11354 Enter mail, end with "." on a line by itself
12
13>>> .
14
15250 2.0.0 h6GLIgpx001304 Message accepted for delivery
16
17root@server1... Sent (h6GLIgpx001304 Message accepted for delivery)
18
19Closing connection to localhost.localdomain.
20
21>>> QUIT
22
23221 2.0.0 station2.andsky.com closing connection
24
25sendmail的工作过程就如上所示。
26
27你可以看日志,检查mail的工作过程,更有意义的观察方法:
28
29在超级用户,另一终端:
30
31# tail -f /var/log/maillog
32
33会动态显示。
34
353.sendmail中使用假名:
36
371) 增加新用户。
38
39# useradd student2
40
41# passwd student2
42
432) 编辑/etc/aliases,增加下列三行。
44
45
46
47me: student2
48
49wizards:root,me
50
51methere: [email protected]
52
53
54
553) 更新假名数据库。
56
57# newaliases
58
594) 测试:
60
61# echo “hello there” | mail -s “hello” me
62
63# echo “hello there” | mail -s “hello” wizards
64
65# echo “hello there” | mail -s “hello” methere
66
675) student用户收到几封邮件?root受到几封邮件?
68
69
70
714.控制中转行为。
72
731) 在机器2上编辑/etc/mail/sendmail.mc 文件,增加下列一行:
74
75
76
77FEATURE(promiscuous_relay)dnl
78
79
80
81注意:如果你这台机连到internet上的话,不推荐你这么作,因为,internet上的用
82
83户会用你的这台机作为跳板,伪装发邮件,使得邮件接收者无迹可寻。
84
852) 在机器2上用m4产生新的配置文件,这里最好再备份原/etc/mail/sendmail.cf
86
87# cp /etc/mail/sendmail.cf /etc/mail/sendmail.cf.BAK2
88
89# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
90
913) 现在你在机器1上模拟,一个用心不良的用户,用你的机器2作为跳板,发送邮件。
92
93这里假设你有一个邮件叫 [email protected],具体可以变更。
94
95# telnet station2.andsky.com 25
96
97Trying 192.168.0.2...
98
99Connected to station2.andsky.com.
100
101Escape character is '^]'.
102
103220 station2.andsky.com ESMTP Sendmail 8.12.5/8.12.5; Thu, 17 Jul 2003 05:45:05 +0800
104
105helo mail.cracker.org
106
107250 station2.andsky.com Hello IDENT:[email protected]. [192.168.0.2], pleased to meet you
108
109mail from: [email protected]
110
111250 2.1.0 [email protected]... Sender ok
112
113rcpt to: [email protected]
114
115250 2.1.5 [email protected]... Recipient ok
116
117data
118
119354 Enter mail, end with "." on a line by itself
120
121Subject: Relayed
122
123This is faked and relayed!
124
125ok?
126
127.
128
129250 2.0.0 h6GLj5MV001565 Message accepted for delivery
130
131quit
132
133221 2.0.0 station2.andsky.com closing connection
134
135Connection closed by foreign host.
136
1374) 观察机器2的/var/log/maillog
138
1395) 收你的[email protected]的邮件,看看里面的格式。
140
1416) 机器2,关掉中转。
142
143# cp /etc/mail/sendmail.cf /etc/mail/sendmail.cf.BAK2
144
145# cp /etc/mail/sendmail.cf.BAK1 /etc/mail/sendmail.cf
146
147# service sendmail restart
148
149重作上面3)步,结果会怎么样呢?
150
1517) 机器2 有选择的中转:
152
153编辑/etc/mail/access,增加
154
155
156
157andsky.com RELAY
158
159
160
161重作上面3) 步,结果如何?
162
163
164
1655.安装和配置POP服务器和客户端。
166
1671) 机器2上,检查下列包是否装过
168
169xinted
170
171krb5-libs*
172
173imap
174
175缺什么,装什么
176
1772) 机器2上,启动服务:
178
179service xinetd start
180
181chkconfig ipop3 on
182
1833) 机器2上,确认服务。
184
185# echo "mail to be popped" | mail -s "hello student2" student2
186
187Trying 127.0.0.1...
188
189Connected to localhost.
190
191Escape character is '^]'.
192
193+OK POP3 localhost.localdomain v2001.78rh server ready
194
195user student2
196
197+OK User name accepted, password please
198
199pass student2
200
201+OK Mailbox open, 1 messages
202
203stat
204
205+OK 1 641
206
207TOP 1 700
208
209+OK Top of message follows
210
211Return-Path: <[email protected]>
212
213Received: from station2.andsky.com (localhost.localdom</[email protected]></[email protected]></[email protected]></[email protected]></[email protected]>