DQ NO.1 - dragon quest fans club

 找回密碼
 加入成為夥伴
搜索
熱搜: 活動 交友 discuz
查看: 3949|回復: 0

[分享] RedHat9.0 Mail Server Web Server 郵件防毒 無痛安

[複製鏈接]
發表於 2005-6-30 16:21:09 | 顯示全部樓層 |閱讀模式
RedHat9.0 Mail Server Web Server 郵件防毒 無痛安裝
測試環境 Intel Xeon 2.4G Ram 1024MB
OS RadHat9.0
Kernel 2.4..20-8
基本上部份設定是轉載鳥哥的網站,此文章為資料整理文件。

先從基本環境開始架設 先安裝 atp更新套件
rpm -ivh  ftp://apt.nc.hcc.edu.tw/pub/freshrpms/redhat/9/apt/apt-0.5.5cnc6-fr1.i386.rpm
這樣子又會將 apt套件線上安裝完畢(需要有網路環境)
在 更新一下 系統清單巴
Apt-get update 這樣子才可以從主機上下載資料。
再來進行 Mail Server的安裝
我所選用的套件為 Postfix這個郵件伺服器
Postfix2.2.3
cyrus-sasl-2.1.21
imap-2001a-18
procmail-3.22-9
有這些套件就可以完成安裝一個 Mail Server了
先檢查一下 在 系統內是否有安裝imap與procmail了。
[root@mail /]# rpm -qa |grep imap
imap-2001a-18
imap-devel-2001a-18
[root@mail /]# rpm -qa |grep procmail
procmail-3.22-9
如果沒有看到 使用
[root@mail /]# apt-get install imap
[root@mail /]# apt-get install procmail
接下來 下載 postfix 及 cyrus-sasl
由於我習慣把套件放在家目錄底下的套件種類進行分別
[root@mail /]# cd
[root@mail root]# mkdir tar rpm
[root@mail root]# cd tar
[root@mail tar]# mkdir mail
[root@mail tar]# cd mail
[root@mail mail]#
在屬於他的 目錄下打入wget進行下載
[root@mail mail]Wget http://ftp.cs.pu.edu.tw/Postfix-source/official/postfix-2.2.3.tar.gz
[root@61-219-211-244 mail]# wget ftp://ftp.andrew.cmu.edu/pub/cyrus-mail/cyrus-sasl-2.1.21.tar.gz
然後就開始進行編譯的程序了
先從 cyrus-sasl開始
[root@mail root]# cd /usr/local/src
[root@mail src]# tar -zxvf /root/cyrus-sasl-2.1.12.tar.gz
2. 再來就是設定你的 cyrus SASL 的參數以及編譯囉!
[root@mail src]# cd cyrus-sasl-2.1.12
[root@mail cyrus-sasl-2.1.12]# ./configure --prefix=/usr/local/cyrus-sasl2 --enable-login --enable-plain  --enable-pwcheck --with-saslauthd=/var/run
[root@mail cyrus-sasl-2.1.12]# make clean && make
[root@mail cyrus-sasl-2.1.12]# make install
由於 RedHat9.0依開始就會幫你安裝了 postfix的 LIB所以我的習慣是先把舊的LIB刪除,再將編譯好的版本,貼上。
[root@61-219-211-244 mail]# rm /usr/lib/libsasl2* 按Tab鍵確定檔案為sasl2的內容後,一個一個刪除。
[root@61-219-211-244 mail]# rm  -fr /usr/lib/sasl2/ 就放心刪除巴,待會要複製新的。
打入
[root@61-219-211-244 mail]# cp -fr /usr/local/cyrus-sasl2/lib/* /usr/lib/
[root@mail lib]# cd /usr/lib/sasl2
[root@mail sasl2]# echo 'pwcheck_method: saslauthd' > smtpd.conf  
[root@mail sasl2]# echo 'mech_list:plain login'  >>  smtpd.conf
把man page 加入系統內
[root@mail sasl2]# vi /etc/man.config
MANPATH /usr/local/cyrus-sasl2/man
檢驗 saslauthd 這支程式是否可行!
[root@mail sasl2]# /usr/local/cyrus-sasl2/sbin/saslauthd -a shadow
# 執行之後, saslauthd 的 PID 會被紀錄到 /var/run/mux.pid 這個檔案!
[root@test sasl2]# cd /usr/local/src/cyrus-sasl-2.1.12/saslauthd/
[root@test saslauthd]# make testsaslauthd
[root@test saslauthd]# ./testsaslauthd -u userID -p 'yours.passwd'
0: OK "Success."
顯示ok就為成功了
設定開機時啟動
[root @test saslauthd]# vi /etc/rc.d/rc.local
# 加入這一行:
/usr/local/cyrus-sasl2/sbin/saslauthd -a shadow
這樣子 cyrus-sasl就安裝完畢了。
接下來安裝postfix
先確認有沒有這個檔案存在!因為我們的 Postfix 會使用到很多資料庫啊!
[root@test root]# locate pcre.h | grep include
/usr/include/pcre.h
如果沒有 就使用 apt-get安裝巴 apt-get install pcre-devel
首先將資料解壓縮(假設您將我們網站的檔案捉到 /root 底下了!)
[root@test root]# cd /usr/local/src
[root@test src]# tar -zxvf /root/postfix-2.2.3.tar.gz
清除規則並且建立新的使用 SMTP 的規則給 postfix
[root@test src]# cd /usr/local/src/postfix-2.2.3
[root@test postfix-2.2.3]# make tidy  # 清除規則
[root@test postfix-2.2.3]# make makefiles CCARGS="-DUSE_SASL_AUTH -I/usr/include/sasl" \
# AUXLIBS="-L/usr/lib/sasl2 -lsasl2"
安裝前準備工作:
此外,還需要建立一個名為 postdrop 的群組與 postfix 的使用者喔!
[root@test postfix-2.2.3]# groupadd -r postdrop
[root@test postfix-2.2.3]# useradd -r -s /bin/false postfix
# 建立一個系統資料帳號吶!
[root@test postfix-2.2.3]# echo 'postfix:  root' >> /etc/aliases
4. 開始安裝 Postfix 到 /etc/postfix 這個目錄下:
[root@test postfix-2.2.3]# make install
# 底下會出現一大堆的問題集,不管如何,幾乎按下 enter 就對啦!
接下來就開始設定 mail的 設定檔了vi /etc/postfix/main.cf
myhostname = mail.dclinux.com.tw<==這裡請書寫你的主機名稱喔!
mydomain = dclinux.com      <==這裡則是你的 domain 名稱!
myorigin = $myhostname           <==這裡則是你的 送件來源的主機名稱  名稱!
mydestination = dclinux.com.tw mail.dclinux.com.tw <==這裡就是 郵件伺服器看到這個Domain的信才會將他收下來。
inet_interfaces = all
mynetworks = 192.168.1.0/24, 內部網路的 IP
relay_domains = dclinux.com.tw mail.dclinux.com.tw<==設定mail relay的domain。
alias_maps = hash:/etc/postfix/aliases
alias_database = hash:/etc/postfix/aliases
改完之後還需要以 postalias 來建置成為 postfix 可以讀取的資料庫格式喔!
[root@test root]# postalias hash:/etc/postfix/aliases
先確認設定檔有沒有錯誤:
[root@test root]# postfix check  <==檢查錯誤,若沒有任何顯示,表示正確
如果是 Tarball 安裝的情況:
[root@test root]# postfix start
檢查是否正確的啟動了呢?
[root@test root]# netstat -tl | grep smtp
tcp        0      0 *mtp                  *:*                     LISTEN
[root@test root]# vi /etc/postfix/main.cf
底下請自行新增在這個檔案的最後面:
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain =
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated,
     reject_unauth_destination
