邮件服务器4—域间收发

news/2024/7/21 14:37:32 标签: 服务器, linux, vim

DNS服务器–域间邮件收发

文章目录

    • 实验环境
    • 对A主机进行配置
      • 一、创建两台DNS服务器
        • (b)修改named.baidu.com文件
        • (c)修改named.qq.com文件
        • (d)启动服务:
      • 二、添加baidu域
        • 1、修改dovecot服务
        • 2、修改10-mail.conf 配置文件
        • 3、配置sasl服务
      • 三、启动网卡并检查
        • 网络配置(添加IP并启动)
      • 四、查看服务器
      • 五、启动服务
      • 六、关闭防火墙
      • 七、修改权限
      • 测试
    • 对B主机进行配置
      • 一、进入B主机, 将A主机的 main.cf 文件拷贝到 B 主机/etc/postifix/ 目录下
      • 二、对拷贝过来的main.cf文件进行修改
        • 1、修改dovecot服务
        • 2、修改10-mail.conf 配置文件
        • 3、配置sasl服务
      • 三、配置并启动网卡
      • 四、启动服务
      • 五、关闭防火墙
      • 六、修改权限
      • 测试
    • 综合测试
      • 一、one用户发送给king用户
      • 二、king用户发送给one用户

实验环境

两台Redhat虚拟机

系统版本

[root@wang named]# cat /etc/redhat-release 
Red Hat Enterprise Linux release 8.2 (Ootpa)

需要安装的包

dnf install cyrus-sasl dovecot *sasl* -y
dnf install postfix dovecot -y
dnf install postfix mailx -y
dnf install *sasl* -y

对A主机进行配置

一、创建两台DNS服务器

(a)添加配置

vim /etc/named.conf
options {
        listen-on port 53 { 192.168.9.129; };
        directory       "/var/named";      
};


zone "baidu.com" IN {
        type master;
        file "named.baidu.com";
};


zone "qq.com" IN {
        type master;
        file "named.qq.com";
};

(b)修改named.baidu.com文件

vim /var/named/named.baidu.com
$TTL    1D
@       IN      SOA     @       admin.baidu.com. (
                                                        0
                                                        5
                                                        3
                                                        10
                                                        15 )
                IN              NS              ns.baidu.com.
                IN              MX              10              mail.baidu.com.
ns              IN              A               192.168.9.129
mail            IN              A               192.168.9.129

©修改named.qq.com文件

vim /var/named/named.qq.com
$TTL    1D
@       IN      SOA     @       admin.qq.com. (
                                                        0
                                                        5
                                                        3
                                                        10
                                                        15 )
                IN              NS              ns.qq.com.
                IN              MX              10              mail.qq.com.
ns              IN              A               192.168.9.129
mail            IN              A               192.168.9.135

PS:小技巧

:%s/baidu/qq/g

作用:在vim编辑器种 将baidu 替换成 qq

(d)启动服务:

systemctl restart named

二、添加baidu域

1、修改dovecot服务

进入文件:

vim /etc/dovecot/dovecot.conf

修改内容:

#将第24行修改为下行所示 
protocols = imap pop3 lmtp

#将下行写入第49行 
login_trusted_networks = 192.168.9.0/24

2、修改10-mail.conf 配置文件

进入文件:

vim /etc/dovecot/conf.d/10-mail.conf

修改内容:

#在第30写入下列内容,或者将第25行修改成下行所示 
mail_location = mbox:~/mail:INBOX=/var/mail/%u

修改权限:

