1.安装dns

1.1 安装包

[root@mail ~]# yum install bind 

[root@mail ~]# yum install bind-chroot –改变dns的路径,保证安全的包

[root@mail ~]# yum install caching-nameserver –y –生成配置文件,提高caching server

[root@mail ~]# yum list all |grep bind

This system is not registered with RHN.

RHN support will be disabled.

bind.i386                              30:9.3.4-10.P1.el5    installed          

bind-chroot.i386                       30:9.3.4-10.P1.el5    installed          

bind-libs.i386                         30:9.3.4-10.P1.el5    installed          

bind-utils.i386                        30:9.3.4-10.P1.el5    installed          

ypbind.i386                            3:1.19-11.el5         installed      

 

1.2 配置

[root@mail ~]# cd /var/named/chroot/etc

[root@mail etc]# cp -p named.caching-nameserver.conf named.conf

[root@mail etc]# vim named.conf

options {

        listen-on port 53 { any; };

        allow-query     { any; };

};

view localhost_resolver {

        match-clients      { any; };

        match-destinations { any; };

        include "/etc/named.rfc1912.zones";

};

1.3声明区域

 

[root@mail etc]# vim named.rfc1912.zones

zone "bj.com" IN {

        type master;

        file "bj.com.db";

        allow-update { none; };

};

 

1.4产生数据库文件

[root@mail named]# cp -p localhost.zone bj.com.db

[root@mail named]# vim bj.com.db 

$TTL    86400

@               IN SOA  ns.bj.com.       root.126.com (

                                        42              ; serial (d. adams)

                                        3H              ; refresh

                                        15M             ; retry

                                        1W              ; expiry

                                        1D )            ; minimum

 

                IN NS           ns.bj.com.

ns              IN A            192.168.101.70

mail            IN A            192.168.101.70

pop3            IN CNAME        mail

smtp            IN CNAME        mail

imap            IN CNAME        mail

@               IN MX      10   mail

1.5 dns指向

[root@mail etc]# vim /etc/resolv.conf 

#search localdomain

nameserver 192.168.101.70

[root@mail named]# vim /etc/sysconfig/network

NETWORKING=yes

HOSTNAME=mail.bj.com

[root@mail etc]# vim /etc/hosts

127.0.0.1               localhost.localdomain localhost

192.168.101.70  mail.bj.com

--更改主机名

1.6 开启服务 解析

[root@mail named]# 

[root@mail named]# service named start

Starting named:                                            [  OK  ]

[root@mail named]# chkconfig named on

[root@mail named]# rndc reload

server reload successful

[root@mail etc]# nslookup mail.bj.com

Server:     192.168.101.70

Address:    192.168.101.70#53

 

Name:   mail.bj.com

Address: 192.168.101.70

 

[root@mail etc]# dig    -t mx bj.com

 

; <<>> DiG 9.3.4-P1 <<>> -t mx bj.com

;; global options:  printcmd

;; Got answer:

;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 24728

;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2

 

;; QUESTION SECTION:

;bj.com.                        IN      MX

 

;; ANSWER SECTION:

bj.com.         86400   IN      MX      10 mail.bj.com.

 

;; AUTHORITY SECTION:

bj.com.         86400   IN      NS      ns.bj.com.

 

;; ADDITIONAL SECTION:

mail.bj.com.            86400   IN      A       192.168.101.70

ns.bj.com.      86400   IN      A       192.168.101.70

 

;; Query time: 1 msec

;; SERVER: 192.168.101.70#53(192.168.101.70)

;; WHEN: Sun Sep  4 16:59:01 2011

;; MSG SIZE  rcvd: 94

[root@mail etc]#

 

 

2.Sendmail 需要的包

2.1需要安装的包

Sendmail-8.13.8。-2.el5 –主包

Sendmai-cf          --生成易配置或快速配置的配置文件

Sendmail-devel   --开发包

m4.i386                                1.4.5-3.el5.1               --转换工具

--重启m4会自动转换

--sendmail.mc—>sendmail.cf

-- accessaccess.db

[root@mail ~]# yum list all |grep sendmail

This system is not registered with RHN.

RHN support will be disabled.

sendmail.i386                          8.13.8-2.el5          installed          

sendmail-cf.i386                       8.13.8-2.el5          installed          

sendmail-devel.i386                    8.13.8-2.el5          installed          

sendmail-doc.i386                      8.13.8-2.el5          installed   

[root@mail ~]# yum list all |grep m4      

This system is not registered with RHN.

RHN support will be disabled.

m4.i386                                1.4.5-3.el5.1         installed          

[root@mail ~]#

 

 

 

2.2配置监听

更改sendmail.mc

[root@mail mail]# pwd

/etc/mail

[root@mail mail]# vim sendmail.mc

116 DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnl

--默认是本机监听25号端口,需要更改才能使非本地用户使用sendmail发送邮件

--Dnl # 是注视文字

--Dnl 是打开可以使用的

--末尾dnl 去除空格

[root@mail mail]# service sendmail restart

[root@mail mail]# netstat -tunpl |grep 25

tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      30569/sendmail: acc

--添加本地用户

[root@mail etc]# useradd user1

[root@mail etc]# useradd user2

[root@mail etc]# passwd user1

[root@mail etc]# passwd user2

--可以通过日志文件查看错误

[root@mail ~]# vim /etc/syslog.conf

# Log all the mail messages in one place.

mail.*                                                  -/var/log/maillog

 

2.3本地发送接收邮件

[root@mail mail]# mail user1

Subject: uu

ws

.

Cc: 

You have new mail in /var/spool/mail/root

[root@mail mail]# ll /var/spool/mail/

total 24

-rw-rw---- 1 redhat mail    0 Aug 27 14:35 redhat

-rw------- 1 root   root 7153 Sep  4 17:30 root

-rw-rw---- 1 rpc    mail    0 Aug 27 22:21 rpc

-rw------- 1 user1  mail 1693 Sep  4 17:30 user1

-rw-rw---- 1 user2  mail  575 Sep  4 17:30 user2

[user1@mail ~]$ mail

Mail version 8.1 6/6/93.  Type ? for help.

"/var/spool/mail/user1": 3 messages 3 new

>N  1 root@mail.bj.com      Sun Sep  4 17:30  17/565   "e"

 N  2 root@mail.bj.com      Sun Sep  4 17:30  16/565   "u"

 N  3 root@mail.bj.com      Sun Sep  4 17:30  16/563   "1"

& 1

Message 1:

From root@mail.bj.com  Sun Sep  4 17:30:56 2011

Date: Sun, 4 Sep 2011 17:18:47 +0800

From: root <root@mail.bj.com>

To: user1@mail.bj.com

Subject: e

 

e

 .

 

& 2

 

 

[root@mail mail]# tail /var/log/maillog

Sep  4 17:30:56 localhost sendmail[30570]: p849UuLM030570: to=<root@mail.bj.com>, delay=00:00:00, xdelay=00:00:00, mailer=local, pri=31521, dsn=2.0.0, stat=Sent

Sep  4 17:30:56 localhost sendmail[30570]: p849BPv9030362: to=<user2@mail.bj.com>, ctladdr=<root@mail.bj.com> (0/0), delay=00:19:31, xdelay=00:00:00, mailer=local, pri=300303, dsn=2.0.0, stat=Sent

--如果sendmail.mc 116 DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA,M=Ea')dnl

--会报错发送不出去mail

Sep  4 17:31:08 localhost sendmail[30587]: p849V8Ni030587: from=root, size=26, class=0, nrcpts=1, msgid=<201109040931.p849V8Ni030587@mail.bj.com>, relay=root@localhost

Sep  4 17:31:08 localhost sendmail[30587]: p849V8Ni030587: to=user1, ctladdr=root (0/0), delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30026, relay=[127.0.0.1] [127.0.0.1], dsn=5.0.0, stat=Service unavailable

 

3.安装MAA

需要安装dovecot开启pop3才可以发送接收邮件

否则出错

 

3.1安装dovecot

[root@mail ~]# yum install dovecot

 

 

--Package dovecot-1.0.7-7.el5.i386 already installed and latest version

 

3.2 更改配置文件

[root@mail ~]# rpm -qc dovecot

/etc/dovecot.conf

 

 

[root@mail ~]# vim /etc/dovecot.conf 

  20 #protocols = imap imaps pop3 pop3s

 --默认全开

  22 protocols = pop3 

[root@mail ~]# netstat -tupln |grep 25

tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      4659/sendmail: acce 

udp        0      0 :::43725                    :::*                                    3191/avahi-daemon:  

[root@mail ~]# netstat -tupln |grep dov

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

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

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

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

[root@mail ~]# grep 993 /etc/services

imaps           993/tcp                         # IMAP over SSL

imaps           993/udp                         # IMAP over SSL

imap4-ssl       585/tcp                         # IMAP4+SSL (use 993 instead)

imap4-ssl       585/udp                         # IMAP4+SSL (use 993 instead)

 

 

[root@mail ~]# grep 995 /etc/services

pop3s           995/tcp                         # POP-3 over SSL

pop3s           995/udp                         # POP-3 over SSL

 

 

[root@mail ~]# service dovecot restart

 

 

 

 

[root@mail ~]# chkconfig dovecot on

3.3客户端使用sendmail发送接收mail

1. 配置outlook

 

[root@mail ~]# mail user1 

Subject: hhh

gfgfg

.

Cc: 

 

27-4

3.4使用Outlook发信

 

 


 

 

3.5telnet发送邮件

[root@mail ~]# telnet mail.bj.com 25

-----中间输入出错可以使用shift+esc+backspace退格。 

Trying 192.168.101.70...

Connected to mail.bj.com (192.168.101.70).

Escape character is '^]'.

220 mail.bj.com ESMTP Sendmail 8.13.8/8.13.8; Thu, 15 Sep 2011 16:54:23 +0800

help

214-2.0.0 This is sendmail

214-2.0.0 Topics:

214-2.0.0       HELO    EHLO    MAIL    RCPT    DATA

214-2.0.0       RSET    NOOP    QUIT    HELP    VRFY

214-2.0.0       EXPN    VERB    ETRN    DSN     AUTH

214-2.0.0       STARTTLS

214-2.0.0 For more info use "HELP <topic>".

214-2.0.0 To report bugs in the implementation see

214-2.0.0       http://www.sendmail.org/email-addresses.html

214-2.0.0 For local information send email to Postmaster at your site.

214 2.0.0 End of HELP info

helo mail.bj.com

250 mail.bj.com Hello mail.bj.com [192.168.101.70], pleased to meet you

mail from: user1@mail.bj.com

250 2.1.0 user1@mail.bj.com... Sender ok

rcpt to :user2@mail.bj.com                            

250 2.1.5 user2@mail.bj.com... Recipient ok

data

354 Enter mail, end with "." on a line by itself

subject

hello user2.this is user1.

.

250 2.0.0 p8F8sNcf032532 Message accepted for delivery

quit  

221 2.0.0 mail.bj.com closing connection

Connection closed by foreign host.

[root@mail ~]#