rh-1:DNS服务器

     rh-2:Mail服务器

     rh-3:linux客户机


前提:拥有DNS服务器。

    1)安装DNS软件。

     

[root@rh-1 ~]# yum -y install bind bind-chroot caching-nameserver

   2)配置服务器静态IP

[root@rh-1 ~]# ifconfig
  eth0      Link encap:Ethernet  HWaddr 52:54:00:AC:DE:C5 
          inet addr:192.168.122.229  Bcast:192.168.122.255  Mask:255.255.255.0

   3)编辑DNS主配置文件

 

[root@rh-1 ~]# cd  /var/named/chroot/etc/
[root@rh-1 etc]# cp -p named.caching-nameserver.conf named.conf
[root@rh-1 etc]# vim named.conf
15         listen-on port 53 { 192.168.122.229; };
27         allow-query     { any; };
28         allow-query-cache { any; };
37         match-clients      { any; };
38         match-destinations { any; };

 4)编辑DNS区域文件

 

[root@rh-1 etc]# cat named.rfc1912.zones | tail -4
zone "qq.com" IN {
type master;
file "qq.com.zone";
};

5)新建数据配置文件并配置数据文件

[root@rh-1 etc]# cd /var/named/chroot/var/named/
[root@rh-1 named]# cp -p named.local qq.com.zone
[root@rh-1 named]# vim qq.com.zone   注:无论服务器、客户机都要设DNS服务器,192.168.122.229
$TTL    86400
@       IN      SOA     localhost. root.localhost.  (
                                      2014042701 ; Serial
                                      28800      ; Refresh
                                      14400      ; Retry
                                      3600000    ; Expire
                                      86400 )    ; Minimum
        IN      NS      dns1.qq.com.
        IN      MX  5   mail.qq.com.
dns1      IN      A       192.168.122.229
mail      IN      A       192.168.122.242

 6)启动服务

[root@rh-1 named]# service named restart
[root@rh-1 named]# chkconfig named on
[root@rh-1 etc]# host -t mx qq.com                //检测DNS是否搭建成功
qq.com mail is handled by 5 mail.qq.com.

 

1、搭建邮箱服务器,在这里用postfix来搭建。

  1)安装邮件软件包

   

[root@rh-2 ~]# yum -y install postfix

  2)编辑postfix配置文件

[root@rh-2 postfix]# postconf -n > main.txt      
[root@rh-2 postfix]# mv main.cf main.cf.bak
[root@rh-2 postfix]# mv main.txt main.cf
[root@rh-2 postfix]# vim main.cf
   8 #inet_interfaces = localhost             //监听端口
   20 myhostname = rh-1                       /邮件服务器主机名
   21 mydomain = qq.com                      //邮件服务器所在区域
   22 mydestination = $mydomain              //指定Postfix允许处理的邮件
   23 myorigin = $mydomain                   //发件人DNS后缀
   24 home_mailbox = Maildir/                //邮箱类型

 3)停止现在占用25端口的服务

   

[root@rh-2 postfix]# netstat -tulnp | grep :25
   tcp    0   0 127.0.0.1:25   0.0.0.0:* 
  LISTEN    4079/sendmail 
[root@rh-2 postfix]# killall -9 sendmail
[root@rh-2 postfix]# chkconfig sendmail off

 4)启用postfix服务

 

[root@rh-2 postfix]# postfix check
[root@rh-2 postfix]# postfix start

 

 5)、在服务器上新建用户用以测试服务器是否搭载成功

 

[root@rh-2 postfix]# useradd a
[root@rh-2 postfix]# useradd b
[root@rh-2 postfix]# echo "123" | passwd --stdin b
[root@rh-2 postfix]# echo "123" | passwd --stdin a

 6)、在 客户机上检测(或服务器上也可以)

 

[root@rh-3 ~]# telnet mail.qq.com 25
Trying 192.168.122.242...
Connected to mail.qq.com (192.168.122.242).
Escape character is '^]'.
220 rh-1 ESMTP Postfix
mail from:a@qq.com                   //邮件来自
250 2.1.0 Ok
rcpt to:b@qq.com                     //邮件发往
250 2.1.5 Ok
data                                  //邮件正文
354 End data with <CR><LF>.<CR><LF>
wan shang lao di fang jian!
.                                    / /邮件结束
250 2.0.0 Ok: queued as 0C1FCC6DED
quit                                 //退出


    接收邮件要安装dovecot软件

 

[root@rh-3 ~]# yum -y install dovecot
[root@rh-3 ~]# service dovecot restart
[root@rh-3 ~]# chkconfig dovecot on       // 无需配置启动即可应用

    接收邮件

 

