分类: LINUX
2009-11-02 00:09:03
搭建有DNS的Sendmail服务器
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
一台MTA:mail.jaylin.com
192.168.1.9
另一台MTA:mail.xin.com
192.168.2.11
一台Client:client.jaylin.com
192.168.1.7
另一台Client:client.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
启动sendmail和dovecot服务。
# 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
说明sendmail和dovecot服务都正常启动了。
配置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
启动sendmail和dovecot服务。
# 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
说明sendmail和dovecot服务都正常启动了。
测试环境
1. 从客户端client.jaylin.com通过telnet方式到mail.jaylin.com的25端口,以jaylin用户向mail.xin.com服务器上的xin用户发送邮件。客户端client.xin.com通过telnet方式到mail.xin.com的110端口查收邮件。
在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
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.com的25端口,以xin用户向mail.jaylin.com服务器上的jaylin用户发送邮件。客户端client.jaylin.com通过telnet方式到mail.jaylin.com的110端口查收邮件。
在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
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.