Chinaunix首页 | 论坛 | 博客
  • 博客访问: 85863
  • 博文数量: 20
  • 博客积分: 1926
  • 博客等级: 上尉
  • 技术积分: 210
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-16 17:21
文章分类
文章存档

2011年(1)

2009年(19)

分类: LINUX

2009-11-02 00:09:03

搭建有DNSSendmail服务器

 

Author: Jaylin Zhou

Date: 10/20/2009


要求:一个DNS服务器,两个MTA,两个Clients,一个Client在一个MTA的域里。需要 两个Clients之间可以互相发mails

 

环境:5台装有Red Hat Enterprise Linux 5 update 3的机器

DNS服务器:server.xin.com/server.jaylin.com

192.168.1.10

192.168.2.10

一台MTAmail.jaylin.com

192.168.1.9

另一台MTAmail.xin.com

192.168.2.11

一台Clientclient.jaylin.com

192.168.1.7

另一台Clientclient.xin.com

192.168.2.8

 

配置DNS服务器

# vi /etc/named.caching-nameserver.conf

acl jaylin { 192.168.1.0/24; };

acl xin { 192.168.2.0/24; };

options {

        listen-on port 53 { 127.0.0.1; jaylin; xin; };

        listen-on-v6 port 53 { ::1; };

        directory       "/var/named";

        dump-file       "/var/named/data/cache_dump.db";

        statistics-file "/var/named/data/named_stats.txt";

        memstatistics-file "/var/named/data/named_mem_stats.txt";

        // Those options should be used carefully because they disable port

        // randomization

        // query-source    port 53;

        // query-source-v6 port 53;

        allow-query     { localhost; jaylin; xin; };

};

logging {

        channel default_debug {

                file "data/named.run";

                severity dynamic;

        };

};

view localhost_resolver {

        match-clients      { localhost; jaylin; xin; };

        match-destinations { localhost; jaylin; xin; };

        recursion yes;

        include "/etc/named.rfc1912.zones";

};

# vi /etc/named.rfc1912.zones

zone "jaylin.com" IN {

        type master;

        file "jaylin.com.zone";

        allow-update { none; };

};

zone "1.168.192.in-addr.arpa" IN {

        type master;

        file "jaylin.com.local";

        allow-update { none; };

};

zone "xin.com" IN {

        type master;

        file "xin.com.zone";

        allow-update { none; };

};

zone "2.168.192.in-addr.arpt" IN {

        type master;

        file "xin.com.local";

        allow-update { none; };

};

 

# vi jaylin.com.zone

$TTL    86400

@               IN SOA  server.jaylin.com. root@jaylin.com. (

                                        42              ; serial (d. adams)

                                        3H              ; refresh

                                        15M             ; retry

                                        1W              ; expiry

                                        1D )            ; minimum

                IN NS           server.jaylin.com.

                IN MX 5         mail.jaylin.com.

server          IN A            192.168.1.10

mail            IN A            192.168.1.9

client          IN A            192.168.1.7

 

# vi jaylin.com.local

$TTL    86400

@       IN      SOA     server.jaylin.com. root@jaylin.com.  (

                                      1997022700 ; Serial

                                      28800      ; Refresh

                                      14400      ; Retry

                                      3600000    ; Expire

                                      86400 )    ; Minimum

        IN      NS      server.jaylin.com.

10      IN      PTR     server.jaylin.com.

9       IN      PTR     mail.jaylin.com.

7       IN      PTR     client.jaylin.com.

 

# vi xin.com.zone

$TTL    86400

@               IN SOA  server.xin.com. root@xin.com. (

                                        42              ; serial (d. adams)

                                        3H              ; refresh

                                        15M             ; retry

                                        1W              ; expiry

                                        1D )            ; minimum

                IN NS           server.xin.com.

                IN MX 5         mail.xin.com.

server          IN A            192.168.2.10

mail            IN A            192.168.2.11

client          IN A            192.168.2.8

 

# vi xin.com.local

$TTL    86400