[root@rh-3 ~]# telnet mail.qq.com 110
Trying 192.168.122.242...
Connected to mail.qq.com (192.168.122.242).
Escape character is '^]'. 
+OK Dovecot ready.
user a           //输入账户
+OK
pass 123         //输入密码
+OK Logged in.
list            //列出邮件
+OK 1 messages:
1 458
.
retr 1           //查看邮件1

     查看日志,可以确定邮件发送是否成功:

 

[root@rh-2 postfix]# vim /var/log/maillog

 2 、 搭建webmail邮箱服务.

   1)安装squirrelmail软件

   

[root@rh-2 ~]# yum -y install   squirrelmail

   2)、配置squirrelmail服务。

 

[root@rh-2 ~]# vim /etc/httpd/conf.d/squirrelmail.conf
  26 $squirrelmail_default_language = 'zh_CN';
  29 $imapServerAddress      = '192.168.122.242';
  32 $smtpServerAddress      = '192.168.122.242';

  3)启用http服务,squirrelmail服务默认开启。

 

[root@rh-2 ~]# service httpd restart
[root@rh-2 ~]# chkconfig httpd on

 
在可以客户机上验证:
http://mail.qq.com/webmail]

3、为了增加邮件服务器的安全和垃圾邮件的产生要添加SMTP认证。

1)检查安装软件包(缺省已安装)

 

[root@rh-2 ~]# rpm -q cyrus-sasl

2)拷贝模板

 

[root@rh-2 ~]# cp /usr/lib64/sasl2/smtpd.conf /etc/sasl2/smtpd.conf
[root@rh-2 ~]# cat /etc/sasl2/smtpd.conf
pwcheck_method: saslauthd


3)编辑配置文件

   

[root@rh-2 ~]# vim /etc/postfix/main.cf
25 mynetworks = 127.0.0.1/ /设置本地网络
 26 smtpd_sasl_auth_enable = yes             //启用SASL认证
 27 smtpd_sasl_security_options = noanonymous//阻止匿名发信
 28 smtpd_recipient_restrictions =          //设置收件人过滤
 29  permit_mynetworks,                     //允许来自mynetworks的客户
 30  permit_sasl_authenticated,             //允许已通过sasl认证的用户
 31  reject_unauth_destination              //拒绝向未授权的目标域发信

4)启用服务

 

[root@rh-2 ~]# postfix start

5)验证:

 

[root@rh-3 ~]# telnet mail.qq.com 25
Trying 192.168.122.242...
Connected to mail.qq.com (192.168.122.242).
Escape character is '^]'.
220 mail.qq.com ESMTP Postfix
mail from:a@baidu.com
250 2.1.0 Ok
rcpt to:b@qq.con
554 5.7.1 <b@qq.con>: Relay access denied        //拒绝

   如果要登录,先在服务器端获取用户和

[root@rh-2 new]# printf "b" | openssl base64
Yg==
[root@rh-2 new]# printf "123" | openssl base64
MTIz


[root@rh-3 ~]# telnet mail.qq.com 25
Trying 192.168.122.242...
Connected to mail.qq.com (192.168.122.242).
Escape character is '^]'.
220 mail.qq.com ESMTP Postfix
helo localhost
250 mail.qq.com
auth login                                //声明要执行认证登录
334 VXNlcm5hbWU6
Yg==                                       //用户密文
334 UGFzc3dvcmQ6
MTIz                                      //密码密文
235 2.0.0 Authentication successful
mail from:bai.baidu.com
250 2.1.0 Ok
rcpt to:b@qq.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
good
.
250 2.0.0 Ok: queued as A7CFBC6E07
quit
[root@rh-3 ~]# telnet mail.qq.com 110
Trying 192.168.122.242...
Connected to mail.qq.com (192.168.122.242).
Escape character is '^]'.
+OK Dovecot ready.
user b
+OK
pass 123
+OK Logged in.
list
+OK 1 messages:
1 409
.
retr 1
+OK 409 octets
Return-Path: <bai.baidu.com@qq.com>
X-Original-To: b@qq.com
Delivered-To: b@qq.com
Received: from localhost (unknown [192.168.122.2])
by mail.qq.com (Postfix) with SMTP id A7CFBC6E07
for <b@qq.com>; Sun, 27 Apr 2014 12:45:47 +0800 (CST)
Message-Id: <20140427044708.A7CFBC6E07@mail.qq.com>
Date: Sun, 27 Apr 2014 12:45:47 +0800 (CST)
From: bai.baidu.com@qq.com
To: undisclosed-recipients:;
good
.