1. 程式人生 > 實用技巧 >PostFix簡單配置

PostFix簡單配置

PostFix簡單配置 RHEL5.3 基本網路配置 一、 1、RHEL5 U3:如圖1 clip_p_w_picpath002 (如圖1) 2、#hostname //檢視當前主機的主機名:如圖2 clip_p_w_picpath003 (如圖2) 3、#vi /etc/sysconfig/network-scripts/ifcfg-eth0 編輯指定網路介面配置檔案:如圖3 clip_p_w_picpath005 (如圖3) 4、#vi /etc/sysconfig/network 通過配置檔案修改主機名:如圖4 clip_p_w_picpath007 (如圖4) 5、在終端字元介面修改其字型和中文字型大小:如圖5 clip_p_w_picpath009 (如圖5) 6、掛載光碟:如圖6 clip_p_w_picpath011 (如圖6) 7、檢視OpenSSH是否安裝:如圖7 clip_p_w_picpath013 (如圖7) 8#vi /etc/hosts 設定本地DNS
解析檔案:如圖8 clip_p_w_picpath015 (如圖8) 9#vi /etc/resolv.conf 指定當前主機的DNS伺服器,最多可指定三個:如圖9 clip_p_w_picpath017 (如圖9) 10、關閉iptables防火牆:如圖10 clip_p_w_picpath018 clip_p_w_picpath020 clip_p_w_picpath022 clip_p_w_picpath024 (如圖10) 二、DNS簡單配置 1、vim /etc/named.conf clip_p_w_picpath026 2、vim /var/named/benet.com.zone clip_p_w_picpath028 3、vim /var/named/1.168.192.in-addr.arpa.zone clip_p_w_picpath030 4、nslookup檢視 clip_p_w_picpath031 三、Postfix簡單配置 1、安裝Postfix (1)相關軟體包:Postfix (2)配置檔案:/etc/postfix/* (3)相關的埠: SMTP(25) (4)系統收到郵件儲存在/var/spool/mail/[linux使用者名稱]
(5)注意:安裝postfix-pflogsumm-2.3.3-2.1.el5_2.i386.rpm之前,需要安裝一下三個perl-Carp-Clan-5.3-1.2.1.noarch.rpm、 perl-Carp-Clan-5.3-1.2.1.noarch.rpm、 perl-Bit-Vector-6.4-2.2.2.1.i386.rpm [[email protected] Server]# ls postfix* postfix-2.3.3-2.1.el5_2.i386.rpm postfix-pflogsumm-2.3.3-2.1.el5_2.i386.rpm [[email protected]
Server]# rpm -ivh --aid postfix-2.3.3-2.1.el5_2.i386.rpm warning: postfix-2.3.3-2.1.el5_2.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186 Preparing... ########################################### [100%] 1:postfix ########################################### [100%] [[email protected] Server]# rpm -ivh --aid perl-Carp-Clan-5.3-1.2.1.noarch.rpm warning: perl-Carp-Clan-5.3-1.2.1.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 37017186 Preparing... ########################################### [100%] 1:perl-Carp-Clan ########################################### [100%] [[email protected] Server]# rpm -ivh --aid perl-Bit-Vector-6.4-2.2.2.1.i386.rpm warning: perl-Bit-Vector-6.4-2.2.2.1.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186 Preparing... ########################################### [100%] 1:perl-Bit-Vector ########################################### [100%] [[email protected] Server]# rpm -ivh --aid perl-Date-Calc-5.4-1.2.2.1.i386.rpm warning: perl-Date-Calc-5.4-1.2.2.1.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186 Preparing... ########################################### [100%] 1:perl-Date-Calc ########################################### [100%] [[email protected] Server]# rpm -ivh --aid postfix-pflogsumm-2.3.3-2.1.el5_2.i386.rpm warning: postfix-pflogsumm-2.3.3-2.1.el5_2.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186 Preparing... ########################################### [100%] 1:postfix-pflogsumm ########################################### [100%] [[email protected] Server]# rpm -qa | grep postfix postfix-pflogsumm-2.3.3-2.1.el5_2 postfix-2.3.3-2.1.el5_2 clip_p_w_picpath033 2、關閉sendmail並啟動postfix服務 [[email protected] Server]# chkconfig sendmail off [[email protected] Server]# chkconfig --level 2345 sendmail off [[email protected] Server]# chkconfig --list sendmail sendmail 0:關閉 1:關閉 2:關閉 3:關閉 4:關閉 5:關閉 6:關閉 [[email protected] Server]# service sendmail stop 關閉 sm-client: [確定] 關閉 sendmail: [確定] [[email protected] Server]# alternatives --config mta 共有 2 個程式提供“mta”。 選擇 命令 ----------------------------------------------- *+ 1 /usr/sbin/sendmail.sendmail 2 /usr/sbin/sendmail.postfix 按 Enter 來儲存當前選擇[+],或鍵入選擇號碼:2 [[email protected] Server]# echo "this is a test"|mail -s testmail root [[email protected] Server]# postdrop: warning: unable to look up public/pickup: No such file or directory [[email protected] Server]# chkconfig postfix on [[email protected] Server]# chkconfig --level 2345 postfix on [[email protected] Server]# chkconfig --list postfix postfix 0:關閉 1:關閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關閉 [[email protected] Server]# service postfix restart 關閉 postfix: [失敗] 啟動 postfix: [確定] clip_p_w_picpath035 3、給root發份郵件測試一下Postfix安裝是否成功 [[email protected] Server]# echo "this is a test"|mail -s testmail root [[email protected] Server]# mail Mail version 8.1 6/6/93. Type ? for help. "/var/spool/mail/root": 3 messages 3 new >N 1 [email protected] Mon Sep 21 04:04 112/3524 "Logwatch for dns (Lin" N 2 [email protected] Thu Oct 15 14:50 14/445 "testmail" N 3 [email protected] Thu Oct 15 14:50 14/445 "testmail" & 3 Message 3: From [email protected] Thu Oct 15 14:50:33 2009 X-Original-To: root Delivered-To: [email protected] To: [email protected] Subject: testmail Date: Thu, 15 Oct 2009 14:50:33 +0800 (CST) From: [email protected] (root) this is a test & quit Saved 1 message in mbox Held 2 messages in /var/spool/mail/root You have mail in /var/spool/mail/root clip_p_w_picpath037 4、檢視埠 [[email protected] Server]# netstat -ntla Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:688 0.0.0.0:* LISTEN tcp 0 0 192.168.1.200:53 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:2207 0.0.0.0:* LISTEN tcp 0 0 :::22 :::* LISTEN tcp 0 0 ::1:953 :::* LISTEN tcp 0 128 ::ffff:192.168.1.200:22 ::ffff:192.168.1.100:1410 ESTABLISHED clip_p_w_picpath039 5、配置postfix (1) 主配置檔案Vim /etc/postfix/main.cf的修改 1) 進入/etc/postfix目錄 [[email protected] Server]# cd /etc/postfix/ [[email protected] postfix]# ll 總計 296 -rw-r--r-- 1 root root 17832 2008-08-11 access -rw-r--r-- 1 root root 3550 2008-08-11 bounce.cf.default -rw-r--r-- 1 root root 11175 2008-08-11 canonical -rw-r--r-- 1 root root 9920 2008-08-11 generic -rw-r--r-- 1 root root 16838 2008-08-11 header_checks -rw-r--r-- 1 root root 11942 2008-08-11 LICENSE -rw-r--r-- 1 root root 26737 2008-08-11 main.cf -rw-r--r-- 1 root root 17981 2008-08-11 main.cf.default -rw-r--r-- 1 root root 958 2008-08-11 makedefs.out -rw-r--r-- 1 root root 4137 2008-08-11 master.cf -rw-r--r-- 1 root root 17639 2008-08-11 postfix-files -rwxr-xr-x 1 root root 6366 2008-08-11 postfix-script -rwxr-xr-x 1 root root 22564 2008-08-11 post-install -rw-r--r-- 1 root root 6805 2008-08-11 relocated -rw-r--r-- 1 root root 1629 2008-08-11 TLS_LICENSE -rw-r--r-- 1 root root 12081 2008-08-11 transport -rw-r--r-- 1 root root 11984 2008-08-11 virtual clip_p_w_picpath040 2) 修改postfix主配置檔案 main.cf ,現在我們要修改配置檔案了, 第一和第二個是設定主機名和域名69行和77行(分別為69行:mail.benet.com 77行benet.com) clip_p_w_picpath042 3) 修改93行 myorigin = $mydomain //去掉前面的#號 clip_p_w_picpath044 4)修改107行inet_interfaces=all //去掉前面的#,設定postfix監聽的介面,這裡使用監聽所有介面。修改110行#inet_interfaces=localhost //前面加上# clip_p_w_picpath046 5)修改155行mydestination=mail.benet.com,benet.com,localhost
//指定postfix接收郵件時收件人的域名所有可能引用的域名或著主機名都寫上。
clip_p_w_picpath048 6)修改255行192.168.1.0/24 //可轉發哪些網路的郵件,一般都只轉發信任網路的郵件 clip_p_w_picpath050 7)修改287行relay_domains = $mydomain //去掉前面的#,防止垃圾郵件的策略 clip_p_w_picpath052 8)重新啟動Postfix和vim /etc/mail/local-host-names clip_p_w_picpath053 四、dovecot簡單配置 1)功能:主要提供imap imaps pop3 pop3s服務。其中imaps pop3s是使用SSL來加密驗證和資料安全的伺服器 2)埠:110(pop3) 995(pop3s) 143(imap) 993(imaps) 3)相關配置檔案:/etc/dovecot.conf 1、Dovecot安裝(安裝之前先安裝這兩個perl-DBI-1.52-2.el5.i386.rpm、 mysql-5.0.45-7.el5.i386.rpm) [[email protected] Server]# rpm -ivh --aid perl-DBI-1.52-2.el5.i386.rpm warning: perl-DBI-1.52-2.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186 Preparing... ########################################### [100%] 1:perl-DBI ########################################### [100%] [[email protected] Server]# rpm -ivh --aid mysql-5.0.45-7.el5.i386.rpm warning: mysql-5.0.45-7.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186 Preparing... ########################################### [100%] 1:mysql ########################################### [100%] [[email protected] Server]# rpm -ivh --aid dovecot-1.0.7-7.el5.i386.rpm warning: dovecot-1.0.7-7.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186 Preparing... ########################################### [100%] 1:dovecot ########################################### [100%] clip_p_w_picpath055 2、修改20行,編輯主配置檔案Vim /etc/dovecot.conf(只要開啟對imap imaps pop3 pop3s協議的支援就可以) protocols = imap imaps pop3 pop3s //前面的#去掉 clip_p_w_picpath057 3、dovecot服務的啟動和檢視埠 [[email protected] Server]# chkconfig dovecot on [[email protected] Server]# service dovecot restart 停止 Dovecot Imap: [失敗] 啟動 Dovecot Imap: [確定] [[email protected] Server]# chkconfig --level 2345 dovecot on [[email protected] Server]# chkconfig --list dovecot dovecot 0:關閉 1:關閉 2:啟用 3:啟用 4:啟用 5:啟用 6:關閉 [[email protected] Server]# [[email protected] Server]# netstat -tulnp | grep 25 tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 3089/master [[email protected] Server]# netstat -ntla Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 127.0.0.1:2208 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:688 0.0.0.0:* LISTEN tcp 0 0 192.168.1.200:53 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:2207 0.0.0.0:* LISTEN tcp 0 0 :::993 :::* LISTEN tcp 0 0 :::995 :::* LISTEN tcp 0 0 :::110 :::* LISTEN tcp 0 0 :::143 :::* LISTEN tcp 0 0 :::22 :::* LISTEN tcp 0 0 ::1:953 :::* LISTEN tcp 0 0 ::ffff:192.168.1.200:22 ::ffff:192.168.1.100:1662 ESTABLISHED [[email protected] Server]# netstat -an | grep 25 tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN unix 2 [ ACC ] STREAM LISTENING 7325 /tmp/.font-unix/fs7100 unix 3 [ ] STREAM CONNECTED 11325 [[email protected] Server]# netstat -an | grep 110 tcp 0 0 :::110 :::* LISTEN [[email protected] Server]# netstat -an | grep 143 tcp 0 0 :::143 LISTEN unix 2 DGRAM 11435 clip_p_w_picpath059 4、測試相關埠25、110、143並新增使用者 [[email protected] Server]# telnet mail.benet.com 25 Trying 192.168.1.200... Connected to mail.benet.com (192.168.1.200). Escape character is '^]'. 220 dns.localdomain ESMTP Postfix ehlo mail.benet.com 250-dns.localdomain 250-PIPELINING 250-SIZE 10240000 250-VRFY 250-ETRN 250-ENHANCEDSTATUSCODES 250-8BITMIME 250 DSN quit 221 2.0.0 Bye Connection closed by foreign host. [[email protected] Server]# telnet mail.benet.com 110 Trying 192.168.1.200... Connected to mail.benet.com (192.168.1.200). Escape character is '^]'. +OK Dovecot ready. quit +OK Logging out Connection closed by foreign host. [[email protected] Server]# [[email protected] Server]# useradd zhangsan [[email protected] Server]# passwd zhangsan Changing password for user zhangsan. New UNIX password: BAD PASSWORD: it is based on a dictionary word Retype new UNIX password: passwd: all authentication tokens updated successfully. [[email protected] Server]# useradd lisi [[email protected] Server]# passwd lisi Changing password for user lisi. New UNIX password: BAD PASSWORD: it is based on a dictionary word Retype new UNIX password: passwd: all authentication tokens updated successfully. [[email protected] Server]# clip_p_w_picpath060 clip_p_w_picpath062 clip_p_w_picpath064 5、OE測試 clip_p_w_picpath065 clip_p_w_picpath067 五、實現郵局aliases別名功能:(這個和Sendmail基本相通,都是用/etc/aliases檔案) 1、編輯/etc/aliases:
1)格式:別名: 真實賬戶1,真實賬戶2,……
2)vim /etc/aliases
增加:test: zhangsan,lisi
當我們給別名賬戶傳送郵件時所有真實賬戶都可以收到,在我們的例子中,當我給[email protected]傳送郵件時,[email protected][email protected]都可以收到。(在最後一行96行新增test: zhangsan,lisi)
clip_p_w_picpath069
3
、執行newaliases命令,生成aliases庫。 clip_p_w_picpath070 4、重新啟動postfix服務。
5、通過客戶端測試別名:使用者收到郵件注意時間是否一樣
clip_p_w_picpath071 clip_p_w_picpath073 clip_p_w_picpath075 clip_p_w_picpath077 六、access訪問控制的實現及檢測(基本和sendmail相同) 1、修改postfix主配置檔案vim /etc/postfix/main.cf在最後增加如下內容:(開啟access檢測)
smtpd_clietn_restrictions=check_client_access hash:/etc/postfix/access
clip_p_w_picpath079 2、vim /etc/postfix/access(在最後一行新增) 我們禁止192.168.1.100 REJECT 使用postfix郵件服務 clip_p_w_picpath081 3修改了access後,需要使用這個命令更新資料庫。postmap /etc/postfix/access 然後重新啟動postfix clip_p_w_picpath083 4、OE測試 1)將客戶端的IP改成192.168.1.100再測試能否傳送 clip_p_w_picpath084 clip_p_w_picpath086 2)去掉限制#192.168.1.100 REJECT就可以正常傳送郵件 clip_p_w_picpath088 clip_p_w_picpath090 clip_p_w_picpath092 配置檔案在附件裡面: 如有不懂的地方,請call我!qq:357714938 mail:[email protected]