@       IN      SOA     server.xin.com. root@xin.com.  (

                                      1997022700 ; Serial

                                      28800      ; Refresh

                                      14400      ; Retry

                                      3600000    ; Expire

                                      86400 )    ; Minimum

        IN      NS      server.xin.com.

10      IN      PTR     server.xin.com.

11      IN      PTR     mail.xin.com.

8       IN      PTR     client.xin.com.

DNS服务器的ip_forward打开,作为一个路由器使用。

 

配置mail.jaylin.com服务器

安装下面的包

sendmail-8.13.8-2.el5

sendmail-cf-8.13.8-2.el5

dovecot-1.0.7-7.el5

mail.jaylin.com/etc/resolv.conf文件改为192.168.1.10

加一条路由:

# route add -net 192.168.2.0/24 gw 192.168.1.10

 

修改配置文件/etc/mail/sendmail.mc

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

 

# vi /etc/mail/access

Connect:localhost.localdomain           RELAY

Connect:localhost                      RELAY

Connect:127.0.0.1                      RELAY

to:xin.com                            RELAY

to:jaylin.com                     OK

 

# vi /etc/mail/local-host-names

mail.jaylin.com

jaylin.com

 

修改/etc/dovecot.conf文件,将下面的一行的注释去掉:

protocols = imap imaps pop3 pop3s

 

启动sendmaildovecot服务。

# service sendmail start

Starting sendmail:                                         [  OK  ]

Starting sm-client:                                        [  OK  ]

# service dovecot start

Starting Dovecot Imap:                                     [  OK  ]

 

检查一下25端口和110端口是否打开

# netstat -nlp | grep 25 

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

unix  2      [ ACC ]     STREAM     LISTENING     6025   1718/dbus-daemon    /var/run/dbus/system_bus_socket

# netstat -nlp | grep 110

tcp        0      0 :::110           :::*               LISTEN      2245/dovecot        

说明sendmaildovecot服务都正常启动了。

 

配置mail.xin.com服务器

安装下面的包

sendmail-8.13.8-2.el5

sendmail-cf-8.13.8-2.el5

dovecot-1.0.7-7.el5

mail.xin.com/etc/resolv.conf文件改为192.168.2.10

加一条路由:

# route add -net 192.168.1.0/24 gw 192.168.2.10

 

修改配置文件/etc/mail/sendmail.mc

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

 

# vi /etc/mail/access

Connect:localhost.localdomain             RELAY

Connect:localhost                       RELAY

Connect:127.0.0.1                       RELAY

to:xin.com                              OK

to:jaylin.com                            RELAY

 

# vi /etc/mail/local-host-names 

mail.xin.com

xin.com

 

修改/etc/dovecot.conf文件,将下面的一行的注释去掉:

protocols = imap imaps pop3 pop3s

 

启动sendmaildovecot服务。

# service sendmail start

Starting sendmail:                                         [  OK  ]

Starting sm-client:                                        [  OK  ]

# service dovecot start

Starting Dovecot Imap:                                     [  OK  ]

 

检查一下25端口和110端口是否打开

# netstat -nlp | grep 25 

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

unix  2      [ ACC ]     STREAM     LISTENING     6025   1718/dbus-daemon    /var/run/dbus/system_bus_socket

# netstat -nlp | grep 110

tcp        0      0 :::110           :::*                LISTEN      2245/dovecot        

说明sendmaildovecot服务都正常启动了。

 

测试环境

1. 从客户端client.jaylin.com通过telnet方式到mail.jaylin.com25端口,以jaylin用户向mail.xin.com服务器上的xin用户发送邮件。客户端client.xin.com通过telnet方式到mail.xin.com110端口查收邮件。

client.jaylin.com上发送邮件:

# telnet mail.jaylin.com 25

Trying 192.168.1.9...

Connected to mail.jaylin.com (192.168.1.9).

Escape character is '^]'.

220 mail.jaylin.com ESMTP Sendmail 8.13.8/8.13.8; Tue, 20 Oct 2009 11:34:43 +0800

MAIL FROM:jaylin@jaylin.com

250 2.1.0 jaylin@jaylin.com... Sender ok

