Chinaunix首页 | 论坛 | 博客
  • 博客访问: 303757
  • 博文数量: 35
  • 博客积分: 1141
  • 博客等级: 少尉
  • 技术积分: 905
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-12 20:35
文章分类

全部博文(35)

文章存档

2012年(35)

我的朋友

分类: LINUX

2012-07-05 15:48:25

Linuxmail服务器应用之sendmail邮件系统的一个案例

sendmail邮件系统的一个案例

实验拓扑

① :在mail.bj.com安装sendmail并进行简单配置
[root@mail ~]# mkdir /mnt/cdrom

[root@mail ~]# mount /dev/cdrom /mnt/cdrom/

mount: block device /dev/cdrom is write-protected, mounting read-only

[root@mail ~]# cd /mnt/cdrom/Server/

[root@mail Server]# rpm -qa |grep -E "sendmail|m4"

m4-1.4.5-3.el5.1
sendmail-8.13.8-2.el5
[root@mail Server]# rpm -ivh sendmail-
sendmail-8.13.8-2.el5.i386.rpm          #主程序包
sendmail-cf-8.13.8-2.el5.i386.rpm           #配置工具包
sendmail-devel-8.13.8-2.el5.i386.rpm
sendmail-doc-8.13.8-2.el5.i386.rpm

[root@junjie Server]# rpm -ivh sendmail-cf-8.13.8-2.el5.i386.rpm

[root@mail Server]# cd /etc/mail/
[root@mail mail]# ls
Makefile     domaintable.db    mailertable.db submit.mc
access       helpfile          sendmail.cf     trusted-users
access.db    local-host-names sendmail.mc     virtusertable
domaintable mailertable       submit.cf       virtusertable.db
编辑主要配置文件:
[root@mail mail]# vim sendmail.mc

116 DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnl

[root@mail ~]# netstat -tupln |grep sendmail

tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      3407/sendmail: acce

[root@mail ~]# service sendmail restart

[root@mail ~]# netstat -tupln |grep sendmail

tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      4440/sendmail: acce

中继文件:
[root@mail mail]# vim access #增加10,11,12行

 9 Connect:127.0.0.1                       RELAY

 10 Connect:10.106.6                        RELAY
 11 bj.com                                  OK
 12 sh.com                                  RELAY
表明邮件服务器的域名:
[root@mail mail]# vim local-host-names

增加:bj.com

重新启动sendmail服务器:
[root@mail mail]# chkconfig sendmail on
[root@mail mail]# service sendmail restart
Shutting down sm-client:                                   [ OK ]
Shutting down sendmail:                                    [ OK ]
Starting sendmail:                                         [ OK ]
Starting sm-client:                                        [ OK ]
新建账户:
[root@mail ~]# useradd user1
[root@mail ~]# useradd user2

[root@mail ~]# echo "123" |passwd --stdin user1

[root@mail ~]# echo "123" |passwd --stdin user2

② :搭建dns服务器,并作相关配置:
[root@mail ~]# cd /mnt/cdrom/Server/

[root@mail Server]# rpm -ivh bind-9.3.4-10.P1.el5.i386.rpm

[root@mail Server]# rpm -ivh bind-chroot-9.3.4-10.P1.el5.i386.rpm

[root@....Server]# rpm -ivh caching-nameserver-9.3.4-10.P1.el5.i386.rpm

[root@mail Server]# cd /var/named/chroot/etc/

[root@mail etc]# ll

[root@mail etc]# cp -p named.caching-nameserver.conf named.conf

[root@mail etc]# vim named.conf
15         listen-on port 53 { any; };
27         allow-query     { any; };
36         match-clients      { any; };
37         match-destinations { any; };

[root@mail etc]# vim named.rfc1912.zones

增加以下几行:

20 zone "bj.com" IN {

 21         type master;

 22         file "bj.com.db";

 23         allow-update { none; };

 24 };
[root@mail etc]# cd ../var/named/
[root@mail named]# ll

[root@mail named]# cp -p localhost.zone bj.com.db

