#################################

配置dns邮件服务

#################################

1.安装dns服务

yum install bind -y

2.配置dns服务

vim /etc/named.conf                     ###配置dns服务主配置文件

将11 17行注释 表示对外开放53端口并允许访问

邮件服务

vim /etc/named.rfc1912.zones  

添加westos.com mmm.com域名的指向配置

邮件服务

编写westos及mmm的域名解析文件

cp -p /var/named/named.localhost westos.com.zone 

cp -p /var/named/named.localhost mmm.com.zone

邮件服务

邮件服务

测试

邮件服务

邮件服务




##########################
postfix
##########################
1.概述
postfix提供smtp 协议用来投递邮件
默认端口25
/var/log/maillog    ###服务日志

mail [email protected]   ###发送邮件给westos.com
Subject: dsaf          
test
test
test

.                        ###"."表示结束录入并发送

mailq             ###查看邮件队列
postqueue -f      ###重新处理邮件队列


2.配置postfix
vim /etc/postfix/main.cf                        ###postfix服务主配置文件 
76 myhostname = westos.com     ###指定mta主机名称

邮件服务
83 mydomain = westos.com       ###指定mta域名

邮件服务
99 myorigin = $mydomain        ###指定邮件来源结尾

邮件服务
116 inet_interfaces = all      ###25端口开启的网络接口

邮件服务
164 mydestination = $myhostname, $mydomain, localhost  ###指定接受的邮件结尾

邮件服务
systemctl restart postfix.service
systemctl stop firewalld


测试

在westos.com端给mmm.com发邮件

邮件服务

在mmm.com端查看

邮件服务


3.邮件别名

在接受邮件的主机配置
vim /etc/aliasses   
别名:     真名
别名:    :include:filename              ###邮件群发
邮件服务
vim filename
root
student
邮件服务
postalias /etc/aliases       ###更新aliases文件


测试

在发送邮件端

邮件服务



在接收邮件端

邮件服务


4.通过远程主机发送邮件
[[email protected] kiosk]# telnet 172.25.254.216 25
Trying 172.25.254.216...
Connected to 172.25.254.216.
Escape character is '^]'.
220 westos.com ESMTP Postfix
mail from:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
1  
1
1
.
250 2.0.0 Ok: queued as 3D21817E866
邮件服务




5.邮件客户端的访问控制
在mta上
postconf -e "smtpd_client_restrictions = check_client_access hash:/etc/postfix/access"                   ###添加访问控制功能

邮件服务

邮件服务
vim /etc/postfix/access              ###添加拒绝访问名单
172.25.254.16 REJECT

邮件服务

postmap /etc/postfix/access                 ###刷新access

systemctl restart postfix.service          ###重启postfix服务

测试
[[email protected] kiosk]# telnet 172.25.254.216 25
Trying 172.25.254.216...
Connected to 172.25.254.216.
Escape character is '^]'.
220 westos.com ESMTP Postfix
mail from:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
554 5.7.1 <unknown[172.25.254.78]>: Client host rejected: Access denied

邮件服务



6.限制用户发送邮件
postconf -e "smtp_sender_restrictions = check_sender_access hash:/etc/postfix/sender"

邮件服务
vim /etc/postfix/sender
[email protected]    REJECT
邮件服务
postmap /etc/postfix/sender

systemctl restart postfix

测试

[[email protected] kiosk]# telnet 172.25.254.216 25
Trying 172.25.254.216...
Connected to 172.25.254.216.
Escape character is '^]'.
220 westos.com ESMTP Postfix
mail from:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
554 5.7.1 <[email protected]>: Sender address rejected: Access denied

邮件服务


7.限制用户接受邮件
postconf -e "smtpd_recipient_restritions = check_recipient_access hash:/etc/postfix/recip"

邮件服务

vim /etc/postfix/recip
[email protected]    REJECT
邮件服务
postmap /etc/postfix/recip
systemctl restart postfix

测试

[[email protected] kiosk]# telnet 172.25.254.216 25
Trying 172.25.254.216...
Connected to 172.25.254.216.
Escape character is '^]'.
220 westos.com ESMTP Postfix
mail from:[email protected]
250 2.1.0 Ok
rcpt to:[email protected]
554 5.7.1 <[email protected]>: Recipient address rejected: Access denied

邮件服务


8.出站地址伪装
postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"

邮件服务
vim /etc/postfix/generic
[email protected]    [email protected]
邮件服务
postmap /etc/postfix/generic
systemctl restart postfix

测试
su - westos
mail [email protected]

邮件服务

在mmm.com端查看邮件

邮件服务


9.入站地址转换

做world.com的dns解析

邮件服务
postconf -e "virtual_alias_maps = hash:/etc/postfix/virtual"

邮件服务

vim /etc/postfix/virtual
[email protected]    [email protected]
邮件服务
postmap /etc/postfix/virtual

测试
mail [email protected]

邮件服务


在westos.com端查看

mail -u studnet

邮件服务



####################################
#dovecot
####################################
1.
dovecot 用来提供收件协议
pop3   110
imap   143
pop3s  995
imaps  993
邮件服务
/etc/services   ###所有服务的所有端口

