RHEL6.4下搭建Postfix+Dovecot邮件服务器
时间:2014-09-13 03:11 来源:linux.it.net.cn 作者:it
在RHEL6.4下搭建Postfix+Dovecot邮件服务器。
实验需求:为公司搭建一台能够收信和发信的邮件服务器(192.168.100.1),为员工提供服务,公司域名为it.net.cn.
一.修改DNS服务器(192.168.100.2)上mx邮件交换记录,确保客户机能解析邮件服务器地址
1.修改DNS区域文件
# vim /var/named/it.net.cn.zone
$TTL 3H
@ IN SOA it.net.cn. root.it.net.cn. (
2014042601; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS dns1.it.net.cn.
IN MX 10 mail.it.net.cn.
dns1 IN A 192.168.100.2
mail IN A 192.168.100.1
……
2.重启服务
# service named restart
3.客户机测试能否解析
# host -t mx it.net.cn 192.168.100.2 //查询目标域的MX记录
Using domain server:
Name: 192.168.100.2
Address: 192.168.100.2#53
Aliases:
it.net.cn mail is handled by 10 mail.it.net.cn.
# host mail.it.net.cn 192.168.100.2 //查看邮件服务器的解析结果
Using domain server:
Name: 192.168.100.2
Address: 192.168.100.2#53
Aliases:
mail.it.net.cn has address 192.168.100.1
二.搭建postfix发信服务器
1.安装软件包
# yum -y install postfix
2.修改主配置文件
[root@mail ~]# cd /etc/postfix/
# postconf -n > tmp.txt //导出非默认配置
# mv main.cf main.cf.bak
# mv tmp.txt main.cf
# vim main.cf
...
9 #inet_interfaces = localhost //监听端口
22 myhostname = mail.it.net.cn //邮件服务器主机名
23 mydomain = it.net.cn //邮件服务器所在区域
24 myorigin = $mydomain //发件人DNS后缀
25 mydestination = $mydomain //指定Postfix允许处理的邮件
26 home_mailbox = Maildir/ //邮箱类型
3、检查语法启动服务
# postfix check
# service postfix start
# chkconfig postfix on
# netstat -tulnp | grep :25 //发信使用SMTP协议
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 3564/master
tcp 0 0 :::25 :::* LISTEN 3564/master
4.新建邮箱用户 //邮件用户默认为系统用户
# useradd damao
# echo 123456| passwd --stdin damao
# useradd tom
# echo 123456| passwd --stdin tom
5.测试发信功能
# telnet mail.it.net.cn 25
Trying 192.168.100.1...
Connected to mail.it.net.cn.
Escape character is '^]'.
220 mail.it.net.cn ESMTP Postfix
helo localhost //宣告客户端
250 mail.it.net.cn
mail from:damao@it.net.cn //邮件发件人
250 2.1.0 Ok
rcpt to:tom@it.net.cn //邮件收件人
250 2.1.5 Ok
data //邮件正文
354 End data with <CR><LF>.<CR><LF>
subject:Test mail //邮件主题
hello,tom //邮件内容
. //独立.表示邮件结束
250 2.0.0 Ok: queued as 9B6463FD97
quit //退出
221 2.0.0 Bye
Connection closed by foreign host.
6.验证邮件是否发送成功
# ls /home/tom/Maildir/new/
1398492202.V803Ibf420M185454.mail.it.net.cn
# cat /home/tom/Maildir/new/1398492202.V803Ibf420M185454.mail.it.net.cn
Return-Path: <damao@it.net.cn>
X-Original-To: tom@it.net.cn
Delivered-To: tom@it.net.cn
Received: from localhost (unknown [192.168.100.1])
by mail.it.net.cn (Postfix) with SMTP id 9B6463FD97
for <tom@it.net.cn>; Fri, 25 Apr 2014 23:00:32 -0700 (PDT)
subject:Test mail
Message-Id: <20140426060137.9B6463FD97@mail.it.net.cn>
Date: Fri, 25 Apr 2014 23:00:32 -0700 (PDT)
From: damao@it.net.cn
To: undisclosed-recipients:;
hello,tom
(责任编辑:IT)
在RHEL6.4下搭建Postfix+Dovecot邮件服务器。 实验需求:为公司搭建一台能够收信和发信的邮件服务器(192.168.100.1),为员工提供服务,公司域名为it.net.cn. 一.修改DNS服务器(192.168.100.2)上mx邮件交换记录,确保客户机能解析邮件服务器地址 1.修改DNS区域文件 # vim /var/named/it.net.cn.zone $TTL 3H @ IN SOA it.net.cn. root.it.net.cn. ( 2014042601; serial 1D ; refresh 1H ; retry 1W ; expire 3H ) ; minimum NS dns1.it.net.cn. IN MX 10 mail.it.net.cn. dns1 IN A 192.168.100.2 mail IN A 192.168.100.1 ……
# service named restart
# host -t mx it.net.cn 192.168.100.2 //查询目标域的MX记录 Using domain server: Name: 192.168.100.2 Address: 192.168.100.2#53 Aliases: it.net.cn mail is handled by 10 mail.it.net.cn.
Using domain server: Name: 192.168.100.2 Address: 192.168.100.2#53 Aliases: mail.it.net.cn has address 192.168.100.1
1.安装软件包 # yum -y install postfix
[root@mail ~]# cd /etc/postfix/ # postconf -n > tmp.txt //导出非默认配置 # mv main.cf main.cf.bak # mv tmp.txt main.cf # vim main.cf ... 9 #inet_interfaces = localhost //监听端口 22 myhostname = mail.it.net.cn //邮件服务器主机名 23 mydomain = it.net.cn //邮件服务器所在区域 24 myorigin = $mydomain //发件人DNS后缀 25 mydestination = $mydomain //指定Postfix允许处理的邮件 26 home_mailbox = Maildir/ //邮箱类型
# postfix check # service postfix start # chkconfig postfix on # netstat -tulnp | grep :25 //发信使用SMTP协议 tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 3564/master tcp 0 0 :::25 :::* LISTEN 3564/master
# useradd damao # echo 123456| passwd --stdin damao # useradd tom # echo 123456| passwd --stdin tom
# telnet mail.it.net.cn 25 Trying 192.168.100.1... Connected to mail.it.net.cn. Escape character is '^]'. 220 mail.it.net.cn ESMTP Postfix helo localhost //宣告客户端 250 mail.it.net.cn mail from:damao@it.net.cn //邮件发件人 250 2.1.0 Ok rcpt to:tom@it.net.cn //邮件收件人 250 2.1.5 Ok data //邮件正文 354 End data with <CR><LF>.<CR><LF> subject:Test mail //邮件主题 hello,tom //邮件内容 . //独立.表示邮件结束 250 2.0.0 Ok: queued as 9B6463FD97 quit //退出 221 2.0.0 Bye Connection closed by foreign host.
# ls /home/tom/Maildir/new/ 1398492202.V803Ibf420M185454.mail.it.net.cn # cat /home/tom/Maildir/new/1398492202.V803Ibf420M185454.mail.it.net.cn Return-Path: <damao@it.net.cn> X-Original-To: tom@it.net.cn Delivered-To: tom@it.net.cn Received: from localhost (unknown [192.168.100.1]) by mail.it.net.cn (Postfix) with SMTP id 9B6463FD97 for <tom@it.net.cn>; Fri, 25 Apr 2014 23:00:32 -0700 (PDT) subject:Test mail Message-Id: <20140426060137.9B6463FD97@mail.it.net.cn> Date: Fri, 25 Apr 2014 23:00:32 -0700 (PDT) From: damao@it.net.cn To: undisclosed-recipients:;
|