Linux怎么配置Postfix邮件服务器
导读:本文共6424字符,通常情况下阅读需要21分钟。同时您也可以点击右侧朗读,来听本文内容。按键盘←(左) →(右) 方向键可以翻页。
摘要: 步骤 1)更新系统第一步是确保系统软件包是最新的。为此,请按如下所示更新系统:#dnfupdate继续之前,还请确保不存在其他 MTA(如 Sendmail),因为这将导致与 Postfix 配置冲突。例如,要删除 Sendmail,请运行以下命令:#dnfremovesendmail步骤 2)设置主机名并更新 /etc/hosts使用下面的 hostnamec... ...
目录
(为您整理了一些要点),点击可以直达。步骤 1)更新系统
第一步是确保系统软件包是最新的。为此,请按如下所示更新系统:
#dnfupdate
继续之前,还请确保不存在其他 MTA(如 Sendmail),因为这将导致与 Postfix 配置冲突。例如,要删除 Sendmail,请运行以下命令:
#dnfremovesendmail
步骤 2)设置主机名并更新 /etc/hosts
使用下面的 hostnamectl 命令在系统上设置主机名:
#hostnamectlset-hostnameserver1.crazytechgeek.info#execbash
此外,你需要在 /etc/hosts 中添加系统的主机名和 IP:
#vim/etc/hosts192.168.1.13server1.crazytechgeek.info
保存并退出文件。
步骤 3)安装 Postfix 邮件服务器
验证系统上没有其他 MTA 在运行后,运行以下命令安装 Postfix:
#dnfinstallpostfix
Install-Postfix-Centos8
步骤 4)启动并启用 Postfix 服务
成功安装 Postfix 后,运行以下命令启动并启用 Postfix 服务:
#systemctlstartpostfix#systemctlenablepostfix
要检查 Postfix 状态,请运行以下 systemctl 命令:
#systemctlstatuspostfix
Start-Postfix-check-status-centos8
太好了,我们已经验证了 Postfix 已启动并正在运行。接下来,我们将配置 Postfix 从本地发送邮件到我们的服务器。
步骤 5)安装 mailx 邮件客户端
在配置 Postfix 服务器之前,我们需要安装 mailx,要安装它,请运行以下命令:
#dnfinstallmailx
Install-Mailx-CentOS8
步骤 6)配置 Postfix 邮件服务器
Postfix 的配置文件位于 /etc/postfix/main.cf 中。我们需要对配置文件进行一些修改,因此请使用你喜欢的文本编辑器将其打开:
#vi/etc/postfix/main.cf
更改以下几行:
myhostname=server1.crazytechgeek.infomydomain=crazytechgeek.infomyorigin=$mydomain##取消注释并将inet_interfaces设置为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/
完成后,保存并退出配置文件。重新启动 postfix 服务以使更改生效:
#systemctlrestartpostfix
步骤 7)测试 Postfix 邮件服务器
测试我们的配置是否有效,首先,创建一个测试用户。
#useraddpostfixuser#passwdpostfixuser
接下来,运行以下命令,从本地用户 pkumar 发送邮件到另一个用户 postfixuser。
#telnetlocalhostsmtp或者#telnetlocalhost25
如果未安装 telnet 服务,那么可以使用以下命令进行安装:
#dnfinstalltelnet-y
如前所述运行命令时,应获得如下输出:
[root@linuxtechi~]#telnetlocalhost25Trying127.0.0.1...Connectedtolocalhost.Escapecharacteris'^]'.220server1.crazytechgeek.infoESMTPPostfix
上面的结果确认与 postfix 邮件服务器的连接正常。接下来,输入命令:
#ehlolocalhost
输出看上去像这样:
250-server1.crazytechgeek.info250-PIPELINING250-SIZE10240000250-VRFY250-ETRN250-STARTTLS250-ENHANCEDSTATUSCODES250-8BITMIME250-DSN250SMTPUTF8
接下来,运行橙色高亮的命令,例如 mail from、rcpt to、data,最后输入 quit:
mailfrom:2502.1.0Okrcptto:2502.1.5Okdata354Enddatawith.Hello,Welcometomymailserver(Postfix).2502.0.0Ok:queuedasB56BF1189BECquit2212.0.0ByeConnectionclosedbyforeignhost
完成 telnet 命令可从本地用户 pkumar 发送邮件到另一个本地用户 postfixuser,如下所示:
Send-email-with-telnet-centos8
如果一切都按计划进行,那么你应该可以在新用户的家目录中查看发送的邮件:
#ls/home/postfixuser/Maildir/new1573580091.Vfd02I20050b8M635437.server1.crazytechgeek.info#
要阅读邮件,只需使用 cat 命令,如下所示:
#cat/home/postfixuser/Maildir/new/1573580091.Vfd02I20050b8M635437.server1.crazytechgeek.info
Read-postfix-email-linux
Postfix 邮件服务器日志
Postfix 邮件服务器邮件日志保存在文件 /var/log/maillog 中,使用以下命令查看实时日志,
#tail-f/var/log/maillog
postfix-maillogs-centos8
保护 Postfix 邮件服务器
建议始终确保客户端和 Postfix 服务器之间的通信安全,这可以使用 SSL 证书来实现,它们可以来自受信任的权威机构或自签名证书。在本教程中,我们将使用 openssl 命令生成用于 Postfix 的自签名证书,
我假设 openssl 已经安装在你的系统上,如果未安装,请使用以下 dnf 命令:
#dnfinstallopenssl-y
使用下面的 openssl 命令生成私钥和 CSR(证书签名请求):
#opensslreq-nodes-newkeyrsa:2048-keyoutmail.key-outmail.csr
Postfix-Key-CSR-CentOS8
现在,使用以下 openssl 命令生成自签名证书:
#opensslx509-req-days365-inmail.csr-signkeymail.key-outmail.crtSignatureoksubject=C=IN,ST=NewDelhi,L=NewDelhi,O=IT,OU=IT,CN=server1.crazytechgeek.info,emailAddress=root@linuxtechiGettingPrivatekey#
现在将私钥和证书文件复制到 /etc/postfix 目录下:
#cpmail.keymail.crt/etc/postfix
在 Postfix 配置文件中更新私钥和证书文件的路径:
#vi/etc/postfix/main.cf………smtpd_use_tls=yessmtpd_tls_cert_file=/etc/postfix/mail.crtsmtpd_tls_key_file=/etc/postfix/mail.keysmtpd_tls_security_level=may………
重启 Postfix 服务以使上述更改生效:
#systemctlrestartpostfix
让我们尝试使用 mailx 客户端将邮件发送到内部本地域和外部域。
从 pkumar 发送内部本地邮件到 postfixuser 中:
#echo"testemail"|mailx-s"TestemailfromPostfixMailServer"-rroot@linuxtechiroot@linuxtechi
使用以下命令检查并阅读邮件:
#cd/home/postfixuser/Maildir/new/#lltotal8-rw-------.1postfixuserpostfixuser476Nov1217:341573580091.Vfd02I20050b8M635437.server1.crazytechgeek.info-rw-------.1postfixuserpostfixuser612Nov1302:401573612845.Vfd02I20050bbM466643.server1.crazytechgeek.info#cat1573612845.Vfd02I20050bbM466643.server1.crazytechgeek.info
Read-Postfixuser-Email-CentOS8
从 postfixuser 发送邮件到外部域(root@linuxtechi.com):
#echo"ExternalTestemail"|mailx-s"PostfixMailServer"-rroot@linuxtechiroot@linuxtechi
注意:如果你的 IP 没有被任何地方列入黑名单,那么你发送到外部域的邮件将被发送,否则它将被退回,并提示你的 IP 被 spamhaus 之类的数据库列入黑名单。
检查 Postfix 邮件队列
使用 mailq 命令列出队列中的邮件:
#mailqMailqueueisempty#
</div> <div class="zixun-tj-product adv-bottom"></div> </div> </div> <div class="prve-next-news">
Linux怎么配置Postfix邮件服务器的详细内容,希望对您有所帮助,信息来源于网络。