DNS服务器–域间邮件收发
文章目录
- DNS服务器--域间邮件收发
- 实验环境
- 对A主机进行配置
- 对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域的用户