天天看點

Linux網絡服務_郵件伺服器-Redhat Enterprise 5.9

Linux網絡服務_郵件伺服器-Redhat Enterprise 5.9

案例環境:

郵件伺服器:mail.tarena.com192.168.1.100

郵件域:@tarena.com

郵件賬号:伺服器的系統使用者

發信服務軟體:postfix

授信服務軟體:dovecot

第一部分:安裝并測試發信服務軟體postfix

第一步:與郵件相關的DNS設定:

需要事先配置dns,在正向檔案中添加相應的MX記錄、A記錄

[root@server1 ~]# cat /var/named/chroot/var/named/tarena.com.zheng

$TTL    86400

@       IN      SOA    tarena.com. root.tarena.com.  (

                                     2014031001 ; Serial

                                     28800      ; Refresh

                                     14400      ; Retry

                                     3600000    ; Expire

                                     86400)     ; Minimum

       IN      NS       server1.tarena.com.

      IN     MX  5   mail.tarena.com.

server1 IN      A        192.168.1.100

mail    IN    A       192.168.1.100

[root@server1 ~]#

第二步:安裝postfix服務

注:

1,在安裝postfix服務之前,需要先關閉sendmail服務,避免端口沖突

2,依賴包為perl-DBI,安裝完後要添加postfix服務

3,需要手動添加postfix服務:chkconfig --add postfix

[root@server1 ~]# service sendmail stop

關閉 sm-client:                                           [确定]

關閉 sendmail:                                            [确定]

[root@server1 ~]# chkconfig sendmail off

[root@server1 ~]# yum -y install postfix

[root@server1 ~]# chkconfig --add postfix

[root@server1 ~]# chkconfig --list postfix

postfix         0:關閉  1:關閉  2:啟用  3:啟用  4:啟用  5:啟用  6:關閉

[root@server1 ~]# service postfix start

啟動 postfix:                                             [确定]

第三步:修改主配置檔案:/etc/postfix/main.cf

服務配置:/etc/postfix/main.cf

主程式配置:/etc/postfix/master.cf

postconf輔助工具:

無選項時,檢視目前的有效配置

選項-n,檢視非預設配置

選項-d,檢視預設的配置

利用postconf提取有效配置,排除幹擾項、隻保留非預設的配置

注:由于postconf-n在輸出資訊的過程中,需要讀取main.cf檔案,是以,先執行

post -n >test.txt,之後再将main.cf更名為main.cf.old,否則,非預設的配置内容将會改變,最後再在将text.txt改名為main.cf,那麼main.cf裡面的内容就為非預設的配置了。

[root@server1 ~]# cd /etc/postfix/

[root@server1 postfix]# postconf -n > test.txt

[root@server1 postfix]# mv main.cf main.cf.old

[root@server1 postfix]# mv test.txt main.cf

[root@server1 postfix]# vim main.cf

[root@server1 postfix]# cat main.cf

alias_database = hash:/etc/aliases

alias_maps = hash:/etc/aliases

command_directory = /usr/sbin

config_directory = /etc/postfix

daemon_directory = /usr/libexec/postfix

debug_peer_level = 2

html_directory = no

#inet_interfaces = localhost       //把這一行注釋掉,否則隻允許本地回環位址

mail_owner = postfix

mailq_path = /usr/bin/mailq.postfix

manpage_directory = /usr/share/man

mydestination = $myhostname, localhost.$mydomain,localhost

newaliases_path = /usr/bin/newaliases.postfix

queue_directory = /var/spool/postfix

readme_directory =/usr/share/doc/postfix-2.3.3/README_FILES

sample_directory =/usr/share/doc/postfix-2.3.3/samples

sendmail_path = /usr/sbin/sendmail.postfix

setgid_group = postdrop

unknown_local_recipient_reject_code = 550

myhostname = mail.tarena.com       //郵件伺服器名子

mydomain = tarena.com       //郵件域

myorigin = $mydomain     //顯示發件域,随郵件域變化

mydestination = $mydomain,$myhostname     //本地投遞域

home_mailbox = Maildir/         //郵箱類型,這裡指定在家目錄的Maildir下

[root@server1 postfix]# service postfix restart

關閉 postfix:                                             [确定]

[root@server1 postfix]# netstat -anpt | grep 25

tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      11475/master

[root@server1 postfix]#

第四步:測試SMTP發信

使用telnet工具:連接配接到25端口,執行發信指令

基本的SMTP指令

   HELO:宣告客戶機位址(大小寫均可)

   MAIL FROM:指定發件人郵箱位址

   RCPT TO:指定收件人郵箱位址

   DATA:編寫郵件内容,SUBJECT為主題,結束則需另起一行,一點“.”結束