[root@mail named]# vim bj.com.db
 2 @               IN SOA ns.bj.com.       root (

9 @               IN NS           ns.bj.com.

 10 ns              IN A            10.106.6.254
 11 mail            IN A            10.106.6.254
 12 pop3            IN CNAME        mail
 13 smtp            IN CNAME        mail

 14 @               IN MX 10        mail

[root@mail named]# chkconfig named on
[root@mail named]# service named start

Starting named:                                            [ OK ]

③ :客户端测试dns解析,进行简单配置:

④ :进行配置,并安装接收dovecot服务器:

进行系统配置:

[root@mail named]# vim /etc/resolv.conf

 1 nameserver 10.106.6.254

[root@mail named]# vim /etc/sysconfig/network

 3 HOSTNAME=mail.bj.com
[root@mail named]# vim /etc/hosts

127.0.0.1      mail.bj.com localhost.localdomain localh    ost

[root@mail named]#init 6
[root@mail ~]# yum install -y dovecot
[root@mail ~]# chkconfig dovecot on
[root@mail ~]# service dovecot start

Starting Dovecot Imap:                                     [ OK ] [root@mail ~]# netstat -tupln |grep dovecot

(110,143,993(imaps),995(pop3s))

⑤ :bj.com客户端发送信息测试:(使用foxmail)
user1给user1发送信息:

user1给user2发送信息:

日志分析:

Mar 23 10:45:50 mail sendmail[3938]: q2N2jovd003938: from=, size=1430, class=0, nrcpts=1, msgid=<201203231044542450591@bj.com>, proto=ESMTP, daemon=MTA, relay=[10.106.6.190]

Mar 23 10:45:50 mail sendmail[3939]: q2N2jovd003938: to=, ctladdr= (501/501), delay=00:00:00, xdelay=00:00:00, mailer=local, pri=31594, dsn=2.0.0, stat=Sent

Mar 23 10:46:08 mail dovecot: pop3-login: Login: user=, method=PLAIN, rip=::ffff:10.106.6.190, lip=::ffff:10.106.6.254

Mar 23 10:46:09 mail dovecot: POP3(user1): Disconnected: Logged out top=0/0, retr=1/1696, del=0/1, size=1679

 

Mar 23 10:58:20 mail sendmail[4012]: q2N2wKKs004012: from=, size=1481, class=0, nrcpts=1, msgid=<201203231057242513780@bj.com>, proto=ESMTP, daemon=MTA, relay=[10.106.6.190]

Mar 23 10:58:20 mail sendmail[4013]: q2N2wKKs004012: to=, ctladdr= (501/501), delay=00:00:00, xdelay=00:00:00, mailer=local, pri=31645, dsn=2.0.0, stat=Sent

Mar 23 10:59:09 mail dovecot: pop3-login: Aborted login: user=, method=PLAIN, rip=::ffff:10.106.6.190, lip=::ffff:10.106.6.254

Mar 23 10:59:09 mail dovecot: pop3-login: Login: user=, method=PLAIN, rip=::ffff:10.106.6.190, lip=::ffff:10.106.6.254

Mar 23 10:59:09 mail dovecot: POP3(user2): Disconnected: Logged out top=0/0, retr=1/1748, del=0/2, size=3448

⑥ :配置mail.sh.com上海服务器:
安装sendmail
[root@mail ~]# mkdir /mnt/cdrom

[root@mail ~]# mount /dev/cdrom /mnt/cdrom/

[root@mail ~]# cd /mnt/cdrom/Server/

[root@mail Server]# rpm -qa |grep -E "sendmail|m4"

[root@junjie Server]# rpm -ivh sendmail-cf-8.13.8-2.el5.i386.rpm

[root@mail Server]# cd /etc/mail/
[root@mail mail]# ls
编辑主要配置文件:
[root@mail mail]# vim sendmail.mc

116 DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnl

[root@mail ~]# netstat -tupln |grep sendmail

tcp        0      127.0.0.1:25                0.0.0.0:*                   LISTEN      3607/sendmail: acce

[root@mail ~]# service sendmail restart

[root@mail ~]# netstat -tupln |grep sendmail

tcp        0      0.0.0.0:25                  0.0.0.0:*                   LISTEN      3528/sendmail: acce

中继文件:
[root@mail mail]# vim access #增加10,11,12行

 9 Connect:127.0.0.1                       RELAY

 10 Connect:10.106.6                        RELAY
 11 sh.com                                  OK
 12 bj.com                                  RELAY
表明邮件服务器的域名:
[root@mail mail]# vim local-host-names

增加:sh.com

重新启动sendmail服务器:
[root@mail mail]#chkconfig sendmail on
[root@mail mail]# service sendmail restart
Shutting down sm-client:                                   [ OK ]
Shutting down sendmail:                                    [ OK ]
Starting sendmail:                                         [ OK ]
Starting sm-client:                                        [ OK ]
新建账户:
[root@mail ~]# useradd user3
[root@mail ~]# useradd user4

[root@mail ~]# echo "123" |passwd --stdin user3

[root@mail ~]# echo "123" |passwd --stdin user4

⑦ :搭建mail.sh.com的dns服务器,并作相关配置:
[root@mail ~]# cd /mnt/cdrom/Server/

[root@mail Server]# rpm -ivh bind-9.3.4-10.P1.el5.i386.rpm

[root@mail Server]# rpm -ivh bind-chroot-9.3.4-10.P1.el5.i386.rpm

[root@....Server]# rpm -ivh caching-nameserver-9.3.4-10.P1.el5.i386.rpm

[root@mail Server]# cd /var/named/chroot/etc/

[root@mail etc]# ll

[root@mail etc]# cp -p named.caching-nameserver.conf named.conf

[root@mail etc]# vim named.conf
15         listen-on port 53 { any; };

27         allow-query     { any; };

36         match-clients      { any; };
37         match-destinations { any; };

[root@mail etc]# vim named.rfc1912.zones

增加以下几行:

20 zone "sh.com" IN {

 21         type master;

 22         file "sh.com.db";

 23         allow-update { none; };

 24 };
[root@mail etc]# cd ../var/named/
[root@mail named]# ll

[root@mail named]# cp -p localhost.zone sh.com.db

[root@mail named]# vim sh.com.db
 2 @               IN SOA ns.sh.com.       root (
 9 @               IN NS           ns.sh.com.
 10 ns              IN A            10.106.6.253
 11 @               IN MX 10        mail
 12 mail            IN A            10.106.6.253
 13 pop3            IN CNAME        mail
 14 smtp            IN CNAME        mail
[root@mail named]# chkconfig named on
[root@mail named]# service named start

Starting named:                                            [ OK ]

客户端测试dns解析:

⑧ :在sh.com进行系统配置,并安装接收服务器:

[root@mail named]# vim /etc/resolv.conf

 1 nameserver 10.106.6.253

[root@mail named]# vim /etc/sysconfig/network

 3 HOSTNAME=mail.sh.com
[root@mail named]# vim /etc/hosts

127.0.0.1      mail.sh.com localhost.localdomain localh    ost

[root@mail named]#init 6
安装接受服务器:
[root@mail ~]# yum install -y dovecot
[root@mail ~]# chkconfig dovecot on
[root@mail ~]# service dovecot start

Starting Dovecot Imap:                                     [ OK ] [root@mail ~]# netstat -tupln |grep dovecot

(110,143,993(imaps),995(pop3s))

⑨ :sh.com的客户端测试,user3给user4发信息:

⑩ :做dns转发和配置反向解析
在mail.bj.com上做dns转发和反向解析:

[root@mail ~]# cd /var/named/chroot/etc/

[root@mail etc]# vim named.conf

28         forwarders      { 10.106.6.253; };

[root@mail etc]# rndc reload

server reload successful

[root@mail etc]# vim named.rfc1912.zones

55 zone "6.106.10.in-addr.arpa" IN {

 56         type master;

 57         file "10.106.6.db";

 58         allow-update { none; };

 59 };

[root@mail etc]# cd ../var/named/

[root@mail named]# ll

[root@mail named]# cp -p named.local 10.106.6.db

[root@mail named]# vim 10.106.6.db

254     IN      PTR     mail.bj.com.

153     IN      PTR     mail.sh.com.

[root@mail named]# rndc reload

server reload successful

在mail.sh.com上做dns转发和反向解析:

[root@mail ~]# cd /var/named/chroot/etc/

[root@mail etc]# vim named.conf

28         forwarders      { 10.106.6.254; };

[root@mail etc]# rndc reload

server reload successful

[root@mail etc]# vim named.rfc1912.zones

55 zone "6.106.10.in-addr.arpa" IN {

 56         type master;

 57         file "10.106.6.db";

 58         allow-update { none; };

 59 };

[root@mail etc]# cd ../var/named/

[root@mail named]# ll

[root@mail named]# cp -p named.local 10.106.6.db

[root@mail named]# vim 10.106.6.db

254     IN      PTR     mail.bj.com.

153     IN      PTR     mail.sh.com.

[root@mail named]# rndc reload

server reload successful

⑪ :测试通信情况

(bj.com的客户user1@bj.com与sh.com的客户user3@sh.com通信)

⑫ :监控的日志信息:
 

mail.bj.com的日志信息:

[root@mail ~]# tail -f /var/log/maillog

Mar 23 15:46:07 mail dovecot: pop3-login: Aborted login: user=, method=PLAIN, rip=::ffff:10.106.6.190, lip=::ffff:10.106.6.254

Mar 23 15:46:07 mail dovecot: pop3-login: Login: user=, method=PLAIN, rip=::ffff:10.106.6.190, lip=::ffff:10.106.6.254

Mar 23 15:46:07 mail dovecot: POP3(user2): Disconnected: Logged out top=0/0, retr=0/0, del=0/3, size=5025

Mar 23 15:46:13 mail sendmail[2298]: q2N7kCbh002298: from=, size=1458, class=0, nrcpts=1, msgid=<2012032316322753227112@bj.com>, proto=ESMTP, daemon=MTA, relay=[10.106.6.190]

Mar 23 15:46:16 mail sendmail[2300]: q2N7kCbh002298: to=, ctladdr= (500/500), delay=00:00:03, xdelay=00:00:03, mailer=esmtp, pri=121458, relay=mail.sh.com. [10.106.6.253], dsn=2.0.0, stat=Sent (q2N8W6jM003583 Message accepted for delivery)

Mar 23 15:48:38 mail sendmail[2307]: q2N7mc6a002307: from=, size=3353, class=0, nrcpts=1, msgid=<001a01cd08cf$bcf83cd0$c8066a0a@hp3aea877158e2>, proto=ESMTP, daemon=MTA, relay=[10.106.6.253]

Mar 23 15:48:38 mail sendmail[2308]: q2N7mc6a002307: to=, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=33514, dsn=2.0.0, stat=Sent

Mar 23 15:48:54 mail dovecot: pop3-login: Aborted login: user=, method=PLAIN, rip=::ffff:10.106.6.190, lip=::ffff:10.106.6.254

Mar 23 15:48:54 mail dovecot: pop3-login: Login: user=, method=PLAIN, rip=::ffff:10.106.6.190, lip=::ffff:10.106.6.254

Mar 23 15:48:54 mail dovecot: POP3(user1): Disconnected: Logged out top=0/0, retr=1/3623, del=0/1, size=3606

Mar 23 15:51:04 mail sendmail[2320]: q2N7p4Pg002320: from=, size=1470, class=0, nrcpts=1, msgid=<2012032316372380506613@bj.com>, proto=ESMTP, daemon=MTA, relay=[10.106.6.190]

Mar 23 15:51:04 mail sendmail[2322]: q2N7p4Pg002320: to=, ctladdr= (500/500), delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=121470, relay=mail.sh.com. [10.106.6.253], dsn=2.0.0, stat=Sent (q2N8aucK003603 Message accepted for delivery)

Mar 23 15:52:25 mail sendmail[2325]: q2N7qPlW002325: from=, size=3514, class=0, nrcpts=1, msgid=<002401cd08d0$4378c360$c8066a0a@hp3aea877158e2>, proto=ESMTP, daemon=MTA, relay=[10.106.6.253]

Mar 23 15:52:25 mail sendmail[2326]: q2N7qPlW002325: to=, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=33675, dsn=2.0.0, stat=Sent

Mar 23 15:52:34 mail dovecot: pop3-login: Aborted login: user=, method=PLAIN, rip=::ffff:10.106.6.190, lip=::ffff:10.106.6.254

Mar 23 15:52:34 mail dovecot: pop3-login: Login: user=, method=PLAIN, rip=::ffff:10.106.6.190, lip=::ffff:10.106.6.254

Mar 23 15:52:34 mail dovecot: POP3(user1): Disconnected: Logged out top=0/0, retr=1/3786, del=0/2, size=7375

mail.sh.com的日志信息:

[root@mail ~]# tail -f /var/log/maillog

Mar 23 16:24:06 mail dovecot: pop3-login: Login: user=, method=PLAIN, rip=::ffff:10.106.6.200, lip=::ffff:10.106.6.253

Mar 23 16:24:06 mail dovecot: POP3(user3): Disconnected: Logged out top=0/0, retr=0/0, del=0/0, size=0

Mar 23 16:24:07 mail dovecot: pop3-login: Login: user=, method=PLAIN, rip=::ffff:10.106.6.200, lip=::ffff:10.106.6.253

Mar 23 16:24:07 mail dovecot: POP3(user4): Disconnected: Logged out top=0/0, retr=0/0, del=0/0, size=0

Mar 23 16:32:07 mail sendmail[3583]: q2N8W6jM003583: from=, size=1617, class=0, nrcpts=1, msgid=<2012032316322753227112@bj.com>, proto=ESMTP, daemon=MTA, relay=mail.bj.com [10.106.6.254]

Mar 23 16:32:08 mail sendmail[3584]: q2N8W6jM003583: to=, delay=00:00:01, xdelay=00:00:01, mailer=local, pri=31791, dsn=2.0.0, stat=Sent

Mar 23 16:32:51 mail dovecot: pop3-login: Login: user=, method=PLAIN, rip=::ffff:10.106.6.200, lip=::ffff:10.106.6.253

Mar 23 16:32:51 mail dovecot: POP3(user3): Disconnected: Logged out top=0/0, retr=1/1898, del=1/1, size=1881

Mar 23 16:34:29 mail sendmail[3595]: q2N8YTvQ003595: from=, size=3193, class=0, nrcpts=1, msgid=<001a01cd08cf$bcf83cd0$c8066a0a@hp3aea877158e2>, proto=SMTP, daemon=MTA, relay=[10.106.6.200]

Mar 23 16:34:29 mail sendmail[3597]: q2N8YTvQ003595: to=, ctladdr= (500/500), delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=123193, relay=mail.bj.com. [10.106.6.254], dsn=2.0.0, stat=Sent (q2N7mc6a002307 Message accepted for delivery)

Mar 23 16:36:56 mail sendmail[3603]: q2N8aucK003603: from=, size=1629, class=0, nrcpts=1, msgid=<2012032316372380506613@bj.com>, proto=ESMTP, daemon=MTA, relay=mail.bj.com [10.106.6.254]

Mar 23 16:36:56 mail sendmail[3604]: q2N8aucK003603: to=, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=31803, dsn=2.0.0, stat=Sent

Mar 23 16:37:04 mail dovecot: pop3-login: Login: user=, method=PLAIN, rip=::ffff:10.106.6.200, lip=::ffff:10.106.6.253

Mar 23 16:37:04 mail dovecot: POP3(user3): Disconnected: Logged out top=0/0, retr=1/1909, del=1/1, size=1892

Mar 23 16:38:16 mail sendmail[3611]: q2N8cGVM003611: from=, size=3354, class=0, nrcpts=1, msgid=<002401cd08d0$4378c360$c8066a0a@hp3aea877158e2>, proto=SMTP, daemon=MTA, relay=[10.106.6.200]

Mar 23 16:38:16 mail sendmail[3613]: q2N8cGVM003611: to=, ctladdr= (500/500), delay=00:00:00, xdelay=00:00:00, mailer=esmtp, pri=123354, relay=mail.bj.com. [10.106.6.254], dsn=2.0.0, stat=Sent (q2N7qPlW002325 Message accepted for delivery)

《完》

--xjzhujunjie

--2012/03/23-19:35

阅读(4495) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~