人妖在线一区,国产日韩欧美一区二区综合在线,国产啪精品视频网站免费,欧美内射深插日本少妇

新聞動(dòng)態(tài)

如何在CentOS8上安裝和配置Postfix郵件服務(wù)器的方法示例

發(fā)布日期:2022-02-20 10:11 | 文章來(lái)源:CSDN

Postfix 是一個(gè)自由開源的 MTA(郵件傳輸代理),用于在 Linux 系統(tǒng)上路由或傳遞電子郵件。在本指南中,你將學(xué)習(xí)如何在 CentOS 8 上安裝和配置 Postfix。

實(shí)驗(yàn)室設(shè)置:

  • 系統(tǒng):CentOS 8 服務(wù)器
  • IP 地址:192.168.1.13
  • 主機(jī)名:server1.crazytechgeek.info(確保域名指向服務(wù)器的 IP)

步驟 1)更新系統(tǒng)

第一步是確保系統(tǒng)軟件包是最新的。為此,請(qǐng)按如下所示更新系統(tǒng):

# dnf update

繼續(xù)之前,還請(qǐng)確保不存在其他 MTA(如 Sendmail),因?yàn)檫@將導(dǎo)致與 Postfix 配置沖突。例如,要?jiǎng)h除 Sendmail,請(qǐng)運(yùn)行以下命令:

# dnf remove sendmail

步驟 2)設(shè)置主機(jī)名并更新 /etc/hosts

使用下面的 hostnamectl 命令在系統(tǒng)上設(shè)置主機(jī)名:

# hostnamectl set-hostname server1.crazytechgeek.info
# exec bash

此外,你需要在 /etc/hosts 中添加系統(tǒng)的主機(jī)名和 IP:

# vim /etc/hosts
192.168.1.13  server1.crazytechgeek.info

保存并退出文件。

步驟 3)安裝 Postfix 郵件服務(wù)器

驗(yàn)證系統(tǒng)上沒(méi)有其他 MTA 在運(yùn)行后,運(yùn)行以下命令安裝 Postfix:

# dnf install postfix

Install-Postfix-Centos8

步驟 4)啟動(dòng)并啟用 Postfix 服務(wù)

成功安裝 Postfix 后,運(yùn)行以下命令啟動(dòng)并啟用 Postfix 服務(wù):

# systemctl start postfix
# systemctl enable postfix

要檢查 Postfix 狀態(tài),請(qǐng)運(yùn)行以下 systemctl 命令:

# systemctl status postfix

Start-Postfix-check-status-centos8

太好了,我們已經(jīng)驗(yàn)證了 Postfix 已啟動(dòng)并正在運(yùn)行。接下來(lái),我們將配置 Postfix 從本地發(fā)送郵件到我們的服務(wù)器。

步驟 5)安裝 mailx 郵件客戶端

在配置 Postfix 服務(wù)器之前,我們需要安裝 mailx,要安裝它,請(qǐng)運(yùn)行以下命令:

# dnf install mailx

Install-Mailx-CentOS8

步驟 6)配置 Postfix 郵件服務(wù)器

Postfix 的配置文件位于 /etc/postfix/main.cf 中。我們需要對(duì)配置文件進(jìn)行一些修改,因此請(qǐng)使用你喜歡的文本編輯器將其打開:

# vi /etc/postfix/main.cf

更改以下幾行:

myhostname = server1.crazytechgeek.info
mydomain = crazytechgeek.info
myorigin = $mydomain
## 取消注釋并將 inet_interfaces 設(shè)置為 all##
inet_interfaces = all
## 更改為 all ##
inet_protocols = all
## 注釋 ##
#mydestination = $myhostname, localhost.$mydomain, localhost
## 取消注釋 ##
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
## 取消注釋并添加 IP 范圍 ##
mynetworks = 192.168.1.0/24, 127.0.0.0/8
## 取消注釋 ##
home_mailbox = Maildir/

完成后,保存并退出配置文件。重新啟動(dòng) postfix 服務(wù)以使更改生效:

# systemctl restart postfix

步驟 7)測(cè)試 Postfix 郵件服務(wù)器

測(cè)試我們的配置是否有效,首先,創(chuàng)建一個(gè)測(cè)試用戶。

# useradd postfixuser
# passwd postfixuser

接下來(lái),運(yùn)行以下命令,從本地用戶 pkumar 發(fā)送郵件到另一個(gè)用戶 postfixuser。

# telnet localhost smtp
或者
# telnet localhost 25

如果未安裝 telnet 服務(wù),那么可以使用以下命令進(jìn)行安裝:

# dnf install telnet -y

如前所述運(yùn)行命令時(shí),應(yīng)獲得如下輸出:

[root@linuxtechi ~]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 server1.crazytechgeek.info ESMTP Postfix

上面的結(jié)果確認(rèn)與 postfix 郵件服務(wù)器的連接正常。接下來(lái),輸入命令:

# ehlo localhost

輸出看上去像這樣:

250-server1.crazytechgeek.info
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250 SMTPUTF8

接下來(lái),運(yùn)行橙色高亮的命令,例如 mail from、rcpt to、data,最后輸入 quit:

