系統環境:
安裝郵件服務器,postfix+squirrelmail+rhat 5.4下測試,本實驗目的是,在服務器與客戶端之間相互收發郵件和轉發郵件;
系 統 |
域 名 |
服務器 |
客戶端 |
RedHat 5.4 |
mail.163.com |
172.16.1.253 |
172.16.1.10 |
所需安裝包:
bind (DNS)
postfix(郵件服務器)
Dovecot(POP/IMAP協議,用於接受郵件)
Saslauthd(安全認證包)
Squirrelmail(基於web的郵件客戶端)
1、配置IP
2、配置主機名:mail.163.com
[root@localhost ~]# vim /etc/sysconfig/network
HOSTNAME=mail.163.com
:wq 保存
[root@localhost ~]# hostname mail.163.com
斷開終端,再次連接,這樣就需要重新啓動系統:ctrl+d
[root@mail ~]#
3、配置DNS文件
[root@mail ~]# vim /etc/resolv.conf
nameserver 172.16.1.253
4、配置hosts文件
[root@mail ~]# vim /etc/hosts
127.0.0.1 mail.163.com
5、配置YUM
參照:
http://yanghuawu.blog.51cto.com/2638960/886129
6、安裝DNS(bind)
[root@mail ~]# cd /mnt/Server/
[root@mail Server]# rpm -ivh bind-9.3.6-4.P1.el5.i386.rpm
Preparing... ########################################### [100%]
1:bind ########################################### [100%]
[root@mail Server]# rpm -ivh bind-chroot-9.3.6-4.P1.el5.i386.rpm
Preparing... ########################################### [100%]
1:bind-chroot ########################################### [100%]
[root@mail Server]# rpm -ivh caching-nameserver-9.3.6-4.P1.el5.i386.rpm
Preparing... ########################################### [100%]
1:caching-nameserver ########################################### [100%]
[root@mail Server]# cd /var/named/chroot/etc/
[root@mail etc]# ll
total 32
-rw-r--r-- 1 root root 405 Dec 18 05:13 localtime
-rw-r----- 1 root named 1230 Jul 30 2009 named.caching-nameserver.conf
-rw-r----- 1 root named 955 Jul 30 2009 named.rfc1912.zones
-rw-r----- 1 root named 113 Dec 18 05:48 rndc.key
[root@mail etc]# cp -p named.caching-nameserver.conf named.conf
[root@mail etc]# vim named.conf
修改:
15 listen-on port 53 { any; };
27 allow-query { any; };
28 allow-query-cache { any; };
37 match-clients { any; };
38 match-destinations { any; };
:wq
[root@mail etc]# vim named.rfc1912.zones
27 zone "163.com" IN {
28 type master;
29 file "163.com.zone";
30 allow-update { none; };
31 };
:wq
[root@mail etc]# cd ../var/named/
[root@mail named]# pwd
/var/named/chroot/var/named
[root@mail named]# cp -p localhost.zone 163.com.zone
[root@mail named]# vim 163.com.zone
$TTL 86400
@ IN SOA ns.163.com. root (
42 ; serial (d. adams)
3H ; refresh
15M ; retry
1W ; expiry
1D ) ; minimum
IN NS ns.163.com.
ns IN A 172.16.1.253
mail IN A 172.16.1.253
pop3 IN CNAME mail
smtp IN CNAME mail
@ IN MX 10 mail
:wq
[root@mail named]# service named start
Starting named: [ OK ]
[root@mail named]# service named restart
Stopping named: [ OK ]
Starting named: [ OK ]
[root@mail named]#
[root@mail named]# rndc reload
server reload successful
[root@mail named]# dig -t mx 163.com
; <<>> DiG 9.3.6-P1-RedHat-9.3.6-4.P1.el5 <<>> -t mx 163.com
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10922
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
;; QUESTION SECTION:
;163.com. IN MX
;; ANSWER SECTION:
163.com. 86400 IN MX 10 mail.163.com.
;; AUTHORITY SECTION:
163.com. 86400 IN NS ns.163.com.
;; ADDITIONAL SECTION:
mail.163.com. 86400 IN A 172.16.1.253
ns.163.com. 86400 IN A 172.16.1.253
;; Query time: 5 msec
;; SERVER: 172.16.1.253#53(172.16.1.253)
;; WHEN: Tue Dec 18 06:12:41 2012
;; MSG SIZE rcvd: 95
[root@mail named]# chkconfig named on
確認sendmail是否已關閉,並不隨機啓動或者卸載
[root@mail named]# service sendmail status
sendmail (pid 2754) is running...
[root@mail named]# service sendmail stop
Shutting down sm-client: [ OK ]
Shutting down sendmail: [ OK ]
[root@mail named]# chkconfig sendmail off
[root@mail named]#
7、安裝postfix
[root@mail named]# cd /mnt/Server/
[root@mail Server]# ll postfix*
-r--r--r-- 278 root root 3734257 Aug 14 2008 postfix-2.3.3-2.1.el5_2.i386.rpm
-r--r--r-- 278 root root 51012 Aug 14 2008 postfix-pflogsumm-2.3.3-2.1.el5_2.i386.rpm
[root@mail Server]# rpm -ivh postfix-2.3.3-2.1.el5_2.i386.rpm
Preparing... ########################################### [100%]
1:postfix ########################################### [100%]
[root@mail Server]# vim /etc/postfix/main.cf
69 #myhostname = host.domain.tld
修改
69 myhostname = mail.163.com #本機名
77 #mydomain = domain.tld
修改:
77 mydomain = 163.com #域名
93 #myorigin = $mydomain
修改爲
93 myorigin = $mydomain
107 #inet_interfaces = all
修改爲
107 inet_interfaces = all
110 inet_interfaces = localhost
修改爲
110 #inet_interfaces = localhost
155 mydestination = $myhostname, localhost.$mydomain, localhost
修改爲
155 #mydestination = $myhostname, localhost.$mydomain, localhost
156 #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
修改爲
156 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
255 #mynetworks = 168.100.189.0/28, 127.0.0.0/8
修改爲
255 mynetworks = 127.0.0.0/8 #提供郵件轉發功能的網段
在255 mynetworks = 127.0.0.0/8上面添加如下:#使用SMTP認證
broken_sasl_auth_clients = yes
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_application_name = smtpd
smtpd_client_restrictions = permit_sasl_authenticated,reject
#smtpd_clietn_restrictions = permit_sasl_authenticated
smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated, reject_unauth_destination
262 mynetworks = 127.0.0.0/8
:wq
[root@mail Server]# service saslauthd start
Starting saslauthd: [ OK ]
[root@mail Server]# chkconfig saslauthd on
[root@mail Server]# service postfix start
Starting postfix: [ OK ]
[root@mail Server]# service postfix restart
Shutting down postfix: [ OK ]
Starting postfix: [ OK ]
[root@mail Server]# netstat -tupln |less
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 4235/master
8、創建用戶
[root@mail Server]# useradd user1
[root@mail Server]# useradd user2
[root@mail Server]# useradd user3
[root@mail Server]# passwd user1
Changing password for user user1.
New UNIX password:
BAD PASSWORD: it does not contain enough DIFFERENT characters
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@mail Server]# passwd user2
Changing password for user user2.
New UNIX password:
BAD PASSWORD: it does not contain enough DIFFERENT characters
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@mail Server]# passwd user3
Changing password for user user3.
New UNIX password:
BAD PASSWORD: it does not contain enough DIFFERENT characters
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
9、安裝squirrelmail(圖形化郵件客戶端)
[root@mail Server]# yum install squirrelmail
[root@mail Server]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using mail.163.com for ServerName
[ OK ]
[root@mail Server]# chkconfig httpd on
[root@mail Server]# rpm -ql squirrelmail
[root@mail Server]# cd /var/www/html/
[root@mail html]# ln -s /usr/share/squirrelmail/ mail
[root@mail html]# ll
total 4
lrwxrwxrwx 1 root root 24 Dec 18 06:46 mail -> /usr/share/squirrelmail/
[root@mail html]# cd mail/
[root@mail mail]# ll
total 88
drwxr-xr-x 5 root root 4096 Dec 18 06:42 class
drwxr-xr-x 2 root root 4096 Dec 18 06:42 config
drwxr-xr-x 4 root root 4096 Dec 18 06:42 functions
drwxr-xr-x 30 root root 4096 Dec 18 06:42 help
drwxr-xr-x 2 root root 4096 Dec 18 06:42 p_w_picpaths
drwxr-xr-x 3 root root 4096 Dec 18 06:42 include
-rw-r--r-- 1 root root 684 May 21 2009 index.php
drwxr-xr-x 47 root root 4096 Dec 18 06:42 locale
drwxr-xr-x 18 root root 4096 Dec 18 06:42 plugins
drwxr-xr-x 2 root root 4096 Dec 18 06:42 src
drwxr-xr-x 3 root root 4096 Dec 18 06:42 themes
[root@mail mail]# cd config/
[root@mail config]# ll
total 204
-rw-r--r-- 1 root root 29548 May 21 2009 config_default.php
lrwxrwxrwx 1 root root 45 Dec 18 06:42 config_local.php -> ../../../../etc/squirrelmail/config_local.php
lrwxrwxrwx 1 root root 39 Dec 18 06:42 config.php -> ../../../../etc/squirrelmail/config.php
-rwxr-xr-x 1 root root 145648 May 21 2009 conf.pl
-rw-r--r-- 1 root root 492 May 21 2009 index.php
打開squirrelmail配置工具
[root@mail config]# ./conf.pl 或[root@mail ~]# /usr/share/squirrelmail/config/conf.pl
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1. Organization Preferences
2. Server Settings
3. Folder Defaults
4. General Options
5. Themes
6. Address Books
7. Message of the Day (MOTD)
8. Plugins
9. Database
10. Languages
D. Set pre-defined settings for specific IMAP servers
C Turn color off
S Save data
Q Quit
Command >> 10
輸入d,然後輸入cyrus(指定IMAP服務器類型)
輸入2. 選擇Server Settings然後輸入1修改Domain爲mail.163.com
3修改Sendmail or SMTP爲選2--SMTP
輸入4. 選擇General Options然後輸入5修改Usernames in Lowercase :爲 true
輸入10 選擇Languages然後輸入1修改Default Language :爲 zh_CN
2修改Default charset :爲 GB2312
R返回上一層
最後輸入s保存以上修改,再輸入q退出(修改的文件同時保存)
[root@mail config]# vim /etc/httpd/conf/httpd.conf
747 AddDefaultCharset UTF-8
修改爲:
747 #AddDefaultCharset UTF-8
:wq
[root@mail config]# service httpd restart
10、網頁訪問:http://172.16.1.253/mail
用戶登陸報錯
系統出錯
連接IMAP服務器出現錯誤:localhost。
111 : 鎷掔粷榪炴帴
解決方法
[root@mail config]# yum install dovecot #用於接受郵件
[root@mail config]# service dovecot restart
重新登錄:OK
發郵件報錯
系統出錯:
Transaction failed
Server replied: 554 5.7.1 <localhost.localdomain[127.0.0.1]>: Client host rejected: Access denied
解決方法:
[root@mail config]# vim /etc/postfix/main.cf
smtpd_client_restrictions = permit_sasl_authenticated,reject
修改爲
#smtpd_client_restrictions = permit_sasl_authenticated,reject
:wq
[root@mail config]# service postfix restart
11、查看收發郵件日誌
[root@mail config]# tail -f /var/log/maillog
收發郵件成功!