Linux搭建邮件服务器
Linux搭建邮件服务器
环境信息
服务器:Centos 7.5
内网ip:192.168.0.166
1、修改主机名
vi /etc/hostname mail.test.com
2、安装DNS服务
yum -y install bind
3、修改配置文件
修改DNS主配置文件
vim /etc/named.conf options { listen-on port 53 { 192.168.0.166; }; 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"; recursing-file "/var/named/data/named.recursing"; secroots-file "/var/named/data/named.secroots"; allow-query { any; };
修改子配置文件添加如下信息
vi /etc/named.rfc1912.zones
zone "test.com" IN {
type master;
file "test.com.zone";
};
zone "0.16.172.in-addr.arpa" {
type master;
file "test.com.local";
};
4、进入DNS服务器区域配置文件目录,复制模板区域配置文件为指定区域配置文件。注:一定要保留源文件权限,如果未保留,须将属组改为named。
cd /var/named/ cp -p named.localhost test.com.zone cp -p named.localhost test.com.local
5、编辑正向区域配置文件,修改并添加以下行
vi test.com.zone
NS @
A 192.168.0.166
MX 10 mail.test.com
mail A 192.168.0.166
AAAA ::1
6、编辑反向区域配置文件,修改并添加以下行
vi test.com.local
NS @
A 192.168.0.166
MX 10 mail.test.com
3 PTR mail.test.com
AAAA ::1
7、重启DNS服务
systemctl restart named
8、安装nslookup命令测试dns能否解析成功
yum install -y bind-utils
9、给本机的DNS增加一个指向自己的dns服务器
vi /etc/resolv.conf
nameserver 192.168.0.166
10、解析邮件服务器地址,显示如下则表示成功
命令:nslookup mail.test.com
Server: 11.125.0.21
Address: 11.125.0.21#53
Non-authoritative answer:
Name: mail.test.com
Address: 69.167.164.199
安装postfix服务器并进行配置
1、安装postfix服务
yum -y install postfix
2、编译postfix配置文件,修改一些配置项
vi /etc/postfix/main.cf
myhostname = mail.test.com //本机主机名
mydomain = test.com //服务器域名
myorigin = $mydomain //初始域名
inet_interfaces = all //监听接口
inet_protocols = all //监听网络版本,可以不改
mydestination = $myhostname, $mydomain //目标域
home_mailbox = Maildir/ //邮件目录,在用户家目录下
3、检查配置文件是否有语法错误
postfix check
4、重启postfix服务
systemctl restart postfix
邮件服务器测试
1、添加邮件账号组
groupadd mailusers
2、添加测试邮箱账号
useradd -g mailusers -s /sbin/nologin jack passwd jack useradd -g mailusers -s /sbin/nologin tom passwd tom
3、添加域名解析
vi /etc/hosts
192.168.0.166 mail.test.com
4、测试远程25端口是否正常(如下表示正常)
telnet mail.test.com 25
Trying 192.168.0.166...
Connected to mail.test.com.
Escape character is '^]'.
220 mail.test.com ESMTP Postfix
5、输入以下内容用于测试
telnet mail.test.com 25 Trying 192.168.0.166... Connected to mail.test.com. Escape character is '^]'. 220 mail.test.com ESMTP Postfix helo mail.test.com 250 mail.test.com mail from:jack@test.com 250 2.1.0 Ok rcpt to:tom@test.com 250 2.1.5 Ok data 354 End data with <CR><LF>.<CR><LF> hellow tom . 250 2.0.0 Ok: queued as 36746405025 quit 221 2.0.0 Bye Connection closed by foreign host.
输入配置的详情
helo mail.aa.com //声明本机的主机名 mail from:jack@aa.com //声明发件人地址 rcpt to:tom@aa.com //声明收件人地址 data //写正文 i am jack!! . //以.结尾 quit // 退出
6、查看tom接收的邮件内容
cat /home/tom/Maildir/new/1586512307.Vfd01I101059M375553.mail.test.com