mail from:<pkumar>
250 2.1.0 Ok
rcpt to:<postfixuser>
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
Hello, Welcome to my mailserver (Postfix)
.
250 2.0.0 Ok: queued as B56BF1189BEC
quit
221 2.0.0 Bye
Connection closed by foreign host

完成 telnet 命令可從本地用戶 pkumar 發(fā)送郵件到另一個(gè)本地用戶 postfixuser,如下所示:

Send-email-with-telnet-centos8

如果一切都按計(jì)劃進(jìn)行,那么你應(yīng)該可以在新用戶的家目錄中查看發(fā)送的郵件:

# ls /home/postfixuser/Maildir/new
1573580091.Vfd02I20050b8M635437.server1.crazytechgeek.info
#

要閱讀郵件,只需使用 cat 命令,如下所示:

# cat /home/postfixuser/Maildir/new/1573580091.Vfd02I20050b8M635437.server1.crazytechgeek.info

Read-postfix-email-linux

Postfix 郵件服務(wù)器日志

Postfix 郵件服務(wù)器郵件日志保存在文件 /var/log/maillog 中,使用以下命令查看實(shí)時(shí)日志,

# tail -f /var/log/maillog

postfix-maillogs-centos8

保護(hù) Postfix 郵件服務(wù)器

建議始終確??蛻舳撕?Postfix 服務(wù)器之間的通信安全,這可以使用 SSL 證書來(lái)實(shí)現(xiàn),它們可以來(lái)自受信任的權(quán)威機(jī)構(gòu)或自簽名證書。在本教程中,我們將使用 openssl 命令生成用于 Postfix 的自簽名證書,

我假設(shè) openssl 已經(jīng)安裝在你的系統(tǒng)上,如果未安裝,請(qǐng)使用以下 dnf 命令:

# dnf install openssl -y

使用下面的 openssl 命令生成私鑰和 CSR(證書簽名請(qǐng)求):

# openssl req -nodes -newkey rsa:2048 -keyout mail.key -out mail.csr

Postfix-Key-CSR-CentOS8

現(xiàn)在,使用以下 openssl 命令生成自簽名證書:

# openssl x509 -req -days 365 -in mail.csr -signkey mail.key -out mail.crt
Signature ok
subject=C = IN, ST = New Delhi, L = New Delhi, O = IT, OU = IT, CN = server1.crazytechgeek.info, emailAddress = root@linuxtechi
Getting Private key
#

現(xiàn)在將私鑰和證書文件復(fù)制到 /etc/postfix 目錄下:

# cp mail.key mail.crt /etc/postfix

在 Postfix 配置文件中更新私鑰和證書文件的路徑:

# vi /etc/postfix/main.cf
………
smtpd_use_tls = yes
smtpd_tls_cert_file = /etc/postfix/mail.crt
smtpd_tls_key_file = /etc/postfix/mail.key
smtpd_tls_security_level = may
………

重啟 Postfix 服務(wù)以使上述更改生效:

# systemctl restart postfix

讓我們嘗試使用 mailx 客戶端將郵件發(fā)送到內(nèi)部本地域和外部域。

從 pkumar 發(fā)送內(nèi)部本地郵件到 postfixuser 中:

# echo "test email" | mailx -s "Test email from Postfix MailServer" -r root@linuxtechi root@linuxtechi

使用以下命令檢查并閱讀郵件:

# cd /home/postfixuser/Maildir/new/
# ll
total 8
-rw-------. 1 postfixuser postfixuser 476 Nov 12 17:34 1573580091.Vfd02I20050b8M635437.server1.crazytechgeek.info
-rw-------. 1 postfixuser postfixuser 612 Nov 13 02:40 1573612845.Vfd02I20050bbM466643.server1.crazytechgeek.info
# cat 1573612845.Vfd02I20050bbM466643.server1.crazytechgeek.info

Read-Postfixuser-Email-CentOS8

從 postfixuser 發(fā)送郵件到外部域(root@linuxtechi.com):

# echo "External Test email" | mailx -s "Postfix MailServer" -r root@linuxtechi root@linuxtechi

注意:如果你的 IP 沒(méi)有被任何地方列入黑名單,那么你發(fā)送到外部域的郵件將被發(fā)送,否則它將被退回,并提示你的 IP 被 spamhaus 之類的數(shù)據(jù)庫(kù)列入黑名單。

檢查 Postfix 郵件隊(duì)列

使用 mailq 命令列出隊(duì)列中的郵件:

# mailq
Mail queue is empty
#

完成!我們的 Postfix 配置正常工作了!目前就這樣了。我們希望你覺(jué)得本教程有見(jiàn)地,并且你可以輕松地設(shè)置本地 Postfix 服務(wù)器。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持本站。

美國(guó)穩(wěn)定服務(wù)器

版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。

相關(guān)文章

實(shí)時(shí)開通

自選配置、實(shí)時(shí)開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問(wèn)服務(wù)

1對(duì)1客戶咨詢顧問(wèn)

在線
客服

在線客服:7*24小時(shí)在線

客服
熱線

400-630-3752
7*24小時(shí)客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部