|
前言:mail配置比较复杂,本文用实验的方法尽量以最通俗的方式,让读者学习sendmail
配置。
[实验目的]
1.安装sendmail。
2.在sendmail中使用假名。
3.用m4改变中转行为。
4.安装和配置POP服务器和客户端。
[实验要求]
1.两台RH8.0机器互连。
2.机器1已配置好DNS,具体要求:机器1的IP:192.168.0.254,host:server1.example.com
机器2的IP:192.168.0.2,host:station2.example.com
[实验步骤]
1.安装sendmail。
1) 在机器1和机器2上检查下列包是否安装
sendmail
sendmail-cf
sendmail-doc
m4
procmail
缺什么,装什么。
2) 编辑机器1和机器2的/etc/mail/sendmail.mc
去掉下列行的dnl
dnl DAEMON_OPTIONS('Port=smtp,Addr=127.0.0.1,Name=MTA')
作用是:使得可以接受其他域的mail。
3) 机器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
4) 机器1和机器2上,重新启动sendmail.
# service sendmail restart
# chkconfig sendmail on
2.检测sendmail是否正常,及模拟sendmail操作。
1) 检测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.example.com
(subdomain name) $m = example.com
(node name) $k = station2
========================================================
Recipient names must be specified
如果显示localhost的话,检查/etc/hosts 去掉除127.0.0.1以外的行。如果还有问题,
查看是否在/etc/sysconfig/network中设置了HOSTNAME
2) 模拟sendmail的操作。
# echo “hello server1” | mail -v -s hello root@server1
root@server1... Connecting to localhost.localdomain. via relay...
220 station2.example.com ESMTP Sendmail 8.12.5/8.12.5; Thu, 17 Jul 2003 05:18:42 +0800
>>> EHLO station2.example.com
250-station2.example.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:<root@station2.example.com> SIZE=47
250 2.1.0 <root@station2.example.com>... Sender ok
>>> RCPT To:<root@server1.example.com>
>>> DATA
250 2.1.5 <root@server1.example.com>... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .
250 2.0.0 h6GLIgpx001304 Message accepted for delivery
root@server1... Sent (h6GLIgpx001304 Message accepted for delivery)
Closing connection to localhost.localdomain.
>>> QUIT
221 2.0.0 station2.example.com closing connection
sendmail的工作过程就如上所示。
你可以看日志,检查mail的工作过程,更有意义的观察方法:
在超级用户,另一终端:
# tail -f /var/log/maillog
会动态显示。
3.sendmail中使用假名:
1) 增加新用户。
# useradd student2
# passwd student2
2) 编辑/etc/aliases,增加下列三行。
me: student2
wizards:root,me
methere: student2@station2.example.com
3) 更新假名数据库。
# newaliases
4) 测试:
# echo “hello there” | mail -s “hello” me
# echo “hello there” | mail -s “hello” wizards
# echo “hello there” | mail -s “hello” methere
5) student用户收到几封邮件?root受到几封邮件?
4.控制中转行为。
1) 在机器2上编辑/etc/mail/sendmail.mc 文件,增加下列一行:
FEATURE(promiscuous_relay)dnl
注意:如果你这台机连到internet上的话,不推荐你这么作,因为,internet上的用
户会用你的这台机作为跳板,伪装发邮件,使得邮件接收者无迹可寻。
2) 在机器2上用m4产生新的配置文件,这里最好再备份原/etc/mail/sendmail.cf
# cp /etc/mail/sendmail.cf /etc/mail/sendmail.cf.BAK2
# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
3) 现在你在机器1上模拟,一个用心不良的用户,用你的机器2作为跳板,发送邮件。
这里假设你有一个邮件叫 linuxsir@sina.com.cn,具体可以变更。
# telnet station2.example.com 25
Trying 192.168.0.2...
Connected to station2.example.com.
Escape character is '^]'.
220 station2.example.com ESMTP Sendmail 8.12.5/8.12.5; Thu, 17 Jul 2003 05:45:05 +0800
helo mail.cracker.org
250 station2.example.com Hello IDENT:root@station2.example.com. [192.168.0.2], pleased to meet you
mail from: spammer@cracker.org
250 2.1.0 spammer@cracker.org... Sender ok
rcpt to: linuxsir@sina.com.cn
250 2.1.5 linuxsir@sina.com.cn... Recipient ok
data
354 Enter mail, end with "." on a line by itself
Subject: Relayed
This is faked and relayed!
ok?
.
250 2.0.0 h6GLj5MV001565 Message accepted for delivery
quit
221 2.0.0 station2.example.com closing connection
Connection closed by foreign host.
4) 观察机器2的/var/log/maillog
5) 收你的linuxsir@sina.com.cn的邮件,看看里面的格式。
6) 机器2,关掉中转。
# cp /etc/mail/sendmail.cf /etc/mail/sendmail.cf.BAK2
# cp /etc/mail/sendmail.cf.BAK1 /etc/mail/sendmail.cf
# service sendmail restart
重作上面3)步,结果会怎么样呢?
7) 机器2 有选择的中转:
编辑/etc/mail/access,增加
example.com RELAY
重作上面3) 步,结果如何?
5.安装和配置POP服务器和客户端。
1) 机器2上,检查下列包是否装过
xinted
krb5-libs*
imap
缺什么,装什么
2) 机器2上,启动服务:
service xinetd start
chkconfig ipop3 on
3) 机器2上,确认服务。
# echo "mail to be popped" | mail -s "hello student2" student2
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK POP3 localhost.localdomain v2001.78rh server ready
user student2
+OK User name accepted, password please
pass student2
+OK Mailbox open, 1 messages
stat
+OK 1 641
TOP 1 700
+OK Top of message follows
Return-Path: <root@station2.example.com>
Received: from station2.example.com (localhost.localdomain [127.0.0.1])
by station2.example.com (8.12.5/8.12.5) with ESMTP id h6GMB9MV001575
for <student2@station2.example.com>; Thu, 17 Jul 2003 06:11:09 +0800
Received: (from root@localhost)
by station2.example.com (8.12.5/8.12.5/Submit) id h6GMB9T0001573
for student2; Thu, 17 Jul 2003 06:11:09 +0800
Date: Thu, 17 Jul 2003 06:11:09 +0800
From: root <root@station2.example.com>
Message-Id: <200307162211.h6GMB9T0001573@station2.example.com>
To: student2@station2.example.com
Subject: hello student2
Status:
mail to be popped
.
dele 1
+OK Message deleted
quit
+OK Sayonara
Connection closed by foreign host.
以上就是pop3的对话过程。如果一切正常的话,你的pop3服务器已经建立。
4) 机器1上安装fetchmail 包。
5) 机器1上,root创建下列文件:
vi /root/.fetchmailrc
poll station2.example.com with protocol pop3:
user student2
password "student2"
6) 机器2上,运行:
# echo "mail to be popped" | mail -s "hello student2" student2
7) 机器1上作为POP3客户端,root收邮件:
# fetchmail -v
能收到邮件吗?
8) 你有油箱吗?仿照上面5) 的格式,写一个pop3客户收邮件的fetchmailrc,试试能
收邮件吗?假设你有个邮箱:linuxsir@sina.com,密码:linuxsir
提示:poll mail.sina.com.cn with protocol pop3:
user linuxsir
password "linuxsir"
[实验总结]
配置sendmail非常复杂,如果你在都完本文后,仍觉的一头雾水的话,建议参考一些
mail工作原理的资料。另外,/usr/share/doc/sendmail/也有不少资料可供参考。
如果网页看不清楚,请参考附件:word文档
如果超连接无效,具体地址在
http://www.linuxsir.cn/bbs/attachment.php?s=&postid=290285 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|