标签:pre 转发 服务 local 电子邮件 centos7 cache esc smt
一、筑基期之邮件服务简介邮件服务通过以下几个协议来实现
简单邮件传输协议(SMTP),用来发送或中转发出的电子邮件,占用tcp 25端口。
邮局协议 第三版(POP3),用于把服务器上的邮件存储到本地主机,占用tcp 110端口。
互联网信息访问协议 第四版(IMAP4),用于在本地主机上访问邮件,占用tcp 143端口。
了解了三种协议,现在再来看看邮件服务的基本概念
邮件传输:MT 邮件传输代理:MTA
邮件投递:MD 邮件投递代理:MDA
邮件用户:MU 邮件用户代理:MUA
在一台邮件服务器上,用户要写一封邮件,是通过MUA(邮件用户代理)来写邮件的;写好邮件后将邮件提交本地SMTPD服务(MTA);SMTPD服务对邮件进行分类,本地的邮件直接通过lmtp(本地邮件传输协议)放在本地;需要远程发送的邮件通过smtp客户端发送远程SMTP主机的服务端;远程SMTPD将邮件通过MDA发送到本地邮局,接收方通过MUA将邮件接收到自己的家目录
实现SMTP协议使用postfix,实现pop3和imap4协议使用dovecot,同时部署用于实现域名解析的bind服务器
关闭防火墙
systemctl stop firewalld.service
模拟内网环境:使用系统光盘作yum源
mkdir /media/cdrom
mount /dev/cdrom /media/cdrom
yum-config-manager --enable c7-media
yum -y install bind bind-libs bind-libs-lite bind-license bind-utils
备份配置文件:cp /etc/named.conf{,.bak}
修改全局配置中的监听地址,加上本机可与外网通信的地址
options {
listen-on port 53 { any; };
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";
allow-query { any; };
recursion yes;
dnssec-enable yes;
dnssec-validation yes;
};
添加正反向区域(根据实际情况配置)
vim /etc/named.rfc1912.zones
zone "zhongdianjizhi.com" IN {
type master;
file "zhongdianjizhi.com.zone";
allow-update { none; };
};
zone "118.168.192.in-addr.arpa" {
type master;
file "zhongdianjizhi.com.local";
allow-update { none; };
};
定义区域解析库文件(配置A记录与MX记录)
cd /var/named
cp -p named.localhost zhongdianjizhi.com.zone
cp -p named.localhost zhongdianjizhi.com.local
zhongdianjizhi.com.zone
$TTL 1D
@ IN SOA @ zhongdianjizhi.com. (
201901 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 192.168.118.150
MX 10 mail.zhongdianjizhi.com.
mail A 192.168.118.150
mail AAAA fe80::3f32:be25:88e8:79b1
zhongdianjizhi.com.local
$TTL 1D
@ IN SOA @ zhongdianjizhi.com. (
201901 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 192.168.118.150
MX 10 mail.zhongdianjizhi.com.
150 PTR mail.zhongdianjizhi.com.
AAAA fe80::3f32:be25:88e8:79b1
named-checkzone "zhongdianjizhi.com.zone" /var/named/zhongdianjizhi.com.zone
named-checkzone "118.168.192.in-addr.arpa" /var/named/zhongdianjizhi.com.local
hostnamectl set-hostname mail.zhongdianjizhi.com
将本机dns解析指向本机dns服务器
vim /etc/resolv.conf
nameserver 192.168.118.150
systemctl start named
systemctl enable named
dig -t A mail.zhongdianjizhi.com @192.168.118.150
dig -x 192.168.143.130 @192.168.118.150
在centos7系统中postfix已经安装,版本为2.10.1
备份
cp /etc/postfix/main.cf{,.bak}
配置文件main.cf
#第76行 修改邮局主机名
myhostname = mail.zhongdianjizhi.com
#第83行 修改邮局域名
mydomain = zhongdianjizhi.com
#第99行 修改寄出邮件域名
myorigin = $mydomain
#第114行 修改监听所有网卡
inet_interfaces = all
#第119行 开启同时使用ipv4和ipv6协议
inet_protocols = all
#第164行 修改可接收邮件的主机名和域名
mydestination = $myhostname, $mydomain
mynetworks = 192.168.118.0/24, 127.0.0.0/8
home_mailbox = Maildir/
vim /etc/hosts
192.168.118.150 mail@zhongdianjizhi.com
systemctl start postfix
systemctl enable postfix
alternatives --display mta
useradd jym
echo ‘123456‘ |passwd --stdin jym
useradd boss
echo ‘123456‘ |passwd --stdin boss
[root@mail ~]# telnet mail.zhongdianjizhi.com 25
Trying 192.168.118.150...
Connected to mail.zhongdianjizhi.com.
Escape character is ‘^]‘.
220 mail.zhongdianjizhi.com ESMTP Postfix
mail from:boss@zhongdianjizhi.com
250 2.1.0 Ok
rcpt to:jym@zhongdianjizhi.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
this is test mail.
.
250 2.0.0 Ok: queued as 43A6B2033E0D
quit
221 2.0.0 Bye
Connection closed by foreign host.
yum install dovecot
备份
cp /etc/dovecot/dovecot.conf{,.bak}
配置dovecot.conf
sed -i ‘24s/^#//g‘ /etc/dovecot/dovecot.conf
sed -i ‘48s/#login_trusted_networks =/login_trusted_networks = 192.168.118.150\/24/g‘
修改子配置文件10-mail.conf
sed -i ‘24s/^#//g‘ /etc/dovecot/conf.d/10-mail.conf
systemctl start dovecot
systemctl enable dovecot
[root@mail named]# telnet mail.zhongdianjizhi.com 110
Trying 192.168.118.150...
Connected to mail.zhongdianjizhi.com.
Escape character is ‘^]‘.
+OK [XCLIENT] Dovecot ready.
user jym
+OK
pass 123456
+OK Logged in.
list
+OK 6 messages:
1 559
2 559
3 559
4 2564
5 2564
6 469
.
retr 6
+OK 469 octets
Return-Path: <boss@zhongdianjizhi.com>
X-Original-To: jym@zhongdianjizhi.com
Delivered-To: jym@zhongdianjizhi.com
Received: from unknown (unknown [192.168.118.150])
by mail.zhongdianjizhi.com (Postfix) with SMTP id 86CAC2033DFF
for <jym@zhongdianjizhi.com>; Sun, 30 Jun 2019 10:20:50 -0400 (EDT)
Message-Id: <20190630142105.86CAC2033DFF@mail.zhongdianjizhi.com>
Date: Sun, 30 Jun 2019 10:20:50 -0400 (EDT)
From: boss@zhongdianjizhi.com
this is test mail.
.
本次部署的邮件服务适用于内部网络,邮件服务用于消息通知,发件与收件由脚本完成,用于连接互联网的邮件服务建议配置webmail来收发件,win平台使用LDAP来管理用户认证,linux平台使用LAMP来管理用户认证,同时务必关闭开放式中继。
https://blog.51cto.com/12227558/2074095
https://blog.51cto.com/13728740/2141927
标签:pre 转发 服务 local 电子邮件 centos7 cache esc smt
原文地址:https://blog.51cto.com/jiayimeng/2415535