Linux postfix配置方法


第七題 配置郵件服務器

postfix學習網站:https://blog.csdn.net/mycms5/article/details/78773308 

system1和systemc2分別執行

[root@system2 ~]# postconf -e inet_interfaces=loopback-only
[root@system2 ~]# postconf -e mydestindation=
[root@system2 ~]# postconf -e local_transport=error:err
[root@system2 ~]# postconf -e relayhost=[mail.group8.example.com]
[root@system2 ~]# postconf -e myorigin=server.group8.example.com
[root@system2 ~]# systemctl enable postfix
[root@system2 ~]# systemctl restart postfix
[root@system2 ~]# echo "hello" | mail -s testmail dave

參數解釋:

relayhost 設定中心郵件服務器
  收到的郵件全部轉交給配置的服務器
inet_interfaces只在本地環回接口接受郵件
  loopback-only表示只接受本地郵件,只在127.0.0.1監聽25號端口deli
myorigin 設定發信人的域
  假設發信人為lily,那么會將信件的發信人改為lily@server.group8.example.com
  如果配置選項為188.com,那么發信人lily就會被改為lily@188.com
mydestindation 將接收到的任何郵件都當做外部郵件,這樣郵件才會轉發的到中心郵件服務器
  收到的所有信件,不管收信人是誰,都不會保存。
  可以理解為收到的所有的郵件都要轉出去。
local_transport
  當配置local_transport=error: local delivery disabled時,表示禁止本地分發郵件到本地用戶郵箱
mynetworks 信任的網絡
  只接受配置選項中網絡的郵件

驗證:

[root@system1 postfix]# curl http://server.group8.example.com/pub/received_mail/8
From root@server.group8.example.com Wed Apr 10 19:18:39 2019
Return-Path: <root@server.group8.example.com>
X-Original-To: dave@server.group8.example.com
Delivered-To: dave@server.group8.example.com
Received: from system1.group8.example.com (system1.group8.example.com [172.24.8.11])
by server.group8.example.com (Postfix) with ESMTP id B5F0E3089EFD
for <dave@server.group8.example.com>; Wed, 10 Apr 2019 19:18:39 +0800 (CST)
Received: by system1.group8.example.com (Postfix, from userid 0)
id 9B87C22E33F0; Wed, 10 Apr 2019 19:18:39 +0800 (CST)
Date: Wed, 10 Apr 2019 19:18:39 +0800
To: dave@server.group8.example.com
Subject: testmail
User-Agent: Heirloom mailx 12.5 7/5/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-Id: <20190410111839.9B87C22E33F0@system1.group8.example.com>
From: root@server.group8.example.com (root)

hello

緊急情況補救措施:
打開配置文件,搜索配錯了的某一項,然后將該項進行刪除,重新配置即可
vim /etc/postfix/main.cf
至此,考試內容結束

 

 

實驗:配置只發郵件服務器

首先在兩台機器上分別執行實驗腳本

[root@server0 ~]# lab smtp-auth setup 
[root@desktop0 ~]# lab smpt-auth setup


Server0:

[root@server0 ~]# postconf -e "relayhost=[smtp0.example.com]:587" 
[root@server0 ~]# postconf -e "inet_interfaces=loopback-only"
[root@server0 ~]# postconf -e "mynetworks=127.0.0.0/8 [::1]/128"
[root@server0 ~]# postconf -e "myorigin=desktop0.example.com"
[root@server0 ~]# postconf -e "mydestination="
[root@server0 ~]# postconf -e "local_transport=error: local delivery disabled"

從下開始與普通郵件不同

[root@server0 ~]# postconf -e "smtp_use_tls=yes" 
將用戶名和密碼以tls的形式加密
[root@server0 ~]# postconf -e "smtp_tls_loglevel=1"
日志級別
[root@server0 ~]# postconf -e "smtp_tls_security_level=encrypt"
信息加密
[root@server0 ~]# postconf -e "smtp_sasl_auth_enable=yes"
啟用smtp發送驗證
[root@server0 ~]# postconf -e "smtp_sasl_security_options=noanonymous"
禁止匿名
[root@server0 ~]# postconf -e "smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd"
用戶密碼所在文件


Server0配置

解釋:只要是將郵件轉給smtp0.example.com的587端口的,我們就用student:student

[root@server0 ~]# vim /etc/postfix/sasl_passwd 
smtp0.example.com:587 student:student

修改密碼文件權限為0600

[root@server0 ~]# chmod 0600 /etc/postfix/sasl_passwd

修改文件格式

[root@server0 ~]# postmap /etc/postfix/sasl_passwd

其實真正使用的文件為/etc/postfix/sasl_passwd.db這個文件來驗證也就是修改格式后的文件


重載服務

[root@server0 ~]# systemctl reload postfix

發送郵件

[root@server0 ~]# mail -s "server0 sasl tls" student@desktop0.example.com
sasl tls test.      這一行寫郵件內容
.    用.來結束郵件內容
EOT

收信

[root@server0 student]# su student
[student@server0 ~]$ mutt -f imaps://imap0.example.com

驗證:

Server0:

[root@server0 student]# lab-smtp-auth grade
Checking for Postfix configuration... PASS
Checking for Postfix TLS and SASL configuration... PASS
Desktop0:

[root@desktop0 ~]# lab smtp-auth grade
Checking E-mail is present in student inbox... PASS

至此,實驗結束

 

如果有什么建議或者意見,請直接在評論區留言或者私信本人,看到了第一時間回復。

本人Linux菜鳥,歡迎各位Linux大神指導。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM