1.环境初始化
[[email protected] ~]# rpm -q centos-release //查看系统版本
centos-release-7-5.1804.el7.centos.x86_64
[[email protected] ~]# vi /etc/hostname //将主机名更改为邮件服务器域名mail.test.com
[[email protected] ~]# systemctl disable firewalld //禁止防火墙开机自启动
[[email protected] ~]# vi /etc/sysconfig/selinux //将未注释的SELINUX行的值改为disabled
[[email protected] ~]# vi /etc/fstab //编辑fstab配置文件,在最后一行添加如下:
/dev/cdrom /mnt iso9660 ro 0 0 //将vmware连接的光盘镜像开机自动以只读挂载到/mnt目录下
[[email protected] ~]# vi /etc/yum.repos.d/CentOS-Base.repo //编辑yum的配置文件,方便后续安装,配置内容如下,其他删除或注释:
[base]
name=CentOS-$releasever - Base
baseurl=file:///mnt
enabled=1
gpgcheck=0
////////////没看懂什么意思,为什么要这样做
[[email protected] ~]# reboot //重启让优化环境生效
2.搭建DNS环境域名解析,用于解析postfix地址
[[email protected] ~]# yum install -y bind //安装DNS服务器
[[email protected] ~]# vi /etc/named.conf //修改DNS主配置文件
listen-on port 53 { 192.168.49.129; };
allow-query { any; }; //修改这两行的内容
[[email protected] ~]# vi /etc/named.rfc1912.zones //修改子配置文件
zone “test.com” IN {
type master;
file "test.com.zone";
};
zone “49.168.192.in-addr.arpa” {
type master;
file "test.com.local";
}; //在最后添加一个正向和一个反向解析区域
[[email protected] ~]# cd /var/named/ //进入DNS服务器区域配置文件目录
[[email protected] named]# cp -p named.localhost test.com.zone
[[email protected] named]# cp -p named.localhost test.com.local //复制模板区域配置文件为指定区域配置文件。保留源文件权限,确定属组为named
[[email protected] named]# vi test.com.zone //编辑正向区域配置文件
$TTL 1D
@ IN SOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS @
A 192.168.49.129
mail A 192.168.49.129
MX 10 mail.test.com.
[[email protected] named]# vi test.com.local //编辑反向区域配置文件
$TTL 1D
@ IN SOA test.com. rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS mail.test.com.
A 192.168.49.129
MX 10 mail.test.com.
129 PTR mail.test.com.
[[email protected] named]# systemctl start named //启动DNS域名解析服务器
[[email protected] named]# yum install -y bind-utils //安装nslookup命令测试dns能否解析成功
[[email protected] named]# vi /etc/resolv.conf //给本机的DNS指向自己的dns服务器
nameserver 192.168.49.129
[[email protected] named]# nslookup mail.test.com //解析服务器地址 //正向解析
Server: 192.168.49.129
Address: 192.168.49.129#53
Name: mail.test.com
Address: 192.168.49.129
//反向解析
[[email protected] named]# nslookup 192.168.49.129
Server: 192.168.49.129
Address: 192.168.49.129#53
129.49.168.192.in-addr.arpa name = mail.test.com.
//成功
3.安装postfix服务器并进行配置
一般是默认自动安装postfix服务器的。
[[email protected] named]# rpm -q postfix //检查系统是否已经安装了postfix服务器
postfix-2.10.1-6.el7.x86_64
[[email protected] named]# postconf -a //检查postfix是否支持cyrus dovecot功能,如果不支持需重新安装更新的版本
[[email protected] named]# vi /etc/postfix/main.cf //编辑postfix的配置文件,查找并修改对应配置项
myhostname = mail.test.com //本机主机名
mydomain = test.com //服务器域名
myorigin = $mydomain //初始域名
inet_interfaces = 192.168.80.181, 127.0.0.1 //监听接口
inet_protocols = ipv4 //监听网络版本,可以不改
mydestination = myhostname,
mydomain //目标域
home_mailbox = Maildir/ //邮件目录,在用户家目录下
[[email protected] named]# postfix check //检查配置文件是否有语法错误
[[email protected] named]# systemctl start postfix //启动postfix服务器
//postconf -n该命令可查看postfix非默认配置
- 1
4.邮件服务器简单发信测试
[[email protected] named]# groupadd mailusers //添加邮件账号组
[[email protected] named]# useradd -g mailusers -s /sbin/nologin jack //用户jack不允许登录(通过mailusers可以连接)
[[email protected] named]# passwd jack
[[email protected] named]# useradd -g mailusers -s /sbin/nologin tom
[[email protected] named]# passwd tom //添加jack、tom邮件服务测试账号
[[email protected] named]# yum install -y telnet //安装远程登录插件,用于登录25端口测试
[[email protected] named]# telnet mail.test.com 25 //远程登录25端口,如报错连接不上,重启postfix
输入如下命令测试:
[[email protected] named]# ls /home/tom/Maildir/new/ //查看tom接收的邮件目录下的邮件
这个只能超级管理员查看邮件
原文地址:https://www.cnblogs.com/duanlinxiao/p/10945202.html