先言:人類很早時期就通過寫信的方式實現不同地區間的通訊 在進入到21世紀後,郵件的作用顯得更為重要 ,互連網的出現極大的減小了收信時間,讓人們幾乎達到可以即時對話,那麼是如何搭建一個郵件伺服器讓人們使用呢 在linux中是通過postfix來實現的
實驗準備:關閉SELinux,配置yum源 配置IP地址
實驗環境:RHEL5.5
實驗所用機器最少三台 其中有一台充當router用於轉寄不同網段的資料包
實驗拓撲圖如下
650) this.width=650;" style="border-right- 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1P034FH-0.png" width="644" height="255" />
router的IP配置如下
650) this.width=650;" style="border-right- 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1P034M20-1.png" width="644" height="351" />
echo 1 > /proc/sys/net/ipv4/ip_forward 開啟網卡轉寄功能
配置DNS
安裝DNS服務
yum –y install bind-*
echo “” > /etc/resolv.conf DNS的指向為空白
vim /var/named/chroot/etc/named.conf 建立一個設定檔
options {
directory "/var/named";
};
zone "sina.com" {
type master;
file "sina.com.zone";
};
zone "yahoo.com" {
type master;
file "yahoo.com.zone";
};
cp /usr/share/doc/bind-9.3.6/sample/var/named/localhost.zone /var/named/chroot/var/named/yahoo.com.zone
cp /usr/share/doc/bind-9.3.6/sample/var/named/localhost.zone /var/named/chroot/var/named/sina.com.zone copy模板檔案到地區檔案
cd /var/named/chroot/var/named/
vim yahoo.com.zone
650) this.width=650;" style="border-right- 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1P0343040-2.png" width="644" height="236" />
vim sina.com.zone
650) this.width=650;" style="border-right- 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1P0345437-3.png" width="644" height="213" />
重啟服務 service named restart
測試
650) this.width=650;" style="border-right- 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1P034K35-4.png" width="644" height="272" />
OK 解析成功
sina 機器上的配置
1.設定解析檔案
vi /etc/resolv.conf
nameserver 192.168.1.1
host mail.sina.com 解析主機地址
650) this.width=650;" style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1P0345057-5.png" "644" height="146" />
如果解析不成功建議添加一條路由記錄
route add -net 192.168.2.0/24 gw 192.168.1.1 到達的目標地址 網關
2. 關閉sendmial服務
service sendmail stop
chkconfig sendmail off
3. 安裝postfix 發送郵件
yum –y install postfix
vim /etc/postfix/main.cf
myhostname = mail.sina.com
mydomain = sina.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname,$mydomain
mynetworks = 192.168.1.0/24, 192.168.2.0, 127.0.0.0/8 郵件伺服器的網段
relay domains = sina.com, yahoo.com 設定可以轉寄哪些網域的郵件
在設定檔的末尾加上
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = ''
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination
broken_sasl_auth_clients = yes
smtpd_client_restrictions = permit_sasl_authenticated
smtpd_sasl_security_options = noanonymous
儲存退出
vim /etc/sysconfig/saslauthd 修改saslauthd服務的設定檔
修改 MECH=shadow
退出
建立一個使用者sina 然後為使用者佈建密碼
useradd sina
passwd sina
啟動saslauthd服務
/etc/init.d/saslauthd restart
chkconfig saslauthd on
測試命令
testsaslauthd -u sina -p 'abc-123'
如果返回OK Success則表示saslauthd服務已經成功工作
service postfix restart 重啟postfix服務
測試postfix
650) this.width=650;" style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1P0344395-6.png" "644" height="234" />
返回250代碼則說明postfix已經配置成功
4 安裝dovecot服務 內送郵件
yum -y install dovecot
修改設定檔
vi /etc/dovecot.conf
要修改的有兩個地方
650) this.width=650;" style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1P0343647-7.png" "644" height="337" />
第20行中設定協議是pop3和pop3s協議
在第35行中去掉注釋 監聽POP3連接埠 注意這裡一定要頂格寫 包括38行的}也是定行寫 不然linux讀取這裡會先讀取空格然後再讀取其他的配置
service dovecot restart 重啟服務
chkconfig dovecot on
修改postfix主配檔案
大約在456行位置 找到
mailbox_transport = lmtp:unix:/var/lib/imap/socket/lmtp 去掉這一行的注釋 使之關聯起來
yum -y install cyrus-imapd cyrus-imapd-devel
cat /etc/passwd 檔案
650) this.width=650;" style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1P034B50-8.png" "644" height="82" />
可以看到有一個cyrus的使用者
設定cyrus的密碼
passwd cyrus
重啟服務
/etc/init.d/cyrus-imapd restart
chkconfig cyrus-imapd on
連結到後台
cyradm -u cyrus localhost
650) this.width=650;" style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1P0344634-9.png" "644" height="150" />
建立一個sina的信箱使用者
然後quit退出
5 安裝webmail
yum -y install squirrelmail
運行PHP設定工具
/usr/share/squirrelmail/config/conf.pl
1)在command中輸入2 伺服器設定
再依次輸入數字元1 3 修改配置
650) this.width=650;" style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1P034CX-10.png" "644" height="290" />
r返回 然後輸入A-------8 改為Cyrus
650) this.width=650;" style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1P0345910-11.png" "542" height="484" />
r返回 然後輸入4 General Options 再選5 將值修改為true #忽略字母大小寫
650) this.width=650;" style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1P03460P-12.png" "524" height="484" />
r返回 然後輸入D Set pre-defined settings for specific IMAP server
IMAP Server為: cyrus
650) this.width=650;" style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1P0344241-13.png" "503" height="374" />
s儲存 q退出 然後啟動httpd服務 service httpd restart
如果沒有安裝的話就安裝httpd服務 yum –y install http-*
開啟瀏覽器輸入 http://mail.sina.com/webmail/
650) this.width=650;" style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1P0342493-14.png" "644" height="368" />
登入後
650) this.width=650;" style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1P03464D-15.png" "644" height="343" />
給自己發郵件測試
650) this.width=650;" style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1P034K37-16.png" "644" height="354" />
OK測試成功
這時再配置yahoo這台機器
1.設定解析檔案
vi /etc/resolv.conf
nameserver 192.168.2.1
從第二步開始都和sina機器配置一樣 唯一不同的在於建立的信箱使用者名 這裡我們在yahoo的機器上配置一個yahoo的信箱使用者
650) this.width=650;" style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1P0345202-17.png" "644" height="389" />
登入後給sina這個使用者發一封郵件
650) this.width=650;" style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1P0341F2-18.png" "644" height="440" />
這時再看sina這個郵箱有沒有收到郵件
650) this.width=650;" style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1P0344007-19.png" "642" height="484" />
sina再給yahoo回一個試試
650) this.width=650;" style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1P03410I-20.png" "644" height="434" />
在到yahoo查看郵件
650) this.width=650;" style="border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.bkjia.com/uploads/allimg/131227/1P0341436-21.png" "644" height="448" />
收到了回複 實驗成功 OK 這裡有一個弊端 每建立一個信箱使用者就在伺服器上建立一個使用者名稱 下次要完善虛擬使用者 各位請多多指教