Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 伺服器技術 >> 郵件伺服器

實戰演練:利用 Postfix 實現不同網段間郵件互通(含路由、DNS、Webmail 完整部署)

編輯:郵件伺服器

實驗環境與拓撲

  • OS:RHEL 5.5(關閉 SELinux、配置 Yum、固定 IP)
  • 最少 3 台機器:Router(雙網卡轉發)、Sina 郵件伺服器(192.168.1.0/24)、Yahoo 郵件伺服器(192.168.2.0/24)
  • Router IP:eth0=192.168.1.1、eth1=192.168.2.1,開啟 echo 1 > /proc/sys/net/ipv4/ip_forward

實驗拓撲圖
Router IP 配置

DNS 服務部署(於 Router)

  1. yum -y install bind-*
  2. echo "" > /etc/resolv.conf(本機不指向上游)
  3. 編輯 /var/named/chroot/etc/named.conf 定義 sina.com、yahoo.com 兩個 zone,類型 master,區域檔分別為 sina.com.zone、yahoo.com.zone。
  4. 複製範本 cp /usr/share/doc/bind-9.3.6/sample/var/named/localhost.zone ... 修改區域檔:
    yahoo.com.zone:mail IN A 192.168.2.2、@ IN MX 10 mail
    sina.com.zone:mail IN A 192.168.1.2、@ IN MX 10 mail
    yahoo.com.zone
    sina.com.zone
  5. service named restart,用 dig 驗證解析正確。
    DNS 測試成功

Sina 伺服器配置(192.168.1.2)

  1. /etc/resolv.conf 指向 nameserver 192.168.1.1,host mail.sina.com 解析正常。
    Sina 解析測試
  2. 若解析失敗,加路由:route add -net 192.168.2.0/24 gw 192.168.1.1
  3. 停用 sendmail:service sendmail stop && chkconfig sendmail off
  4. yum -y install postfix,編輯 /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
    尾部加入 SASL 參數:
    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
  5. 修改 /etc/sysconfig/saslauthd:MECH=shadow。建立用戶 sina 設密碼,啟動 saslauthd,testsaslauthd -u sina -p 'abc-123' 回傳 OK。service postfix restart,telnet localhost 25 測試回應 250 碼。
    Postfix 測試 250 碼
  6. 安裝 Dovecot (POP3/IMAP):yum -y install dovecot,修改 /etc/dovecot.conf 啟用 pop3/pop3s 協定、監聽埠(頂格寫入)。重啟服務。
    Dovecot 配置
  7. 修改 Postfix mailbox_transport = lmtp:unix:/var/lib/imap/socket/lmtp 取消註釋。安裝 cyrus-imapd cyrus-imapd-devel,設定 cyrus 用戶密碼,啟動服務。用 cyradm -u cyrus localhost 進入後台建立 sina 郵箱用戶。
    /etc/passwd 查看 cyrus 用戶
    cyradm 建立信箱
  8. 安裝 SquirrelMail:yum -y install squirrelmail,執行 /usr/share/squirrelmail/config/conf.pl 設定:Server 選 Cyrus、General Options 啟用大小寫忽略、預設 IMAP Server 選 Cyrus。啟動 httpd。
    SquirrelMail 設定 1
    SquirrelMail 設定 2
    SquirrelMail 設定 3
    SquirrelMail 設定 4
  9. 瀏覽器訪問 https://mail.sina.com/webmail/ 登入測試自寄信成功。
    Webmail 登入頁
    Webmail 介面
    自寄信測試成功

Yahoo 伺服器配置(192.168.2.2)

步驟與 Sina 同,差異:
- /etc/resolv.conf 指向 nameserver 192.168.2.1
- Cyrus 建立用戶 yahoo
Yahoo 建立用戶

跨網段收發驗證

  1. Yahoo Webmail 寄信給 sina@sina.com → Sina Webmail 收到。
    Yahoo 寄給 Sina
    Sina 收到信件
  2. Sina 回信給 yahoo@yahoo.com → Yahoo Webmail 收到回覆。
    Sina 回信
    Yahoo 收到回覆

實驗成功! 缺點:每新增郵箱用戶需在系統建立帳號,後續可優化為虛擬用戶方案。
文章來源:https://yushantao.blog.51cto.com/975462/1220927#560270

Copyright © Windows教程網 All Rights Reserved