chmod 0600 /var/mail/*

3、配置sasl服务

vim /etc/postfix/main.cf

需要修改的内容:

————————————————————————————————————————————————第一处——————————————————————————————————————————————————
 89 # The myhostname parameter specifies the internet hostname of this
 90 # mail system. The default is to use the fully-qualified domain name
 91 # from gethostname(). $myhostname is used as a default value for many
 92 # other configuration parameters.
 93 
 94 myhostname = mail.baidu.com
 
————————————————————————————————————————————————第二处——————————————————————————————————————————————————
 97 # The mydomain parameter specifies the local internet domain name.
 98 # The default is to use $myhostname minus the first component.
 99 # $mydomain is used as a default value for many other configuration
100 # parameters.
101 
102 mydomain = baidu.com

————————————————————————————————————————————————第三处——————————————————————————————————————————————————
113 # For the sake of consistency between sender and recipient addresses,
114 # myorigin also specifies the default domain name that is appended
115 # to recipient addresses that have no @domain part.
116 #
117 #myorigin = $myhostname
118 myorigin = $mydomain

————————————————————————————————————————————————第四处——————————————————————————————————————————————————
132 inet_interfaces = all
133 #inet_interfaces = $myhostname
134 #inet_interfaces = $myhostname, localhost
135 #inet_interfaces = localhost

————————————————————————————————————————————————第五处——————————————————————————————————————————————————
137 # Enable IPv4, and IPv6 if supported
138 inet_protocols = all

————————————————————————————————————————————————第六处——————————————————————————————————————————————————
183 #mydestination = $myhostname, localhost.$mydomain, localhost
184 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
185 #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
186 #       mail.$mydomain, www.$mydomain, ftp.$mydomain

————————————————————————————————————————————————第七处——————————————————————————————————————————————————
 # You can also specify the absolute pathname of a pattern file instead
281 # of listing the patterns here. Specify type:table for table-based lookups
282 # (the value on the table right-hand side is not used).
283 #
284 mynetworks = 192.168.9.0/24, 127.0.0.0/8
285 #mynetworks = $config_directory/mynetworks
286 #mynetworks = hash:/etc/postfix/network_table

————————————————————————————————————————————————第八处——————————————————————————————————————————————————
12 # NOTE: Postfix will not automatically forward mail for domains that
313 # list this system as their primary or backup MX host. See the
314 # permit_mx_backup restriction description in postconf(5).
315 #
316 relay_domains = $mydestination

————————————————————————————————————————————————第九处——————————————————————————————————————————————————
#最后面
737 smtp_tls_security_level = may
738 meta_directory = /etc/postfix
739 shlib_directory = /usr/lib64/postfix
740 
742 broken_sasl_auth_clients = yes
743 smtpd_sasl_auth_enable = yes
744 smtpd_sasl_security_options = noanonymous
745 smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination

三、启动网卡并检查

网络配置(添加IP并启动)

nmcli connection modify ens160 ipv4.dns 192.168.9.129
nmcli connection modify ens160 ipv4.method manual 
nmcli connection up ens160 

注意:nmcli connection modify ens160 ipv4.method manual 该命令作用是修改为手动配置

四、查看服务器

nmcli device show | grep DNS

五、启动服务

systemctl restart postfix
systemctl restart dovecot
systemctl restart saslauthd

六、关闭防火墙

systemctl stop firewalld

七、修改权限

setenforce 0

测试

dig -t mail.qq.com
dig -t mail.baidu.com

对B主机进行配置

一、进入B主机, 将A主机的 main.cf 文件拷贝到 B 主机/etc/postifix/ 目录下

scp root@192.168.9.129:/etc/postfix/main.cf /etc/postifix/

注意:

192.168.9.129是baidu域主机的IP地址

192.168.9.135是qq 域的主机的IP地址

二、对拷贝过来的main.cf文件进行修改

1、修改dovecot服务

进入文件:

vim /etc/dovecot/dovecot.conf

修改内容:

#将第24行修改为下行所示 
protocols = imap pop3 lmtp

#将下行写入第49行 
login_trusted_networks = 192.168.9.0/24

2、修改10-mail.conf 配置文件

进入文件:

vim /etc/dovecot/conf.d/10-mail.conf

修改内容:

#在第30写入下列内容,或者将第25行修改成下行所示 
mail_location = mbox:~/mail:INBOX=/var/mail/%u

修改权限:

chmod 0600 /var/mail/*

3、配置sasl服务

vim /etc/postfix/main.cf
————————————————————————————————————————————————第一处——————————————————————————————————————————————————
89 # The myhostname parameter specifies the internet hostname of this
 90 # mail system. The default is to use the fully-qualified domain name
 91 # from gethostname(). $myhostname is used as a default value for many
 92 # other configuration parameters.
 93 
 94 myhostname = mail.qq.com
 
————————————————————————————————————————————————第二处—————————————————————————————————————————————————
 97 # The mydomain parameter specifies the local internet domain name.
 98 # The default is to use $myhostname minus the first component.
 99 # $mydomain is used as a default value for many other configuration
100 # parameters.
101 
102 mydomain = qq.com

————————————————————————————————————————————————第三处——————————————————————————————————————————————————
113 # For the sake of consistency between sender and recipient addresses,
114 # myorigin also specifies the default domain name that is appended
115 # to recipient addresses that have no @domain part.
116 #
117 #myorigin = $myhostname
118 myorigin = $mydomain

————————————————————————————————————————————————第四处——————————————————————————————————————————————————
132 inet_interfaces = all
133 #inet_interfaces = $myhostname
134 #inet_interfaces = $myhostname, localhost
135 #inet_interfaces = localhost


————————————————————————————————————————————————第五处——————————————————————————————————————————————————
137 # Enable IPv4, and IPv6 if supported
138 inet_protocols = all

————————————————————————————————————————————————第六处——————————————————————————————————————————————————
183 #mydestination = $myhostname, localhost.$mydomain, localhost
184 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
185 #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
186 #       mail.$mydomain, www.$mydomain, ftp.$mydomain

————————————————————————————————————————————————第七处——————————————————————————————————————————————————
280# You can also specify the absolute pathname of a pattern file instead
281 # of listing the patterns here. Specify type:table for table-based lookups
282 # (the value on the table right-hand side is not used).
283 #
284 mynetworks = 192.168.9.0/24, 127.0.0.0/8
285 #mynetworks = $config_directory/mynetworks
286 #mynetworks = hash:/etc/postfix/network_table

————————————————————————————————————————————————第八处——————————————————————————————————————————————————
12 # NOTE: Postfix will not automatically forward mail for domains that
313 # list this system as their primary or backup MX host. See the
314 # permit_mx_backup restriction description in postconf(5).
315 #
316 relay_domains = $mydestination

————————————————————————————————————————————————第九处——————————————————————————————————————————————————
#最后面
737 smtp_tls_security_level = may
738 meta_directory = /etc/postfix
739 shlib_directory = /usr/lib64/postfix
740 
742 broken_sasl_auth_clients = yes
743 smtpd_sasl_auth_enable = yes
744 smtpd_sasl_security_options = noanonymous
745 smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination

三、配置并启动网卡

nmcli connection modify ens160 ipv4.addresses 192.168.9.135/24
nmcli connection modify ens160 ipv4.method manual 
nmcli connection modify ens160 connection.autoconnect yes
nmcli connection modify ens160 ipv4.dns 192.168.9.129
nmcli connection up ens160 

四、启动服务

systemctl restart postfix
systemctl restart dovecot
systemctl restart saslauthd

五、关闭防火墙

systemctl stop firewalld

六、修改权限

setenforce 0

测试

dig -t A mail.qq.com
dig -t A mail.baidu.com

综合测试

使用foxmail添加不同域之间的用户 相互发送信息

注意:

king是baidu域的用户
one 是qq域的用户

一、one用户发送给king用户

在这里插入图片描述

在这里插入图片描述

二、king用户发送给one用户

在这里插入图片描述


http://www.niftyadmin.cn/n/1019847.html

相关文章

postgresql远程不能访问 - PostgreSQL9.4.5

postgresql默认情况下,远程访问不能成功,如果需要允许远程访问,需要修改两个配置文件,说明如下: 1.postgresql.conf 将该文件中的listen_addresses项值设定为“*”,在9.4.5 Linux版中,该文件位置…

【Matlab肌电信号】脉搏信号处理系统【含GUI源码 1062期】

一、代码运行视频(哔哩哔哩) 【Matlab肌电信号】脉搏信号处理系统【含GUI源码 1062期】 二、matlab版本及参考文献 1 matlab版本 2014a 2 参考文献 [1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版…

邮件服务器5—邮件加密收发

邮件加密收发实验 文章目录邮件加密收发实验系统版本需要安装的包一、创建密钥对二、编辑主配置文件三、编辑功能配置文件四、重启服务五、测试系统版本 [rootwang named]# cat /etc/redhat-release Red Hat Enterprise Linux release 8.2 (Ootpa)需要安装的包 dnf install …

mysql 数据迁移 索引_mysql数据存储索引迁移小记_mysql

mysql数据存储目录迁移小记背景:因刚开始安装mysql的时候没有考虑后期磁盘分区空间问题,所以mysql的数据保存目录就按安装默认的目录/usr/local/mysql/(我下载的是一个lamp一键安装包安装的mysql),现在随着服务的运行发现/usr/local/mysql所在分区空间使…

【Matlab肌电信号】脉搏信号分析(去噪+特征提取)【含GUI源码 862期】

一、代码运行视频(哔哩哔哩) 【Matlab肌电信号】脉搏信号分析(去噪特征提取)【含GUI源码 862期】 二、matlab版本及参考文献 1 matlab版本 2014a 2 参考文献 [1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电…

邮件服务器6—虚拟别名域

虚拟别名域 文章目录虚拟别名域系统版本需要安装的包一、在两个域的主配置文件中添加如下内容二、在虚拟别名域中添加别名三、重新生成虚拟别名域数据库四、重新加载虚拟别名域数据文件五、在foxmail软件上测试king用户给456work.com的所有人发生邮件one用户给 123work.com的所…

【Matlab肌电信号】肌电信号处理【含GUI源码 966期】

一、代码运行视频(哔哩哔哩) 【Matlab肌电信号】肌电信号处理【含GUI源码 966期】 二、matlab版本及参考文献 1 matlab版本 2014a 2 参考文献 [1] 包子阳,余继周,杨杉.智能优化算法及其MATLAB实例(第2版)[M].电子工业出版社&a…

ubuntu装了mysqldb就不mysql就能用了_解决Ubuntu18.04安装flask-mysqldb中mysql_config not found问题...

解决Ubuntu18.04安装flask-mysqldb中mysql_config not found问题本人环境:Ubuntu18.04 mysql8.0python3.6问题描述:在学习flask框架的时候需要调用flask-mysqldb,本来轻轻安装一下就完成的事,在我这里折磨了我一天,好不容易才脱坑…