用實驗快速學習sendmail
用實驗快速學習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
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 server
root@server1... Connecting to localhost.localdomain. via relay...
220 station2.example.com ESMTP Sendmail
>>> 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:<root@station2.example.com> SIZE=47
250
>>> RCPT To:<root@server1.example.com>
>>> DATA
250
354 Enter mail, end with "." on a line by itself
>>> .
250
root@server1... Sent (h6GLIgpx001304 Message accepted for delivery)
Closing connection to localhost.localdomain.
>>> QUIT
221
sendmail的工作過程就如上所示。
你可以看日志,檢查mail的工作過程,更有意義的觀察方法:
在超級用戶,另一終端:
# tail -f /var/log/maillog
會動態顯示。
3.sendmail中使用假名:
1) 增加新用戶。
# useradd student2
# passwd student2
2) 編輯/etc/aliases,增加下列三行。
me: student2
wizards:root,me
methere: student2@station2.example.com
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作為跳板,發送郵件。
這里假設你有一個郵件叫 linuxsir@sina.com.cn,具體可以變更。
# telnet station2.example.com 25
Trying 192.168.0.2...
Connected to station2.example.com.
Escape character is '^]'.
220 station2.example.com ESMTP Sendmail
helo mail.cracker.org
250 station2.example.com Hello IDENT:root@station2.example.com. [192.168.0.2], pleased to meet you
mail from: spammer@cracker.org
250
rcpt to: linuxsir@sina.com.cn
250
data
354 Enter mail, end with "." on a line by itself
Subject: Relayed
This is faked and relayed!
ok?
.
250
quit
221
Connection closed by foreign host.
4) 觀察機器2的/var/log/maillog
5) 收你的linuxsir@sina.com.cn的郵件,看看里面的格式。
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: <root@station2.example.com>
Received: from station2.example.com (localhost.localdomain [127.0.0.1])
by station2.example.com (
for <student2@station2.example.com>; Thu, 17 Jul 2003 06:11:09 +0800
Received: (from root@localhost)
by station2.example.com (
for student2; Thu, 17 Jul 2003 06:11:09 +0800
Date: Thu, 17 Jul 2003 06:11:09 +0800
From: root <root@station2.example.com>
Message-Id: <200307162211.h6GMB9T0001573@station2.example.com>
To: student2@station2.example.com
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,試試能
收郵件嗎?假設你有個郵箱:linuxsir@sina.com,密碼:linuxsir
提示:poll mail.sina.com.cn with protocol pop3:
user linuxsir
password "linuxsir"
[實驗總結]
配置sendmail非常復雜,如果你在都完本文后,仍覺的一頭霧水的話,建議參考一些
mail工作原理的資料。另外,/usr/share/doc/sendmail/也有不少資料可供參考。
posted on 2005-09-26 08:59 MingIsMe 閱讀(537) 評論(0) 編輯 收藏 所屬分類: 09 Linux