Linux总结笔记9-搭建Postfix邮件服务器

1.修改主机名和部署好DNS服务器

[root@linux1 ~]# hostname
mail.kangvcar.com

[root@linux1 ~]# cat /etc/named.conf    //修改/etc/named.conf文件
        listen-on port 53 { any; };
        allow-query     { any; };

[root@linux1 ~]# cat /etc/named.rfc1912.zones   //修改/etc/named.rfc1912.zones文件
zone "kangvcar.com" IN {
        type master;
        file "kangvcar.com.zone";
        allow-update { none;};
};

zone "100.168.192.arpa" IN {
        type master;
        file "192.168.100.arpa";
        allow-update { none;};
};

[root@linux1 ~]# cat /var/named/kangvcar.com.zone   //修改/var/named/kangvcar.com.zone 文件
$TTL 1D
@       IN SOA  kangvcar.com. root.kangvcar.com. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      ns.kangvcar.com.
ns      IN A    192.168.100.10
@       IN MX 10        mail.kangvcar.com.
mail    IN A    192.168.100.10

[root@linux1 ~]# cat /var/named/192.168.100.arpa    //修改/var/named/192.168.100.arpa 文件
$TTL 1D
@       IN SOA  kangvcar.com. root.kangvcar.com. (
                                        0       ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      ns.kangvcar.com.
ns      IN A    192.168.100.10

[root@linux1 ~]# nslookup       //验证
> mail.kangvcar.com
Server:         192.168.100.10
Address:        192.168.100.10#53

Name:   mail.kangvcar.com
Address: 192.168.100.10

2.安装 postfix 服务程序

[root@linux1 ~]# yum -y install postfix

3.修改postfix主配置文件

[root@linux1 ~]# vim /etc/postfix/main.cf
myhostname = mail.kangvcar.com      //设置服务器的主机名
mydomain = kangvcar.com     //设置服务器的域名
myorigin = $mydomain        //定义寄出邮件的域
inet_interfaces = all       //指定要由服务器的那些IP地址对外提供电子邮件服务
mydestination = $myhostname,$mydomain       //定义的可接收邮件的主机名或域名列表

[root@linux1 ~]# systemctl restart postfix
[root@linux1 ~]# systemctl enable postfix

4.安装dovecot 服务程序

[root@linux1 ~]# yum -y install dovecot

5.修改dovecot主配置文件

[root@linux1 ~]# vim /etc/dovecot/dovecot.conf
protocols = imap pop3 lmtp      //设置支持的电子邮件协议修改为imap、pop3和lmtp
disable_plaintext_auth = no     //允许客户的明文登陆行为
login_trusted_networks = 192.168.100.0/24   //设置允许登陆的网段地址,如果想允许所有人都能来使用,可以不用修改本条参数

6.修改dovecot子配置文件

[root@linux1 ~]# vim /etc/dovecot/conf.d/10-mail.conf
mail_location = mbox:~/mail:INBOX=/var/mail/%u      //定义要将收到的邮件信息保存到服务器本地的路径

7.创建邮件用户,并创建邮箱存放目录

[root@linux1 ~]# useradd user1
[root@linux1 ~]# su - user1
[user1@mail ~]$ mkdir -p mail/.imap/INBOX

8.启动dovecot服务程序

[root@linux1 ~]# systemctl restart dovecot
[root@linux1 ~]# systemctl enable dovecot

9.验证

[root@linux1 ~]# echo "this is for user1 mail" | mail -s "test mail" user1@kangvcar.com
[root@linux1 ~]# su - user1
[user1@mail ~]$ mail
Heirloom Mail version 12.5 7/5/10.  Type ? for help.
"/var/spool/mail/user1": 1 message 1 new
>N  1 root                  Thu Apr 13 02:27  18/589   "test mail"
& 1
Message  1:
From root@kangvcar.com  Thu Apr 13 02:27:55 2017
Return-Path: @kangvcar.com>
X-Original-To: user1@kangvcar.com
Delivered-To: user1@kangvcar.com
Date: Thu, 13 Apr 2017 02:27:54 +0800
To: user1@kangvcar.com
Subject: test mail
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: root@kangvcar.com (root)
Status: R

this is for user1 mail

& 

10.扩展–设置邮箱别名

[root@linux1 ~]# vim /etc/aliases
hkj:            user1       //加入一行别名设置,当发送给hkj@kangvcar.com这个邮箱时,实际上是发送给了user1用户的邮箱里
[root@linux1 ~]# newaliases     //让别名立刻生效

你可能感兴趣的:(Linux,Linux服务器配置,Linux,服务器搭建)