用實驗快速學習sendmail

前言:mail配置比較複雜,本文用實驗的方法儘量以最通俗的方式,讓讀者學習sendmail
配置。
[實驗目的]
1.安裝sendmail。
2.在sendmail中使用假名。
3.用m4改變中轉行爲。
4.安裝和配置POP服務器和客戶端。
[實驗要求]
1.兩臺RH8.0機器互連。
2.機器1已配置好DNS,具體要求:機器1的IP:192.168.0.254,host:server1.example.com
機器2的IP:192.168.0.2,host:station2.example.com
[實驗步驟]
1.安裝sendmail。
1) 在機器1和機器2上檢查下列包是否安裝
sendmail
sendmail-cf
sendmail-doc
m4
procmail
缺什麼,裝什麼。
2) 編輯機器1和機器2的/etc/mail/sendmail.mc
去掉下列行的dnl
dnl DAEMON_OPTIONS(Port=smtp,Addr=127.0.0.1,Name=MTA)
作用是:使得可以接受其他域的mail。
3) 機器1和機器2上,產生新的配置文件,最好先備份/etc/mail/sendmail.cf
cp /etc/mial/sendmail.cf /etc/mail/sendmail.cf.BAK
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
4) 機器1和機器2上,重新啓動sendmail.
# service sendmail restart
# chkconfig sendmail on
2.檢測sendmail是否正常,及模擬sendmail操作。
1) 檢測sendmail是否可識別你的域名。
# sendmial -d0 < /dev/null
Version 8.12.5
Compiled with: DNSMAP HESIOD HES_GETMAILHOST LDAPMAP LOG MAP_REGEX
MATCHGECOS MILTER MIME7TO8 MIME8TO7 NAMED_BIND NETINET NETINET6
NETUNIX NEWDB NIS PIPELINING SASL SCANF STARTTLS TCPWRAPPERS
USERDB USE_LDAP_INIT
============ SYSTEM IDENTITY (after readcf) ============
(short domain name) $w = station2
(canonical domain name) $j = station2.example.com
(subdomain name) $m = example.com
(node name) $k = station2
========================================================
Recipient names must be specified
如果顯示localhost的話,檢查/etc/hosts 去掉除127.0.0.1以外的行。如果還有問題,
查看是否在/etc/sysconfig/network中設置了HOSTNAME
2) 模擬sendmail的操作。
# echo “hello server1” | mail -v -s hello root@server1
root@server1... Connecting to localhost.localdomain. via relay...
220 station2.example.com ESMTP Sendmail 8.12.5/8.12.5; Thu, 17 Jul 2003 05:18:42 +0800
>>> EHLO station2.example.com
250-station2.example.com Hello localhost.localdomain [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-DELIVERBY
250 HELP
>>> MAIL From: SIZE=47
250 2.1.0 ... Sender ok
>>> RCPT T
>>> DATA
250 2.1.5 ... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .
250 2.0.0 h6GLIgpx001304 Message accepted for delivery
root@server1... Sent (h6GLIgpx001304 Message accepted for delivery)
Closing connection to localhost.localdomain.
>>> QUIT
221 2.0.0 station2.example.com closing connection
sendmail的工作過程就如上所示。
你可以看日誌,檢查mail的工作過程,更有意義的觀察方法:
在超級用戶,另一終端:
# tail -f /var/log/maillog
會動態顯示。
3.sendmail中使用假名:
1) 增加新用戶。
# useradd student2
# passwd student2
2) 編輯/etc/aliases,增加下列三行。
me: student2
wizards:root,me
methere: [email protected]
3) 更新假名數據庫。
# newaliases
4) 測試:
# echo “hello there” | mail -s “hello” me
# echo “hello there” | mail -s “hello” wizards
# echo “hello there” | mail -s “hello” methere
5) student用戶收到幾封郵件?root受到幾封郵件?
4.控制中轉行爲。
1) 在機器2上編輯/etc/mail/sendmail.mc 文件,增加下列一行:
FEATURE(promiscuous_relay)dnl
注意:如果你這臺機連到internet上的話,不推薦你這麼作,因爲,internet上的用
戶會用你的這臺機作爲跳板,僞裝發郵件,使得郵件接收者無跡可尋。
2) 在機器2上用m4產生新的配置文件,這裏最好再備份原/etc/mail/sendmail.cf
# cp /etc/mail/sendmail.cf /etc/mail/sendmail.cf.BAK2
# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
3) 現在你在機器1上模擬,一個用心不良的用戶,用你的機器2作爲跳板,發送郵件。
這裏假設你有一個郵件叫 [email protected],具體可以變更。
# telnet station2.example.com 25
Trying 192.168.0.2...
Connected to station2.example.com.
Escape character is ^].
220 station2.example.com ESMTP Sendmail 8.12.5/8.12.5; Thu, 17 Jul 2003 05:45:05 +0800
helo mail.cracker.org
250 station2.example.com Hello IDENT:[email protected]. [192.168.0.2], pleased to meet you
mail from: [email protected]
250 2.1.0 [email protected]... Sender ok
rcpt t [email protected]
250 2.1.5 [email protected]... Recipient ok
data
354 Enter mail, end with "." on a line by itself
Subject: Relayed
This is faked and relayed!
ok?
.
250 2.0.0 h6GLj5MV001565 Message accepted for delivery
quit
221 2.0.0 station2.example.com closing connection
Connection closed by foreign host.
4) 觀察機器2的/var/log/maillog
5) 收你的[email protected]的郵件,看看裏面的格式。
6) 機器2,關掉中轉。
# cp /etc/mail/sendmail.cf /etc/mail/sendmail.cf.BAK2
# cp /etc/mail/sendmail.cf.BAK1 /etc/mail/sendmail.cf
# service sendmail restart
重作上面3)步,結果會怎麼樣呢?
7) 機器2 有選擇的中轉:
編輯/etc/mail/access,增加
example.com RELAY
重作上面3) 步,結果如何?
5.安裝和配置POP服務器和客戶端。
1) 機器2上,檢查下列包是否裝過
xinted
krb5-libs*
imap
缺什麼,裝什麼
2) 機器2上,啓動服務:
service xinetd start
chkconfig ipop3 on
3) 機器2上,確認服務。
# echo "mail to be popped" | mail -s "hello student2" student2
Trying 127.0.0.1...
Connected to localhost.
Escape character is ^].
+OK POP3 localhost.localdomain v2001.78rh server ready
user student2
+OK User name accepted, password please
pass student2
+OK Mailbox open, 1 messages
stat
+OK 1 641
TOP 1 700
+OK Top of message follows
Return-Path:
Received: from station2.example.com (localhost.localdomain [127.0.0.1])
by station2.example.com (8.12.5/8.12.5) with ESMTP id h6GMB9MV001575
for ; Thu, 17 Jul 2003 06:11:09 +0800
Received: (from root@localhost)
by station2.example.com (8.12.5/8.12.5/Submit) id h6GMB9T0001573
for student2; Thu, 17 Jul 2003 06:11:09 +0800
Date: Thu, 17 Jul 2003 06:11:09 +0800
From: root
Message-Id: <[email protected]>
T [email protected]
Subject: hello student2
Status:
mail to be popped
.
dele 1
+OK Message deleted
quit
+OK Sayonara
Connection closed by foreign host.
以上就是pop3的對話過程。如果一切正常的話,你的pop3服務器已經建立。
4) 機器1上安裝fetchmail 包。
5) 機器1上,root創建下列文件:
vi /root/.fetchmailrc
poll station2.example.com with protocol pop3:
user student2
password "student2"
6) 機器2上,運行:
# echo "mail to be popped" | mail -s "hello student2" student2
7) 機器1上作爲POP3客戶端,root收郵件:
# fetchmail -v
能收到郵件嗎?
8) 你有油箱嗎?仿照上面5) 的格式,寫一個pop3客戶收郵件的fetchmailrc,試試能
收郵件嗎?假設你有個郵箱:[email protected],密碼:linuxsir
提示:poll mail.sina.com.cn with protocol pop3:
user linuxsir
password "linuxsir"
[實驗總結]
配置sendmail非常複雜,如果你在都完本文後,仍覺的一頭霧水的話,建議參考一些mail工作原理的資料。另外,/usr/share/doc/sendmail/也有不少資料可供參考。
發佈了43 篇原創文章 · 獲贊 0 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章