smtpd_client_restrictions = permit_sasl_authenticated
smtpd_sasl_security_options = noanonymous
到這邊主機就設定完畢了
重新啟動一下 postfix
[root@test root]# postfix restart
[root@test root]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mail2.cablesoft.com.tw ESMTP Postfix
ehlo localhost   <==確認一下你的主機狀態
250-mail.dclinux.com.tw
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH PLAIN LOGIN  <==出現這個就是成功囉!
250-XVERP
250 8BITMIME
quit  <==離開吧!
221 Bye
Connection closed by foreign host.
這樣子就可以在 outlook上面 測試是否可以收發信件了,記得要勾選外寄伺服器需要認證。
讓postfix支援MailScanner、spamassassin、f-prot
A、安裝 f-prot
從http://files.f-prot.com/files/linux-x86/fp-linux-ws.rpm下載 f-prot套件
# rpm -ivh fp-linux-ws.rpm
B、安裝MailScanner
下載http://www.sng.ecs.soton.ac.uk/mailscanner/files/4/rpm/MailScanner-版本.rpm.tar.gz
(這裡可能會少些perl的套件,出現啥錯誤訊息!請造著錯誤訊息要的rpm裝完即可!)
代碼:
# tar zxf MailScanner-版本.rpm.tar.gz
# cd MailScanner-版本
# ./install.sh
C、安裝spamassassin
引言回覆:
1、確認spamassassin是否有安裝:
代碼:
# rpm -qa |grep spam
spamassassin-2.63-8
如果沒有安裝就拿出 RedHat9的光碟 2 3 片
2、建立Mailscanner支援spamassassin所需的目錄:
代碼:
# mkdir /var/spool/MailScanner/spamassassin
# chmod 700 /var/spool/MailScanner/spamassassin
# chown postfix.postfix /var/spool/MailScanner/spamassassin
3、修改spamassassin的設定檔local.cf
代碼:
# vi /etc/mail/spamassassin/local.cf
# How many hits before a message is considered spam.
required_hits           5.0
# Whether to change the subject of suspected spam
rewrite_subject         1
# Text to prepend to subject if rewrite_subject is used
subject_tag             *****SPAM*****
# Encapsulate spam in an attachment
report_safe             1
# Use terse version of the spam report
use_terse_report        0
# Enable the Bayes system
use_bayes               1
# Enable Bayes auto-learning
auto_learn              1
# Enable or disable network checks
skip_rbl_checks         1
use_razor2              0
use_dcc                 0
use_pyzor               0
# Mail using languages used in these country codes will not be marked
# as being possibly spam in a foreign language.
ok_languages            all
# Mail using locales used in these country codes will not be marked
# as being possibly spam in a foreign language.
ok_locales              all
score HEADER_8BITS              0
score HTML_COMMENT_8BITS        0
score SUBJ_FULL_OF_8BITS        0
score UPPERCASE_25_50           0
score UPPERCASE_50_75           0
score UPPERCASE_75_100          0
score HEAD_ILLEGAL_CHARS        0
score SUBJ_ILLEGAL_CHARS        0
score X_PRIORITY_HIGH           0
4、啟動spamassassin
代碼:
# service spamassassin start
D、MailScanner設定
1、修改MailScanner.conf
代碼:
# vi /etc/MailScanner/MailScanner.conf
Run As User = postfix
Run As Group = postfix
Incoming Queue Dir = /var/spool/postfix/hold
Outgoing Queue Dir = /var/spool/postfix/incoming
MTA = postfix
Virus Scanners = f-prot
Always Include SpamAssassin Report = yes
Use SpamAssassin = yes
Required SpamAssassin Score = 4
SpamAssassin User State Dir = /var/spool/MailScanner/spamassassin
SpamAssassin Install Prefix = /usr/bin
SpamAssassin Local Rules Dir = /etc/MailScanner
2、修改 postfix支援mailscanner
# vi /etc/postfix/main.cf
變更以下的值
代碼:
header_checks = regexp:/etc/postfix/header_checks
# vi /etc/postfix/header_checks
加入以下的值
代碼:
/^Received:/ HOLD
PS: 注意, 在 / 之前不可以有空白!
3、變更目錄權限
代碼:
# chown postfix.postfix /var/spool/MailScanner/incoming
# chown postfix.postfix /var/spool/MailScanner/quarantine
4、停止postfix執行、啟動MailScanner
代碼:
# service MailScanner start
PS:設定MailScanner,當MTA = postfix時,會自己啟動postfix,如有設定啟動postfix的請先將它停掉
最後測試你的mail server 的防毒!
請到http://www.testvirus.org,輸入你的e-mail 後,它會寄一封認證信到你輸入的mail!開啟他就能測試1-26封的病毒信了!


之前再公司弄了一台,病毒.廣告信.mail Server的主機
Web的部分全忘光了,所以就沒有寫出來.....
您需要登錄後才可以回帖 登錄 | 加入成為夥伴

本版積分規則

Archiver|手機版|ぱふぱふ屋|DQ NO.1

GMT+8, 2024-4-23 15:27 , Processed in 0.024491 second(s), 16 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回復 返回頂部 返回列表