RCPT TO:xin@xin.com

250 2.1.5 xin@xin.com... Recipient ok

DATA

354 Enter mail, end with "." on a line by itself

SUBJECT xin

hehe~

.

250 2.0.0 n9K3Yhg3002271 Message accepted for delivery

quit

221 2.0.0 mail.jaylin.com closing connection

Connection closed by foreign host.

 

client.xin.com上接受邮件:

# telnet mail.xin.com 110

Trying 192.168.2.11...

Connected to mail.xin.com (192.168.2.11).

Escape character is '^]'.

+OK Dovecot ready.

User xin

+OK

Pass ******

+OK Logged in.

List

+OK 2 messages:

1 725

2 604

.

retr 2

+OK 604 octets

Return-Path: 

Received: from mail.jaylin.com (mail.jaylin.com [192.168.1.9])

        by mail.xin.com (8.13.8/8.13.8) with ESMTP id n9K5vnZ7002364

        for ; Tue, 20 Oct 2009 13:57:50 +0800

Received: from [192.168.1.7] ([192.168.1.7])

        by mail.jaylin.com (8.13.8/8.13.8) with SMTP id n9K3Yhg3002271

        for xin@xin.com; Tue, 20 Oct 2009 11:35:02 +0800

Date: Tue, 20 Oct 2009 11:34:43 +0800

From: jaylin@jaylin.com

Message-Id: <200910200335.n9K3Yhg3002271@mail.jaylin.com>

X-Authentication-Warning: mail.jaylin.com: [192.168.1.7] didn't use HELO protocol

SUBJECT xin

hehe~

.

quit

+OK Logging out.

Connection closed by foreign host.

2. 从客户端client.xin.com通过telnet方式到mail.xin.com25端口,以xin用户向mail.jaylin.com服务器上的jaylin用户发送邮件。客户端client.jaylin.com通过telnet方式到mail.jaylin.com110端口查收邮件。

 

client.xin.com上发送邮件:

# telnet mail.xin.com 25

Trying 192.168.2.11...

Connected to mail.xin.com (192.168.2.11).

Escape character is '^]'.

220 mail.xin.com ESMTP Sendmail 8.13.8/8.13.8; Tue, 20 Oct 2009 14:03:31 +0800

MAIL FROM:xin@xin.com

250 2.1.0 xin@xin.com... Sender ok

RCPT TO:jaylin@jaylin.com

250 2.1.5 jaylin@jaylin.com... Recipient ok

DATA

354 Enter mail, end with "." on a line by itself

SUBJECT jaylin

heihei~

.

250 2.0.0 n9K63Vpp002386 Message accepted for delivery

quit

221 2.0.0 mail.xin.com closing connection

Connection closed by foreign host.

 

client.jaylin.com上接受邮件:

# telnet mail.jaylin.com 110

Trying 192.168.1.9...

Connected to mail.jaylin.com (192.168.1.9).

Escape character is '^]'.

+OK Dovecot ready.

User jaylin

+OK

Pass ******

+OK Logged in.

List

+OK 9 messages:

1 360

2 448

3 447

4 447

5 434

6 434

7 518

8 450

9 598

.

retr 9

+OK 598 octets

Return-Path: 

Received: from mail.xin.com (mail.xin.com [192.168.2.11])

        by mail.jaylin.com (8.13.8/8.13.8) with ESMTP id n9K3fTaa002285

        for ; Tue, 20 Oct 2009 11:41:30 +0800

Received: from [192.168.2.8] ([192.168.2.8])

        by mail.xin.com (8.13.8/8.13.8) with SMTP id n9K63Vpp002386

        for jaylin@jaylin.com; Tue, 20 Oct 2009 14:03:47 +0800

Date: Tue, 20 Oct 2009 14:03:31 +0800

From: xin@xin.com

Message-Id: <200910200603.n9K63Vpp002386@mail.xin.com>

X-Authentication-Warning: mail.xin.com: [192.168.2.8] didn't use HELO protocol

SUBJECT jaylin

heihei~

.

quit

+OK Logging out.

Connection closed by foreign host.

 

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