不同地方使用sendmail实现mail的收发
28-1
BJ-mail服务器的配置
1.安装dns
1.1 安装包
[root@mail ~]# yum install bind
[root@mail ~]# yum install bind-chroot –改变dns的路径,保证安全的包
[root@mail ~]# yum install caching-nameserver –y –生成配置文件,提高caching server
[root@mail ~]# yum list all |grep bind
This system is not registered with RHN.
RHN support will be disabled.
bind.i386 30:9.3.4-10.P1.el5 installed
bind-chroot.i386 30:9.3.4-10.P1.el5 installed
bind-libs.i386 30:9.3.4-10.P1.el5 installed
bind-utils.i386 30:9.3.4-10.P1.el5 installed
ypbind.i386 3:1.19-11.el5 installed
1.2 配置
[root@mail ~]# cd /var/named/chroot/etc
[root@mail etc]# cp -p named.caching-nameserver.conf named.conf
[root@mail etc]# vim named.conf
options {
listen-on port 53 { any; };
forwarders { 192.168.101.71;}; --不同区域dns需要转发
allow-query { any; };
};
view localhost_resolver {
match-clients { any; };
match-destinations { any; };
include "/etc/named.rfc1912.zones";
};
1.3声明区域
[root@mail ~]# vim /var/named/chroot/etc/named.rfc1912.zones
zone "bj.com" IN {
type master;
file "bj.com.db";
allow-update { none; };
};
zone "101.168.192.in-addr.arpa" IN {
type master;
file "192.168.101.70.db";
allow-update { none; };
};
1.4产生数据库文件
[root@mail named]# cp -p localhost.zone bj.com.db
[root@mail named]# vim bj.com.db
$TTL 86400
@ IN SOA ns.bj.com. root.126.com (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS ns.bj.com.
ns IN A 192.168.101.70
mail IN A 192.168.101.70
pop3 IN CNAME mail
smtp IN CNAME mail
imtp IN CNAME mail
@ IN MX 10 mail
[root@mail ~]# vim /var/named/chroot/var/named/192.168.101.70.db
$TTL 86400
@ IN SOA localhost. root.localhost. (
1997022700 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS localhost.
71 IN PTR mail.sh.com.
70 IN PTR mail.bj.com.
1.5 dns指向
[root@mail etc]# vim /etc/resolv.conf
nameserver 192.168.101.70
[root@mail named]# vim /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=mail.bj.com
[root@mail etc]# vim /etc/hosts
127.0.0.1 localhost.localdomain localhost
192.168.101.70 mail.bj.com
--更改主机名
1.6 开启服务 解析
[root@mail named]# service named start
[root@mail named]# chkconfig named on
[root@mail named]# rndc reload
server reload successful
[root@mail etc]# nslookup mail.bj.com
[root@mail etc]# dig -t mx bj.com
2.Sendmail 需要的包
2.1需要安装的包
Sendmail-8.13.8。-2.el5 –主包
Sendmai-cf --生成易配置或快速配置的配置文件
Sendmail-devel --开发包
m4.i386 1.4.5-3.el5.1 --转换工具
--重启m4会自动转换
--sendmail.mc—>sendmail.cf
-- accessaccess.db
[root@mail ~]# yum list all |grep sendmail
This system is not registered with RHN.
RHN support will be disabled.
sendmail.i386 8.13.8-2.el5 installed
sendmail-cf.i386 8.13.8-2.el5 installed
sendmail-devel.i386 8.13.8-2.el5 installed
sendmail-doc.i386 8.13.8-2.el5 installed
[root@mail ~]# yum list all |grep m4
This system is not registered with RHN.
RHN support will be disabled.
m4.i386 1.4.5-3.el5.1 installed
[root@mail ~]#
2.2配置监听
更改sendmail.mc
[root@mail mail]# pwd
/etc/mail
[root@mail mail]# vim sendmail.mc
116 DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnl
--默认是本机监听25号端口,需要更改才能使非本地用户使用sendmail发送邮件
--Dnl # 是注视文字
--Dnl 是打开可以使用的
--末尾dnl 去除空格
[root@mail mail]# service sendmail restart
[root@mail mail]# netstat -tunpl |grep 25
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 30569/sendmail: acc
2.3.本地认证 --中继文件
[root@mail ~]# cd /etc/mail
[root@mail mail]# vim access
Connect:localhost.localdomain RELAY
Connect:localhost RELAY
Connect:127.0.0.1 RELAY
#connect:192.168.101. RELAY
-- ok 无条件接受, relay 中继, reject是拒绝
[root@mail mail]# service sendmail restart
2.4本地域名
--知道自己负责的域增加网段可以发送
[root@mail mail]# vim /etc/mail/local-host-names
mail.bj.com –主机名
bj.com –本地域名
[root@mail mail]# service sendmail restart
2.5 添加本地用户
[root@mail etc]# useradd user1
[root@mail etc]# useradd user2
[root@mail etc]# passwd user1
[root@mail etc]# passwd user2
3.安装MAA
[root@mail ~]# yum install dovecot
--更改配置文件
[root@mail ~]# vim /etc/dovecot.conf
20 #protocols = imap imaps pop3 pop3s
--默认全开
22 protocols = pop3
[root@mail ~]# service dovecot restart
[root@mail ~]# chkconfig dovecot on
Sh-mail服务器的配置
1.dns配置
1.1克隆出现的没有ip问题
[root@mail network-scripts]# cd /etc/sysconfig/network-scripts/
[root@mail network-scripts]# ll ifcfg*
-rw-r--r-- 1 root root 117 Sep 15 17:20 ifcfg-eth0
-rw-r--r-- 1 root root 211 Sep 4 20:39 ifcfg-eth0.bak
[root@mail network-scripts]# mv ifcfg-eth0.bak ifcfg-eth0
mv: overwrite `ifcfg-eth0'? y
[root@mail network-scripts]#
1.2 更改配置
[root@mail etc]# cd /var/named/chroot/etc
[root@mail etc]# vim named.conf
options {
listen-on port 53 { any; };
forwarders { 192.168.101.70;}; --不同区域dns需要转发
allow-query { any; };
};
view localhost_resolver {
match-clients { any; };
match-destinations { any; };
recursion yes;
include "/etc/named.rfc1912.zones";
};
[root@mail ~]#vim /var/named/chroot/etc/named.rfc1912.zones
zone "sh.com" IN {
type master;
file "sh.com.db";
allow-update { none; };
};
zone "101.168.192.in-addr.arpa" IN {
type master;
file "192.168.101.71.db";
allow-update { none; };
};
--做反向区域,解决不信任,延迟发送邮件的问题
1.3产生数据库文件
[root@mail etc]# cd /var/named/chroot/var/named
[root@mail named]# mv bj.com.db sh.com.db
[root@mail named]# vim sh.com.db
$TTL 86400
@ IN SOA ns.sh.com. root.126.com (
43 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
@ IN NS ns.sh.com.
ns IN A 192.168.101.71
mail IN A 192.168.101.71
pop3 IN CNAME mail
smtp IN CNAME mail
#imtp IN CNAME mail
@ IN MX 10 mail
[root@mail ~]# cat /var/named/chroot/var/named/192.168.101.71.db
$TTL 86400
@ IN SOA localhost. root.localhost. (
1997022700 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS localhost.
71 IN PTR mail.sh.com.
70 IN PTR mail.bj.com.
[root@mail ~]#
1.4更改主机名
[root@mail named]# vim /etc/resolv.conf
nameserver 192.168.101.71
[root@mail named]# vim /etc/sysconfig/network
HOSTNAME=mail.sh.com
[root@mail named]# vim /etc/hosts
127.0.0.1 localhost.localdomain localhost
192.168.101.71 mail.sh.com
1.5 测试解析域名
[root@mail named]# dig -t mx sh.com
[root@mail named]#
1.6添加用户
[root@mail ~]# useradd user5
[root@mail ~]# passwd user5
[root@mail ~]# useradd user6
[root@mail ~]# passwd user6
2.sendmail的安装配置
2.1安装sendmail
安装同bj-mail
2.1修改配置文件
[root@mail ~]# mailq
/var/spool/mqueue (6 requests)
-----Q-ID----- --Size-- -----Q-Time----- ------------Sender/Recipient-----------
p8FA52pO004641 2 Thu Sep 15 18:05 <root@mail.bj.com>
(host map: lookup (mail.bj.com): deferred)
<user6@mail.bj.com>
p8F9tad9004449 3 Thu Sep 15 17:55 <root@mail.bj.com>
(host map: lookup (mail.bj.com): deferred)
<user5@mail.bj.com>
p8F9sat7004396 3 Thu Sep 15 17:54 <root@mail.bj.com>
(host map: lookup (mail.bj.com): deferred)
<user5@mail.bj.com>
p8F9qa7g004283 3 Thu Sep 15 17:52 <root@mail.bj.com>
(host map: lookup (mail.bj.com): deferred)
<user5@mail.bj.com>
p8F9ldpj004065 3 Thu Sep 15 17:47 <root@mail.bj.com>
(host map: lookup (mail.bj.com): deferred)
<user2@mail.bj.com>
p8F9lmPS004068 3 Thu Sep 15 17:47 <root@mail.bj.com>
(host map: lookup (mail.bj.com): deferred)
<user3@mail.bj.com>
Total requests: 6
--更改配置之前发送给外地区域的邮件都被deferred
[root@mail mail]# vim sendmail.mc
116 DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnl
--默认是本机监听25号端口,需要更改才能使非本地用户使用sendmail发送邮件
--Dnl # 是注视文字
--Dnl 是打开可以使用的
--末尾dnl 去除空格
[root@mail ~]# vim /etc/mail/access
Connect:localhost.localdomain RELAY
Connect:localhost RELAY
Connect:127.0.0.1 RELAY
Connect:192.168.101. RELAY
sh.com ok
bj.com RELAY
[root@mail mail]# vim local-host-names
mail.sh.com –主机名
sh.com –本地域名
[root@mail mail]# service sendmail restart
[root@mail mail]# mailq
/var/spool/mqueue is empty
Total requests: 0
对发 bj地方给sh地方发送邮件,对方能接收
[root@mail ~]# netstat -tupln |grep -E "name|dov|send"
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 192.168.101.70:53 0.0.0.0:* LISTEN 2749/named
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 2749/named
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 5328/sendmail: acce
tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 2749/named
tcp 0 0 :::110 :::* LISTEN 3058/dovecot
tcp 0 0 ::1:53 :::* LISTEN 2749/named
tcp 0 0 ::1:953 :::* LISTEN 2749/named
udp 0 0 0.0.0.0:46353 0.0.0.0:* 2749/named
udp 0 0 192.168.101.70:53 0.0.0.0:* 2749/named
udp 0 0 127.0.0.1:53 0.0.0.0:* 2749/named
udp 0 0 ::1:53 :::* 2749/named
udp 0 0 :::49657 :::* 2749/named
--确保各服务都已经开启 实现对发
[root@mail ~]# hostname
mail.bj.com
[root@mail ~]# mail user5@sh.com
Subject: hello sh
this is bj.
.
Cc:
[root@mail ~]#
[root@mail ~]# hostname
mail.sh.com
[root@mail ~]# su - user5
[user5@mail ~]$ mail
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/user5": 2 messages 1 new
1 MAILER-DAEMON@mail.s Fri Sep 16 01:21 13/542 "DON'T DELETE THIS MES"
>N 2 root@mail.bj.com Fri Sep 16 03:28 19/740 "hello sh"
& 2
Message 2:
From root@mail.bj.com Fri Sep 16 03:28:06 2011
Date: Fri, 16 Sep 2011 05:51:57 +0800
From: root <root@mail.bj.com>
To: user5@sh.com
Subject: hello sh
this is bj.
&
客户端使用sendmail发送接收mail
1.配置outlook
28-2
使用Outlook给外地发信
28-3