自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

如何在CentOS 8上安裝和配置Postfix郵件服務(wù)器

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

[[283088]]

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

實驗室設(shè)置:

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

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

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

  1. # dnf update

繼續(xù)之前,還請確保不存在其他 MTA(如 Sendmail),因為這將導(dǎo)致與 Postfix 配置沖突。例如,要刪除 Sendmail,請運行以下命令:

  1. # dnf remove sendmail

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

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

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

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

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

保存并退出文件。

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

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

  1. # dnf install postfix

 

Install-Postfix-Centos8

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

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

  1. # systemctl start postfix
  2. # systemctl enable postfix

要檢查 Postfix 狀態(tài),請運行以下 systemctl 命令:

  1. # systemctl status postfix

 

Start-Postfix-check-status-centos8

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

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

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

  1. # dnf install mailx

 

Install-Mailx-CentOS8

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

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

  1. # vi /etc/postfix/main.cf

更改以下幾行:

  1. myhostname = server1.crazytechgeek.info
  2. mydomain = crazytechgeek.info
  3. myorigin = $mydomain
  4. ## 取消注釋并將 inet_interfaces 設(shè)置為 all##
  5. inet_interfaces = all
  6. ## 更改為 all ##
  7. inet_protocols = all
  8. ## 注釋 ##
  9. #mydestination = $myhostname, localhost.$mydomain, localhost
  10. ## 取消注釋 ##
  11. mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
  12. ## 取消注釋并添加 IP 范圍 ##
  13. mynetworks = 192.168.1.0/24, 127.0.0.0/8
  14. ## 取消注釋 ##
  15. home_mailbox = Maildir/

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

  1. # systemctl restart postfix

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

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

  1. # useradd postfixuser
  2. # passwd postfixuser

接下來,運行以下命令,從本地用戶 pkumar 發(fā)送郵件到另一個用戶 postfixuser。

  1. # telnet localhost smtp
  2. 或者
  3. # telnet localhost 25

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

  1. # dnf install telnet -y

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

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

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

  1. # ehlo localhost

輸出看上去像這樣:

  1. 250-server1.crazytechgeek.info
  2. 250-PIPELINING
  3. 250-SIZE 10240000
  4. 250-VRFY
  5. 250-ETRN
  6. 250-STARTTLS
  7. 250-ENHANCEDSTATUSCODES
  8. 250-8BITMIME
  9. 250-DSN
  10. 250 SMTPUTF8

接下來,運行橙色高亮的命令,例如 mail fromrcpt to、data,最后輸入 quit

  1. mail from:<pkumar>
  2. 250 2.1.0 Ok
  3. rcpt to:<postfixuser>
  4. 250 2.1.5 Ok
  5. data
  6. 354 End data with <CR><LF>.<CR><LF>
  7. Hello, Welcome to my mailserver (Postfix)
  8. .
  9. 250 2.0.0 Ok: queued as B56BF1189BEC
  10. quit
  11. 221 2.0.0 Bye
  12. Connection closed by foreign host

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

 

Send-email-with-telnet-centos8

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

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

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

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

 

Read-postfix-email-linux

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

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

  1. # tail -f /var/log/maillog

 

postfix-maillogs-centos8

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

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

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

  1. # dnf install openssl -y

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

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

 

Postfix-Key-CSR-CentOS8

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

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

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

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

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

  1. # vi /etc/postfix/main.cf
  2. ………
  3. smtpd_use_tls = yes
  4. smtpd_tls_cert_file = /etc/postfix/mail.crt
  5. smtpd_tls_key_file = /etc/postfix/mail.key
  6. smtpd_tls_security_level = may
  7. ………

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

  1. # systemctl restart postfix

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

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

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

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

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

 

Read-Postfixuser-Email-CentOS8

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

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

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

檢查 Postfix 郵件隊列

使用 mailq 命令列出隊列中的郵件:

  1. # mailq
  2. Mail queue is empty
  3. #

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

 

責(zé)任編輯:龐桂玉 來源: Linux中國
相關(guān)推薦

2019-10-14 15:00:12

Centos 8 RHEL 8VNC

2011-02-21 14:12:15

Postfix服務(wù)器安裝

2011-01-20 10:08:25

postfix安裝

2010-06-02 18:17:09

Postfix郵件

2015-12-11 13:16:10

CentOS 7Redis服務(wù)器

2019-11-05 11:20:36

CentOS 8RHEL 8Linux

2023-05-05 16:20:15

2019-11-14 09:20:15

CentOS 8RHEL 8Nagios Core

2010-06-02 16:48:49

postfix郵件服務(wù)

2016-08-04 13:44:20

CentOS6.xNodejs解決方案

2019-05-05 10:42:22

LinuxNTP命令

2020-03-02 18:16:12

FedoraLinuxMongoDB

2019-10-28 14:38:36

RsyslogCentOS8開源

2017-03-17 14:05:48

LinuxUbuntuFTP服務(wù)器

2019-10-12 10:24:06

CentOSRHELCockpit

2020-03-02 14:06:54

CentOS 8FFmpegLinux

2011-01-18 15:47:20

2017-04-11 13:20:06

CentOSRHELFedora

2015-12-25 14:30:47

LinuxISC DHCP服務(wù)器

2015-08-04 13:29:06

Fedoralinux
點贊
收藏

51CTO技術(shù)棧公眾號