Linux 5.4 RHCE Sendmail 學習筆記基礎配置
<a href="http://wqmsl.blog.wqmsl.com/">我的部落格:http://wqmsl.blog.51cto.com/</a>
制作人:wqmsl
目标:1、搭建一個正常的sendmail伺服器,實作域内收發郵件
2、實作域和域之間發送郵件
3、實作群發功能
1、IP說明:
192.168.1.2——主機名:mail.wqmsl.com mail伺服器
192.168.1.3——主機名:mail.lpmsl.com mail伺服器
192.168.1.4——主機名:dns.wqmsl.com DNS伺服器
2、前期準備
更改主機名稱(更改三處):1、hostname更改,2、hosts更改,3、/etc/sysconfig/network
3、所需軟體包如下
Sendmail服務軟體包
sendmail-8.13.8-2.el5.i386.rpm:sendmail服務的主程式包,必須安裝該軟體包。
sendmail-cf-8.13.8-2.el5.i386.rpm:sendmail宏檔案包
sendmail-devel-8.13.8-2.el5.i386.rpm:sendmail伺服器開發工具軟體包
sendmail-doc-8.13.8-2.el5.i386.rpm:sendmail伺服器的說明文檔
m4-1.4.5-3.el5.1.i386.rpm:宏處理過慮軟體包
dovecot-1.0-1.2.rc15.el5.i386.rpm:接收郵件軟體包,安裝時需要注意安裝順序
2.Sendmail相關配置文檔
sendmail.cf:sendmail核心配置檔案,位于/etc/mail/sendmail/sendmail.cf
sendmail.mc:sendmail提供sendmail檔案模闆,通過編輯此檔案後再使用m4工具将結果導入sendmail.cf完成配置sendmail核心配置檔案,降低配置複雜度,位于/etc/mail/sendmail.mc
local-host-name:定義收發郵件伺服器的域名和主機名稱,位于/etc/mail/local-host-name
access.db:用來設定sendmail伺服器為哪些主機進行轉發郵件,位于/etc/mail/access.db
aliases.db:用來定義郵箱别名,位于/etc/mail/aliases.db
virtusertable.db:用來設定虛拟賬戶,位于/etc/mail/virtusertable.db
下面我們看看哦
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_12739353472D33.png"></a>
我們先來做一下基礎的工作,配置好DNS伺服器
在DNS上有三個區域檔案 wqmsl.com.zone、192.168.1.rev、lpmsl.com.zone各個區域檔案配置内容如下
wqmsl.com.zone
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_1273935350lkyX.png"></a>
192.168.1.rev
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_1273935357yD3r.png"></a>
lpmsl.com.zone
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_1273935366xfJb.png"></a>
如有DNS上面的問題,請看《Linux 5.4 RHCE DNS學習筆記》
要保證在用戶端可以正常解析哦
下面我們來配置sendmail伺服器
一、來實作第一個實驗目标,搭建一個正常的sendmail伺服器,實作本域使用者收發郵件
修改DNS域名解析的配置檔案
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_1273935370RZKq.png"></a>
Sendmail軟體的安裝我就不多說了,你可以使用rpm安裝也可以使用yum安裝,看個人愛好哦
下面我們就來開始配置吧
找到52和53行去掉開頭的dnl(注釋的意思),讓其生效
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_1273935373leDL.png"></a>
找到116這行,把原來的127.0.0.1改為0.0.0.0,默這樣可以擴大偵聽範圍(通常都設定成0.0.0.0),否則郵件伺服器無法正常發送郵件。
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_1273935373JaHQ.png"></a>
找到155這行,修改為自己伺服器所在的域名
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_1273935377wjkb.png"></a>
儲存退出
然後修改 local-host-names 這個檔案,添加自己的域名和主機名
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_1273935391XHfZ.png"></a>
然後使用m4指令生成sendmail.cf檔案,其實sendmail.mc即是一個模闆檔案哈~
m4 /etc/mail/sendmail.mc &gt; /etc/mail/sendmail.cf 執行後沒有任何消息傳回
然後重新開機服務并設定伺服器開機自行啟動
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_1273935395pRGp.png"></a>
下面我們安裝Dovecot軟體包(POP3和IMAP)
到這裡sendmail伺服器基本配置完成後,Mail Server就可以完成郵件發送工作,如果需要使用POP3和IMAP協定接收郵件還需要安裝dovecot軟體包。在rhel5裡dovecot整合了IMAP。
安裝dovecot軟體包要解決其依賴性,安裝perl-DBI-1.52-1.fc6.i386.rpm和mysql-5.0.22-2.1.0.1.i386.rpm
是以大家可以使用yum 來安裝,省心啊...(偶比較懶哦)
我的已經安裝過了,來看一下(安裝指令:yum install dovecot 依賴性自動解決)
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_1273935396uTP1.png"></a>
配置dovecot,打開/etc/dovecot.conf ,找到第20行,去掉前面的注釋即可
這樣就開啟了IMAP和pop3了。
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_1273935397ASxK.png"></a>
啟動dovecot服務并讓其随開機啟動
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_1273935399O3Ey.png"></a>
檢查sasl包是否都安裝到系統上了,預設已經安裝到系統上了(sasl是用來用戶端驗證使用者的,是以必須安裝的)
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_1273935399fc91.png"></a>
已經都安裝到系統上了,啟動saslauthd服務并讓其随系統開機啟動
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_1273935400puB5.png"></a>
端口測試
使用netstat指令測試是否開啟SMTP的25端口、POP3的110端口及IMAP的143端口
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_127393540805Mh.png"></a>
可以看到所有端口都處于監聽狀态
驗證Sendmail的SMTP認證功能
使用telnet 192.168.1.2 25,然後ehlo localhost
250-AUTH DIGEST-MD5 CRAM-MD5 LOGIN PLAIN 有這行顯示說明sendmail開啟了使用者認證(smtp認證)
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_1273935416S9KM.png"></a>
然後 telnet 192.168.1.2 110
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_1273935422ch3P.png"></a>
這樣我們就可以建立郵件使用者了
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_1273935424JNbt.png"></a>
建立使用者的參數我就不詳細說明了。
我們使用Windows用戶端測試一下
我們從wqmsl2給wqmsl3發送測試郵件,如下:
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_1273935433rpA0.png"></a>
在wqmsl3上收取郵件,如下:
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_1273935445Ud9Z.png"></a>
二、下面我們實作第二個目标,實作不同域之間郵件發送
所有DNS,和mail.wqmsl.com伺服器作為第二個目标的基礎,我們隻要搭建好第二台mail.lpmsl.com伺服器即可
mail.lpmsl.com ——IP:192.168.1.3 主機名:mail.lpmsl.com
Mail.lpmsl.com伺服器搭建方法和,mail.wqmsl.com伺服器方法一樣下面我們之間來測試就行了
我直接測試就行了(在用戶端上一定要選上“我的伺服器要求身份驗證”,否則你的郵件會被本地伺服器阻攔)
使用[email protected] 給[email protected] 、[email protected] 發送郵件
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_12739354524iMS.png"></a>
下面看一下接收到的郵件
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_1273935455vHwA.png"></a>
接收成功
這裡有時候大家肯能會遇到一點問題,這個我們最後的時候總結一下遇到的問題
一、下面我們實作sendmail群發功能
要實作群發功能其實很簡單的,隻要修改/etc/aliases 這個檔案就可以了,修改之後記得要用newaliases這個指令生成新的資料檔案,下面來操作
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_1273935466VCIR.png"></a>
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_1273935475kox7.png"></a>
這樣,我使用[email protected]發郵件給 [email protected],這樣[email protected]和[email protected]句能收到郵件,下面我們來測試哦
寫郵件
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_1273935477Pmci.png"></a>
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_1273935481uZry.png"></a>
<a href="http://wqmsl.blog.51cto.com/attachment/201005/15/847418_1273935486YNW1.png"></a>
最近比較忙,今天先說到這裡,下次我們要說道sendmail的進階配置的。
本文轉自 wqmsl 51CTO部落格,原文連結:http://blog.51cto.com/wqmsl/316245,如需轉載請自行聯系原作者