[root@server1 ~]#telnet mail.tarena.com 25

Trying192.168.1.100...

Connected tomail.tarena.com (192.168.1.100).

Escape character is'^]'.

220 mail.tarena.comESMTP Postfix

helo mail.tarena.com            //給mail.tarena.com打招呼

250 mail.tarena.com             //mail.tarena.com給出250回應,如果是501則失敗

mail from:[email protected]       //發信人為nick

250 2.1.0 Ok

rcpt to:[email protected]       //收信任為hunter

250 2.1.5 Ok

data        //正文的開始

354 End data with<CR><LF>.<CR><LF>     //提示以“.”結束

subject:Test mail           //郵件标題,subject開頭

this is a test mail...         //這是郵件内容

.           //以“.”結束

250 2.0.0 Ok: queuedas A68ED41BFB3

quit        //quit退出郵件系統

221 2.0.0 Bye

Connection closed byforeign host.

[root@server1 ~]# ls /home/hunter/Maildir/new/      //檢視新郵件清單

1394448613.V803I30cf17M502725.server1.tarena.com

[root@server1 ~]# cd /home/hunter/Maildir/new/      //郵件存放位置

[root@server1 new]# cat 1394448613.V803I30cf17M502725.server1.tarena.com

Return-Path:<[email protected]>

X-Original-To:[email protected]

Delivered-To:[email protected]

Received:from mail.tarena.com (server1.tarena.com [192.168.1.100])

       by mail.tarena.com (Postfix) with SMTPid A68ED41BFB3

       for <[email protected]>; Mon, 10Mar 2014 18:49:16 +0800 (CST)

subject:Testmail

Message-Id:<[email protected]>

Date:Mon, 10 Mar 2014 18:49:16 +0800 (CST)

From:[email protected]

To:undisclosed-recipients:;

thisis a test mail ...

[root@server1 new]#

第二部分:安裝并測試收信服務軟體dovecot

第一步:安裝dovecot軟體并啟動該服務

[root@server1 ~]#yum install dovecot

[root@server1 ~]#chkconfig --list dovecot

dovecot         0:關閉  1:關閉  2:關閉  3:關閉  4:關閉  5:關閉  6:關閉

[root@server1 ~]#service dovecot start

啟動 DovecotImap:                                        [确定]

[root@server1 ~]#chkconfig dovecot on

第二步:配置收信服務

調整dovecot配置:

1,整個配置檔案基本不需更改,隻需保證以下三個字段正确即可:

/etc/dovecot.conf配置檔案中

ssl_disable = yes                   //禁用ssl加密

disable_plaintest_auth= no         //允許明文認證通信

mail_location =maildir:~/Maildir   //設定郵箱路徑

2,重新啟動服務:service dovecot restart

3,保證tcp的110和143端口開啟

[root@server1 ~]# netstat -anpt | grep dovecot

tcp        0      0 :::993           :::*            LISTEN      12138/dovecot      

tcp        0      0 :::995           :::*            LISTEN      12138/dovecot      

tcp        0      0 :::110           :::*            LISTEN     12138/dovecot      

tcp        0      0 :::143           :::*            LISTEN     12138/dovecot      

第三步:測試POP3/IMAP收信

使用telnet工具:連接配接到110或143端口,執行收信指令

基本的SMTP指令:

   USER:指定登入賬号

   PASS:指定用于驗證的密碼

   LIST:檢視郵件清單

   RETR:擷取指定編号的郵件内容

[root@server1 ~]# telnet mail.tarena.com 110

+OK Dovecot ready.

user hunter

+OK

pass 123

+OK Logged in.

list

+OK 2 messages:

1 473

.

retr 1

+OK 491 octets

Received: frommail.tarena.com (server1.tarena.com [192.168.1.100])

subject:Test mail

Date: Mon, 10 Mar2014 18:49:16 +0800 (CST)

this is a test mail...

quit

+OK Logging out.

需要注意的幾點:

1,在安裝postfix之前,需要先停了sendmail服務,同樣的郵件軟體,占用的端口都是25,如果不停用,可能會導緻無法啟動postfix;

2,postfix是發送郵件的服務,dovecot是接收郵件的服務,兩個軟體合起來才能完成發送和接受的服務,是以需要完成兩個部分的安裝和配置;

3,在做測試的過程中,可以通過一個windows的用戶端,安裝foxmail軟體,在foxmail中建立賬戶,互發和接受信件,進行測試!

擴充:郵件伺服器的安全

本文轉自 murongqingqqq  51CTO部落格,原文連結:http://blog.51cto.com/murongqingqqq/1372049

繼續閱讀