用實(shí)驗(yàn)快速學(xué)習(xí)sendmail
前言:mail配置比較復(fù)雜,本文用實(shí)驗(yàn)的方法盡量以最通俗的方式,讓讀者學(xué)習(xí)sendmail
配置。
[實(shí)驗(yàn)?zāi)康?/SPAN>]
1.安裝sendmail。
2.在sendmail中使用假名。
3.用m4改變中轉(zhuǎn)行為。
4.安裝和配置POP服務(wù)器和客戶端。
[實(shí)驗(yàn)要求]
1.兩臺(tái)RH8.0機(jī)器互連。
2.機(jī)器1已配置好DNS,具體要求:機(jī)器1的IP:192.168.0.254,host:server1.example.com
機(jī)器2的IP:192.168.0.2,host:station2.example.com
[實(shí)驗(yàn)步驟]
1.安裝sendmail。
1) 在機(jī)器1和機(jī)器2上檢查下列包是否安裝
sendmail
sendmail-cf
sendmail-doc
m4
procmail
缺什么,裝什么。
2) 編輯機(jī)器1和機(jī)器2的/etc/mail/sendmail.mc
去掉下列行的dnl
dnl DAEMON_OPTIONS('Port=smtp,Addr=127.0.0.1,Name=MTA')
作用是:使得可以接受其他域的mail。
3) 機(jī)器1和機(jī)器2上,產(chǎn)生新的配置文件,最好先備份/etc/mail/sendmail.cf
cp /etc/mial/sendmail.cf /etc/mail/sendmail.cf.BAK
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
4) 機(jī)器1和機(jī)器2上,重新啟動(dòng)sendmail.
# service sendmail restart
# chkconfig sendmail on
2.檢測(cè)sendmail是否正常,及模擬sendmail操作。
1) 檢測(cè)sendmail是否可識(shí)別你的域名。
# 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以外的行。如果還有問(wèn)題,
查看是否在/etc/sysconfig/network中設(shè)置了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:<root@station2.example.com> SIZE=47
250 2.1.0 <root@station2.example.com>... Sender ok
>>> RCPT To:<root@server1.example.com>
>>> DATA
250 2.1.5 <root@server1.example.com>... 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的工作過(guò)程就如上所示。
你可以看日志,檢查mail的工作過(guò)程,更有意義的觀察方法:
在超級(jí)用戶,另一終端:
# tail -f /var/log/maillog
會(huì)動(dòng)態(tài)顯示。
3.sendmail中使用假名:
1) 增加新用戶。
# useradd student2
# passwd student2
2) 編輯/etc/aliases,增加下列三行。
me: student2
wizards:root,me
methere: student2@station2.example.com
3) 更新假名數(shù)據(jù)庫(kù)。
# newaliases
4) 測(cè)試:
# 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.控制中轉(zhuǎn)行為。
1) 在機(jī)器2上編輯/etc/mail/sendmail.mc 文件,增加下列一行:
FEATURE(promiscuous_relay)dnl
注意:如果你這臺(tái)機(jī)連到internet上的話,不推薦你這么作,因?yàn)椋?/SPAN>internet上的用
戶會(huì)用你的這臺(tái)機(jī)作為跳板,偽裝發(fā)郵件,使得郵件接收者無(wú)跡可尋。
2) 在機(jī)器2上用m4產(chǎn)生新的配置文件,這里最好再備份原/etc/mail/sendmail.cf
# cp /etc/mail/sendmail.cf /etc/mail/sendmail.cf.BAK2
# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
3) 現(xiàn)在你在機(jī)器1上模擬,一個(gè)用心不良的用戶,用你的機(jī)器2作為跳板,發(fā)送郵件。
這里假設(shè)你有一個(gè)郵件叫 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 8.12.5/8.12.5; Thu, 17 Jul 2003 05:45:05 +0800
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 2.1.0 spammer@cracker.org... Sender ok
rcpt to: linuxsir@sina.com.cn
250 2.1.5 linuxsir@sina.com.cn... 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) 觀察機(jī)器2的/var/log/maillog
5) 收你的linuxsir@sina.com.cn的郵件,看看里面的格式。
6) 機(jī)器2,關(guān)掉中轉(zhuǎn)。
# cp /etc/mail/sendmail.cf /etc/mail/sendmail.cf.BAK2
# cp /etc/mail/sendmail.cf.BAK1 /etc/mail/sendmail.cf
# service sendmail restart
重作上面3)步,結(jié)果會(huì)怎么樣呢?
7) 機(jī)器2 有選擇的中轉(zhuǎn):
編輯/etc/mail/access,增加
example.com RELAY
重作上面3) 步,結(jié)果如何?
5.安裝和配置POP服務(wù)器和客戶端。
1) 機(jī)器2上,檢查下列包是否裝過(guò)
xinted
krb5-libs*
imap
缺什么,裝什么
2) 機(jī)器2上,啟動(dòng)服務(wù):
service xinetd start
chkconfig ipop3 on
3) 機(jī)器2上,確認(rèn)服務(wù)。
# 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 (8.12.5/8.12.5) with ESMTP id h6GMB9MV001575
for <student2@station2.example.com>; 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 <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的對(duì)話過(guò)程。如果一切正常的話,你的pop3服務(wù)器已經(jīng)建立。
4) 機(jī)器1上安裝fetchmail 包。
5) 機(jī)器1上,root創(chuàng)建下列文件:
vi /root/.fetchmailrc
poll station2.example.com with protocol pop3:
user student2
password "student2"
6) 機(jī)器2上,運(yùn)行:
# echo "mail to be popped" | mail -s "hello student2" student2
7) 機(jī)器1上作為POP3客戶端,root收郵件:
# fetchmail -v
能收到郵件嗎?
8) 你有油箱嗎?仿照上面5) 的格式,寫(xiě)一個(gè)pop3客戶收郵件的fetchmailrc,試試能
收郵件嗎?假設(shè)你有個(gè)郵箱:linuxsir@sina.com,密碼:linuxsir
提示:poll mail.sina.com.cn with protocol pop3:
user linuxsir
password "linuxsir"
[實(shí)驗(yàn)總結(jié)]
配置sendmail非常復(fù)雜,如果你在都完本文后,仍覺(jué)的一頭霧水的話,建議參考一些
mail工作原理的資料。另外,/usr/share/doc/sendmail/也有不少資料可供參考。