利用postfix实现两台邮件服务器间的邮件收发实验
原创
©著作权归作者所有:来自51CTO博客作者smileliuyb的原创作品,请联系作者获取转载授权,否则将追究法律责任
1.配置服务器server1作为DNS服务器和网关服务器
1).配置服务器的hostname
hostname dns.server1
vim /etc/hosts
#============================================
127.0.0.1 dns.server1 localhost localhost.localdomain
#============================================
vim /etc/sysconfig/network
#============================================
HOSTNAME=dns.server1
#============================================
2).配置服务器的eth0和eth1的ip地址分别为127.16.1.254/16和192.168.1.254/24
3).将server1配置成为网关服务器
vim /etc/sysctl.conf //永久启用网卡转发功能
#=======================
net.ipv4.ip_forward = 1
#=======================
echo 1 > /proc/sys/net/ipv4/ip_forward //临时启用网卡转发
4).配置DNS服务器
yum install bind bind-*
#配置DNS服务的主配置文件
vim /var/named/chroot/etc/named.conf
#=======================
options{
directory "var/named";
};
zone "liuyb01.com." {
type master;
file "liuyb01.com.zone";
};
zone "liuyb02.com." {
type master;
file "liuyb02.com.zone;
};
#=======================
#配置liuyb01.com的区域文件
vim /var/named/chroot/var/named/liuyb01.com.zone
#==========================================
mail IN A 172.16.0.1
liuyb01.com IN MX 10 mail.liuyb01.com.
#==========================================
#配置liuyb02.com的区域文件
vim /var/named/chroot/var/named/liuyb02.com.zone
#==========================================
mail IN A 192.168.1.1
liuyb02.com IN MX 10 mail.liuyb02.com
#==========================================
#启动DNS服务
service named start
chkconfig named on
2.配置邮件服务器mail.liuyb01.com
1).配置服务器的hostname
hostname mail.liuyb01.com
vim /etc/hosts
#========================
127.0.0.1 mail.liuyb01.com localhost localhost.localdomain
#========================
vim /etc/sysconfig/network
#========================
HOSTNAME=mail.liuyb01.com
#========================
2).配置邮件服务器的IP地址
IP:172.16.0.1/10
GATEWAY:172.16.0.254
DNS:172.16.0.254
3).建立用户
useradd -s /sbin/nologin liuyb01
echo abc/123 | passwd --stdin liuyb01
4).停止sendmail服务
service sendmail stop
chkconfig sendmail off
5).安装postfix软件包并启动该服务
yum install postfix
service postfix start
chkconfig postfix on
6).配置postfix服务
vim /etc/postfix/main.cf
#===================
myhostname = mail.liuyb01.com //邮件服务器的QSDN
mydomain = liuyb01.com //邮件服务所在的域
myorigin = $mydomain //邮件服务器本机发送邮件是使用的发件人格式
inet_interfaces = all //邮件服务区监听的网络接口
mydestination = $myhostname,$mydomain //邮件服务器监听的发件人格式
mynetworks = 172.16.0.0/16,127.0.0.0/8 //邮件服务器监听的发件人IP地址
relay_domains = $mydestination,liuyb01.com //允许使用邮件服务器作为转发服务器的邮件服务器
#=====================
#重启postfix服务
service postfix restart
#测试postfix是否能够使用
telnet mail.liuyb01.com 25
mail from:root@mail.liuyb01.com
rcpt to:root@mail.liuyb01.com
data
subject:hello
hello!
.
quit
#=====================
You have mail in /var/spool/mail/root
#=====================
mail
7).配置cyrus软件包用于安全验证
rpm -qa | grep cyrus
cyrus-sasl-2.*
#配置安全验证方式为shadow并启动saslauthd服务
vim /etc/sysconfig/saslauthd
#=========================
SOCKETDIR=/var/run/saslauthd
MECH=shadow
FLAGS=
#=========================
/ect/init.d/saslauthd start
chkconfig saslauthd on
8).配置postfix服务使用sasl
vim /etc/postfix/main.cf
#===============================
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = ''
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
broken_sasl_auth_clients = yes
smtpd_client_restrictions = permit_sasl_authenticated
smtpd_sasl_security_options = noanonymous
#=================================
#测试验证服务是否可用
perl -MMIME::Base64 -e 'print encode_base64("liuyb01")'
bGl1eWIwMQ==
perl -MMIME::Base64 -e 'print encode_base64("abc/123")'
YWJjLzEyMw==
telnet mail.liuyb01.com 25
ehlo mail.liuyb01.com
auth login
334 VXNlcm5hbWU6
bGl1eWIwMQ==
334 UGFzc3dvcmQ6
YWJjLzEyMw==
235 2.0.0 Authentication successful
9).安装dovecot服务用于监听pop3端口
yum install dovecot
vim /etc/dovecot.conf
#==================
protocols = pop3 pop3s //dovecot监听的服务
protocol pop3 {
listen = *:10100 //dovecot监听的端口
}
#===================
service dovecot start
chkconfig dovecot on
10).安装cyrus-imapd软件包用于监听imap,并为邮件服务器提供后台服务
yum install cyrus-imapd cyrus-imapd-devel
#为cyrus用户增加密码用以邮件服务器后台管理
echo abc/123 | passwd --stdin cyrus
#使postfix服务使用cyrus-imapd模块
vim /etc/postfix/main.cf
#===================
mailbox_transport = lmtp:unix:/var/lib/imap/socket/lmtp
#===================
/etc/init.d/postfix restart
#启动cyrus服务
/etc/init.d/cyrus-imapd start
chkconfig cyrus-imapd on
#为用户建立邮箱
cyradm -u cyrus mail.liuyb01.com
mail.liuyb01.com> cm user.liuyb01 //为liuyb01建立用户邮箱
exit
11).邮件服务器配置完成,使用邮件客户端(MUA)测试邮件服务器是否可用
12).使用squirrelmail配置简单的webmail服务
yum install squirrelmail -y
/usr/share/squirrelmail/config/conf.pl //配置squirrelmail
service httpd start
#测试webmail客户端(http://mail.liuyb01.com/webmail)
3.同理配置第二台邮件服务器mail.liuyb02.com
4.测试邮件服务器间发送信件
![](https://ucenter.51cto.com/images/noavatar_middle.gif)
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章