2.安装devecot服务
yum install dovecot y  
邮件服务
3.配置
vim /etc/dovecot/dovecot.conf
24 protocols = imap pop3 lmtp

邮件服务

48 login_trusted_networks = 0.0.0.0/0

49 disable_plaintext_auth = no

邮件服务
vim /etc/dovecot/conf.d/10-mail.conf
30 mail_location = mbox:~/mail:INBOX=/var/mail/%u
邮件服务
systemctl restart dovecot
mkdir /etc/skel/mail/.imap -p           ###在用户骨架文件中建立所需目录及文件
touch /etc/skel/mail/.imap/INBOX
邮件服务

测试
yum install mutt -y
mutt -f pop://[email protected]

邮件服务



#########################
postfix + mariadb
#########################
准备工作
yum install httpd php php-mysql mariadb-server -y
config mariadb
mysql_secure_installation

邮件服务
create databs

邮件服务
create table

邮件服务

邮件服务

邮件服务

邮件服务

1.
vim /etc/postfix/mailuser.cf  ##用户名称查询
host = localhost    ##数据库所在主机    
user = postuser        ##登陆数据库的用户
password = 123        ##登陆数据库的密码
dbname = email        ##postfix要查询的名称
table = emailuser    ##postfix要查询的表的名称
select_field = username    ##postfix要查询的字段
where_field = username    ##用户给定postfix的查询条件
邮件服务

vim /etc/postfix/maildomain.cf      ##用户域名查询
host = localhost
user = postuser
password = 123
dbname = email
table = emailuser
select_field = domain
where_field = domain

邮件服务

vim /etc/postfix/mailbox.cf     ##用户邮箱位置查询
host = localhost
user = postuser
password = 123
dbname = email
table = emailuser
select_field = maildir
where_field = username

邮件服务

postmap -q "[email protected]" mysql:/etc/postfix/mailuser.cf
[email protected]
postmap -q "mmm.com" mysql:/etc/postfix/maildomain.cf
mmm.com
postmap -q "[email protected]" mysql:/etc/postfix/mailbox.cf
/mnt/mmm.com/mmm
邮件服务
配置postfix
groupadd -g 666 vmail
useradd -s /sbin/nologin -u 666 -g 666 vmail

邮件服务

postconf -e "virtual_mailbox_base = /home/vmail"##设定虚拟账户的邮件目录
postconf -e "virtual_uid_maps = static:666"##虚拟账户建立文件的uid
postconf -e "virtual_gid_maps = static:666"##虚拟用户建立文件的gid
postconf -e "virtual_alias_maps = mysql:/etc/postfix/mailuser.cf"
postconf -e "virtual_mailbox_domains = mysql:/etc/postfix/maildomain.cf"
postconf -e "virtual_mailbox_maps = mysql:/etc/postfix/mailbox.cf"


邮件服务


测试

mail [email protected]

邮件服务

查看[email protected]的收件情况

邮件服务





##############################

dovecot+mysql

##############################

1. 安装dovecot及插件
yum install dovecot dovecot-mysql -y  

                      ##dovecot-mysql devocot的插件,让devocot可以识别mysql

邮件服务

2.配置
vim /etc/dovecot/dovecot.conf

24 protocols = imap pop3 lmtp     ##支持收件协议

邮件服务

48 login_trusted_networks = 0.0.0.0/0 ##信任网络

邮件服务

49 disable_plaintext_auth = no    ##开启明文认证

邮件服务


vim /etc/dovecot/conf.d/10-auth.conf
123 !include auth-sql.conf.ext     ##开启mysql的认证方式

邮件服务


##生成dovecot读取mysql的配置
cp /usr/share/doc/dovecot-2.2.10/example-config/dovecot-sql.conf.ext /etc/dovecot/dovecot-sql.conf.ext

邮件服务


vim /etc/dovecot/dovecot-sql.conf.ext
32 driver = mysql     ##数据库类型
71 connect = host=localhost dbname=email user=postuser password=123

##查询时用到的 库,表,用户及秘密

邮件服务

78 default_pass_scheme = PLAIN   ##默认认证方式为明文

邮件服务

107 password_query = \         ##查询密码匹配

108  SELECT username, domain, password \
109  FROM emailuser WHERE username = '%u' AND domain = '%d'


125 user_query = SELECT maildir, 666 AS uid, 666 AS gid FROM emailuser WHERE use    rname = '%u'


vim /etc/dovecot/conf.d/10-mail.conf
30 mail_location = maildir:/home/vmail/%d/%n    ##指定邮件位置
168 first_valid_uid = 666            ##邮件文件查询用户身份
175 first_valid_gid = 666

systemctl restart dovecot

测试
[[email protected] Desktop]# telnet 172.25.254.116 110
Trying 172.25.254.116...
Connected to 172.25.254.116.
Escape character is '^]'.
+OK [XCLIENT] Dovecot ready.
user [email protected]
+OK
pass 123

+OK Logged in.




相关文章: