题目:两个不同网段的邮件服务可以通过DNS解析互发邮件

 

 

DNS :eth0 192.168.18.103 

      eth1 192.168.17.103

邮件服务器1:   mail.vfast.com 192.168.18.104

邮件服务器2:   mail.haha.com 192.168.17.106

 

DNS:

[root@localhost ~]# echo > 1 /proc/sys/net/ipv4/ip_forward 

[root@localhost ~]# vim /etc/sysctl.conf 

[root@localhost ~]# sysctl -p

net.ipv4.ip_forward = 1

net.ipv4.conf.default.rp_filter = 1

net.ipv4.conf.default.accept_source_route = 0

kernel.sysrq = 0

kernel.core_uses_pid = 1

net.ipv4.tcp_syncookies = 1

kernel.msgmnb = 65536

kernel.msgmax = 65536

kernel.shmmax = 4294967295

kernel.shmall = 268435456

[root@localhost ~]# service network restart

正在关闭接口 eth0:                                        [确定]

正在关闭接口 eth1:                                        [确定]

关闭环回接口:                                             [确定]

禁用 IPv4 包转送: net.ipv4.ip_forward = 0

                                                           [确定]

弹出环回接口:                                             [确定]

弹出界面 eth0:                                            [确定]

弹出界面 eth1:                                            [确定]

 

[root@localhost ~]# yum install bind*

 

[root@localhost ~]# vim /var/named/chroot/etc/named.conf

options {

      directory   "/var/named";

};

zone "vfast.com"{

      type   master;

      file   "vfast.com.zone";

};

zone "haha.com"{

      type    master;

      file    "haha.com.zone";

};

 

[root@localhost ~]# cp /usr/share/doc/bind-9.3.6/sample/var/named/localhost.zone /var/named/chroot/var/named/vfast.com.zone 

[root@localhost ~]# vim /var/named/chroot/var/named/vfast.com.zone

$TTL    86400

@               IN SOA  @       root (

                                        42              ; serial (d. adams)

                                        3H              ; refresh

                                        15M             ; retry

                                        1W              ; expiry

                                        1D )            ; minimum

vfast.com.      IN  NS   mail.vfast.com.

mail.vfast.com.  IN  A    192.168.18.104

vfast.com.       IN  MX  10  mail.vfast.com.

haha.com.        IN  NS   mail.haha.com.

mail.haha.com.   IN  A    192.168.17.106

mail.haha.com.   IN  MX  19  mail.haha.com.

 

[root@localhost ~]# cp /usr/share/doc/bind-9.3.6/sample/var/named/localhost.zone /var/named/chroot/var/named/haha.com.zone

[root@localhost ~]# vim /var/named/chroot/var/named/haha.com.zone 

$TTL    86400

@               IN SOA  @       root (

                                        42              ; serial (d. adams)

                                        3H              ; refresh

                                        15M             ; retry

                                        1W              ; expiry

                                        1D )            ; minimum

 

vfast.com.       IN   NS    mail.vfast.com.

mail.vfast.com.  IN   A     192.168.18.104

vfast.com.       IN   MX 10 mail.vfast.com.

haha.com.        IN   NS    mail.haha.com.

mail.haha.com.   IN   A     192.168.17.106

haha.com.        IN   MX 10 mail.haha.com.

 

 

[root@localhost ~]# echo "" > /etc/hosts

[root@localhost ~]# cat /etc/hosts

 

[root@localhost ~]# service named restart

停止 named:                                               [确定]

启动 named:                                               [确定]

 

[root@localhost ~]# echo "" > /etc/resolv.conf 

[root@localhost ~]# host  mail.vfast.com

mail.vfast.com has address 192.168.18.104

[root@localhost ~]# host  mail.vfast.com

mail.vfast.com has address 192.168.18.104

 

 

 

邮件服务器1:

[root@localhost ~]# route add default gw 192.168.18.103

[root@localhost ~]# service network restart

正在关闭接口 eth0:                                        [确定]

关闭环回接口:                                             [确定]

弹出环回接口:                                             [确定]

弹出界面 eth0:                                            [确定]

 

[root@localhost ~]# service sendmail status

sendmail 已停

[root@localhost ~]# chkconfig sendmail off

[root@localhost ~]# vim /etc/resolv.conf

nameserver   192.168.18.103

 

[root@localhost ~]# rpm -qa | grep postfix

postfix-2.3.3-2.1.el5_2

[root@localhost ~]# vim /etc/postfix/main.cf

 

      myhostname = mail.vfast.com

      mydomain = vfast.com

      myorigin = $mydomain

      inet_interfaces = all

      mydestination = $myhostname, $mydomain, 

      mynetworks = 192.168.18.0/24, 192.168.17.0/24, 127.0.0.0/8

      relay_domains = vfast.com, haha.com   

      mailbox_transport = lmtp:unix:/var/lib/imap/socket/lmtp    

末尾加:

smtpd_sasl_auth_enable = yes

smtpd_sasl_local_domain = ''

smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination

broken_sasl_auth_clients = yes

smtpd_client_restrictions = permit_sasl_authenticated

smtpd_sasl_security_options = noanonymous

 

[root@localhost ~]# service postfix restart

关闭 postfix:                                             [失败]

启动 postfix:                                             [确定]

 

 

安装dovecot:

[root@localhost ~]# yum install dovecot -y

修改配置文件:

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

protocols = pop3 pop3s

protocol imap {

    listen = *:10143

    ssl_listen = *:10943

#     ..

}

启动:

[root@mail ~]# /etc/init.d/dovecot start

启动 Dovecot Imap:                                        [确定]

[root@localhost ~]# chkconfig dovecot on

 

[root@localhost ~]# yum install cyrus-imapd cyrus-imapd-devel -y

 

[root@localhost ~]# /etc/init.d/cyrus-imapd start

导入 cyrus-imapd 数据库:                                  [确定]

启动 cyrus-imapd:                                         [确定]

 

[root@localhost ~]# chkconfig cyrus-imapd on

[root@localhost ~]# service postfix restart

关闭 postfix:                                             [确定]

启动 postfix:                                             [确定]

 

[root@localhost ~]# telnet mail.haha.com 25

Trying 192.168.17.106...

Connected to mail.haha.com (192.168.17.106).

Escape character is '^]'.

220 mail.haha.com ESMTP Postfix

ehlo mail.haha.com

250-mail.haha.com

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-AUTH PLAIN LOGIN

250-AUTH=PLAIN LOGIN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

^]

 

telnet> quit

Connection closed.

 

[root@localhost ~]# vim /etc/sysconfig/saslauthd 

MECH=shadow

 

[root@localhost ~]# service saslauthd restart

停止 saslauthd:                                           [失败]

启动 saslauthd:                                           [确定]

[root@localhost ~]# chkconfig saslauthd on

 

[root@localhost ~]# useradd abc

[root@localhost ~]# passwd abc

Changing password for user abc.

New UNIX password: 

BAD PASSWORD: it is WAY too short

Retype new UNIX password: 

passwd: all authentication tokens updated successfully.

[root@localhost ~]# testsaslauthd -u abc -p "abc"

0: OK "Success."

[root@localhost ~]# service postfix restart

关闭 postfix:                                             [确定]

启动 postfix:                                             [确定]

[root@localhost ~]# cyradm -u cyrus localhost

IMAP Password: 

              localhost.localdomain> cm user.abc

localhost.localdomain> quit

 

[root@localhost ~]# yum install squirrelmail -y

[root@localhost ~]# /usr/share/squirrelmail/config/conf.pl

修改默认的IMAP服务:d--->cryus--->

修改服务器设置:2--->1(设置域名)--->vfast.com---->3(选择邮件类型)--->2(smtp)---->r(进入主菜单)----4(设置区分大小写)----->5---->---y----r(返回)--->10(修改字符编码)----->1--->zh_CN--->2----->gb2312---->s---->q

 

 

 

邮件服务器2:

[root@localhost ~]# route add default gw 192.168.17.103

[root@localhost ~]# service network restart

正在关闭接口 eth0:                                        [确定]

关闭环回接口:                                             [确定]

弹出环回接口:                                             [确定]

弹出界面 eth0:                                            [确定]

[root@localhost ~]# service sendmail status

sendmail 已停

[root@localhost ~]# chkconfig sendmail off

[root@localhost ~]# vim /etc/resolv.conf 

nameserver   192.168.17.103

 

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

[root@localhost ~]# vim /etc/postfix/main.cf

 

       myhostname = mail.haha.com

       mydomain = haha.com

       myorigin = $mydomain

       inet_interfaces = all

       mydestination = $myhostname, $mydomain, 

       mynetworks = 192.168.18.0/24, 192.168.17.0/24, 127.0.0.0/8

       relay_domains = vfast.com, haha.com   

       mailbox_transport = lmtp:unix:/var/lib/imap/socket/lmtp    

 

smtpd_sasl_auth_enable = yes

smtpd_sasl_local_domain = ''

smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination

broken_sasl_auth_clients = yes

smtpd_client_restrictions = permit_sasl_authenticated

smtpd_sasl_security_options = noanonymous

 

安装dovecot:

[root@localhost ~]# yum install dovecot -y

修改配置文件:

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

protocols = pop3 pop3s

protocol imap {

    listen = *:10143

    ssl_listen = *:10943

#     ..

}

启动:

[root@mail ~]# /etc/init.d/dovecot start

启动 Dovecot Imap:                                        [确定]

[root@localhost ~]# chkconfig dovecot on

 

[root@localhost ~]# yum install cyrus-imapd cyrus-imapd-devel -y

 

[root@localhost ~]# /etc/init.d/cyrus-imapd start

导入 cyrus-imapd 数据库:                                  [确定]

启动 cyrus-imapd:                                         [确定]

 

[root@localhost ~]# chkconfig cyrus-imapd on

[root@localhost ~]# service postfix restart

关闭 postfix:                                             [确定]

启动 postfix:                                             [确定]

 

[root@localhost ~]# telnet mail.haha.com 25

Trying 192.168.17.106...

Connected to mail.haha.com (192.168.17.106).

Escape character is '^]'.

220 mail.haha.com ESMTP Postfix

ehlo mail.haha.com

250-mail.haha.com

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-AUTH PLAIN LOGIN

250-AUTH=PLAIN LOGIN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

^]

 

telnet> quit

Connection closed.

 

[root@localhost ~]# vim /etc/sysconfig/saslauthd 

MECH=shadow

 

[root@localhost ~]# service saslauthd restart

停止 saslauthd:                                           [失败]

启动 saslauthd:                                           [确定]

[root@localhost ~]# chkconfig saslauthd on

 

[root@localhost ~]# useradd abc

[root@localhost ~]# passwd abc

Changing password for user abc.

New UNIX password: 

BAD PASSWORD: it is WAY too short

Retype new UNIX password: 

passwd: all authentication tokens updated successfully.

[root@localhost ~]# testsaslauthd -u abc -p "abc"

0: OK "Success."

[root@localhost ~]# service postfix restart

关闭 postfix:                                             [确定]

启动 postfix:                                             [确定]

[root@localhost ~]# cyradm -u cyrus localhost

IMAP Password: 

              localhost.localdomain> cm user.abc

localhost.localdomain> quit

 

[root@localhost ~]# yum install squirrelmail -y

[root@localhost ~]# /usr/share/squirrelmail/config/conf.pl

 

修改默认的IMAP服务:d--->cryus--->

修改服务器设置:2--->1(设置域名)--->vfast.com---->3(选择邮件类型)--->2(smtp)---->r(进入主菜单)----4(设置区分大小写)----->5---->---y----r(返回)--->10(修改字符编码)----->1--->zh_CN--->2----->gb2312---->s---->q

 

 

测试:在邮件服务器1上,用abc@vfast.com给abc@haha.com发一封邮件,到邮件服务器2上查看,反之再回复一封,在查看