第一章、概述
1、邮件服务通常使用什么协议?
SMTP:简单邮件传输协议,只实现传输功能,没有索引、加密邮件功能。ESMTP,SMTP的升级版本,可以实现身份检测功能了。
POP3:;post office protocol 邮局协议
IMAP4:互联网访问协议
SASL:邮件认证协议
2、邮件服务的发展简史。
早期unix之间的通信协议是UUCP协议(unix to unix copy,主机间复制文件协议)。后来出现了smtp,smtp具有路由功能,可以依据邮件的目的地址来通过邮件中继器进行转发后最终到达目的地址。
发邮件过程:
1、首先需要客户端之间要有邮件服务器,邮件服务器就是类似@163.com这个域空间的邮件服务器,在dns服务器上通过mx来进行配置。
2、客户端发送一封署名为jerry@a.org收件人的邮件,邮件客户端将邮件发送到本地的邮件服务器上。
3、服务器通过收件人地址,确定收件人在a.org服务器上,于是通过dns进行解析确定谁是a.org的邮件服务器,dns的mx记录就是邮件服务器的解析主机名。
4、通过解析获得ip地址,通过smtp协议传输邮件信息。于是将发送给jerry@a.org的邮件发送到jerry的邮件服务器上,那么我们现在权当邮件服务器为mail.a.org这台主机。
5、mail.a.org收到邮件后,确定jerr@a.org是否存在,如果不存在通常会有反馈信息,如果存在就将邮件存入相应的用户目录或数据库中。此时将用户邮件投递到用户客户端上使用的是邮件投递协议MD。
6、jerry通过登录邮件服务器(web方式、或者outlook)获取邮件信息。
邮件传输(MT):邮件流动在邮件服务器和邮件服务器之间的情况称为邮件传输,使用的协议是smtp。
邮件投递 (MD):邮件工作在邮件服务器和邮件客户端之间的情况,称为邮件投递。
MUA:mail user agent 类似的有outlook,foxmail、thunderbird、evolution、mutt邮件终端软件。
MTA:mail transfer agent 邮件服务器 类似exchange、postfix,sendmail(鼻祖)
MDA:邮件投递代理,实现邮件投递功能的软件或者设备。比如exchange的procmail,maildrop,
邮件中继:由于smtp协议的特点,邮件服务器作为邮件中继会将发送到他这里的邮件(不是自己的)无条件的转发出去,这样也就造成了垃圾邮件的产生。
open relay:开放式中继,无条件转发。
MRA:邮件检索(取回)代理,使用的是pop3协议或者imap4,功能就是实现帮助客户端收取邮件服务器邮件功能的协议。现实中使用的程序包括cyrus-imap,dovecot。
LDAP:轻量级目录访问协议,适用于存储用户账户信息,一次写入多次读取的情况。
虚拟用户:仅用于访问某服务的数字标识。
webmail:支持通过浏览器访问邮件服务器的程序,比如openwebmail、squirrelmail、extmail
SASL:simple authotication secure layer 简单认证安全层。
为防止客户端无认证的发送邮件,开发了此协议,实现smtp协议没有的安全认证功能。阻止了客户端滥发邮件的可能。现实中的程序如cyrus-sasl,courier-authlib。
^C[root@37-test ~]# rpm -qa |grep sasl
cyrus-sasl-md5-2.1.23-15.el6_6.2.x86_64
cyrus-sasl-plain-2.1.23-15.el6_6.2.x86_64
cyrus-sasl-gssapi-2.1.23-15.el6_6.2.x86_64
cyrus-sasl-lib-2.1.23-15.el6_6.2.x86_64
cyrus-sasl-2.1.23-15.el6_6.2.x86_64
cyrus-sasl-sql-2.1.23-15.el6_6.2.x86_64
cyrus-sasl-ntlm-2.1.23-15.el6_6.2.x86_64
cyrus-sasl-devel-2.1.23-15.el6_6.2.x86_64
cyrus-sasl-ldap-2.1.23-15.el6_6.2.x86_64
垃圾邮件服务器的产生就是因为邮件服务器本身对于不是自己的邮件有转发功能,所有会将发送到自己的错误邮件转发出去,这就给恶意人员提供了发送垃圾邮件的机会,这种情况,手动邮件的人,发件人是垃圾发件人本身,发送邮箱则是被转发的邮箱。
这种可以转发的邮件服务器就称为开发式的中继服务器,强力建议关闭此功能。
但内部用户发送邮件到外部邮箱,本身就是一个邮箱中继的过程,如何解决这个问题呢?那就是基于身份验证的方式访问邮箱服务器,如何进行身份验证,可以采用数据库方式
第二章 postfix
搭建邮件服务器常用的组合方式:
postfix+sasl(courier-authlib)+mysql
dovecot+mysql
extmail+extman+httpd
一、安装postfix
通常linux6以上系统默认就已经安装了postfix的程序,编译安装postfix前可以先卸载或停用他。
[root@gongbing ~]# ps aux |grep master
root 1893 0.0 0.3 80900 3428 ? Ss 11:52 0:00 /usr/libexec/postfix/master
root 6399 0.0 0.0 103328 892 pts/0 S+ 21:54 0:00 grep master
[root@gongbing ~]# netstat -tnlp |grep 25
tcp 0 0 ::1:25 :::* LISTEN 1893/master
关闭postfix进程
[root@gongbing ~]# service postfix stop
Shutting down postfix: [ OK ]
关闭自动启动功能
[root@gongbing ~]# chkconfig postfix off
或者直接卸载postfix
[root@gongbing ~]# rpm -e postfix --nodeps
安装前准备:
1、需要创建postfix和postdrop用户名和组,并且要求用户名id和组id相同。linux6以上可能会已经存在postfix、postdrop账户和组可以先删除然后重新创建
[root@37-test postfix-3.1.4]# groupadd -g 3000 postfix
[root@37-test postfix-3.1.4]# useradd -g 3000 -u 3000 -M -s /sbin/nologin postfix
[root@37-test postfix-3.1.4]# groupadd -g 3001 postdrop
groupadd: group 'postdrop' already exists
[root@37-test postfix-3.1.4]# groupdel postdrop
[root@37-test postfix-3.1.4]# groupadd -g 3001 postdrop
[root@37-test postfix-3.1.4]# useradd -g 3001 -u 3001 -M -s /sbin/nologin postdrop
[root@37-test postfix-3.1.4]# id postfix
uid=3000(postfix) gid=3000(postfix) 组=3000(postfix)
[root@37-test postfix-3.1.4]# id postdrop
uid=3001(postdrop) gid=3001(postdrop) 组=3001(postdrop)
2、确认sasl-devel、cyrus-sasl-plain包已经安装完毕。
[root@37-test postfix-3.1.4]# yum list all |grep sasl
cyrus-sasl.x86_64 2.1.23-15.el6_6.2 @base
cyrus-sasl-devel.x86_64 2.1.23-15.el6_6.2 @base
cyrus-sasl-lib.x86_64 2.1.23-15.el6_6.2 @base
cyrus-sasl-devel.i686 2.1.23-15.el6_6.2 base
cyrus-sasl-gssapi.i686 2.1.23-15.el6_6.2 base
3、确认库文件和头文件位置
[root@37-test postfix-3.1.4]# rpm -ql cyrus-sasl-devel
/usr/bin/sasl2-sample-client
/usr/bin/sasl2-sample-server
/usr/include/sasl
/usr/include/sasl/hmac-md5.h
/usr/include/sasl/md5.h
/usr/include/sasl/md5global.h
/usr/include/sasl/prop.h
/usr/include/sasl/sasl.h
/usr/include/sasl/saslplug.h
/usr/include/sasl/saslutil.h
/usr/lib64/libsasl2.so
4、编译安装postfix
编译配置文件
make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/local/dtedu/mysql/include/ -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS' 'AUXLIBS=-L/usr/local/dtedu/mysql/lib/ -lmysqlclient -lz -lm -L/usr/lib64/sasl2 -lsasl2 -lssl -lcrypto'
手动编译Postfix时使用的环境变量,变量值中含有空格符或者shell特殊字符,整个变量值必须放在双引号中。
AUXLIBS
指出位于标准位置以外的函数库,使用此变量标出函数库的路径;
CC
指出需要使用的特定编译器,Postfix默认使用gcc编译器,如果不想使用,可以使用此变量指出想要使用的编译器路径;
CCARGS
提供额外选项给编译器,编译器支持特殊选项,或是所需要的支持文件不是在标准路径中,使用此变量指出特殊选项或路径。
-L选项,指出函数库路径,如CCARGS '-I/usr/local/include/',
-l选项指出函数库的名称(不是指函数库的文件名),如/usr/lib/mysql/目录下的libmysqlclient.so是mysqlclient函数库的文件名,函数名是mysqlclient,则链接形式为-lmysqlclient。
Postfix包定义了一系列的宏,代表在系统上找到的特定资源以及预先设定的选项,编译器选项提供
-D选项供用户定义编译宏,如Postfix具备查询mysql的能力,则定义HAS_MYSQL宏,CCARGS='-DHAS_MYSQL';
DEBUG
-DUSE_SASL_AUTH:启用sasl认证
-I /usr/include/sasl:指定sasl程序的头文件位置
-DUSE_TLS:启用通信过程中的安全加密机制,也就是smtps。
CCARGS=-DHAS_MYSQL:定义postfix具有查询mysql的能力
-I /usr/local/dtedu/mysql/incloude/:指定mysql头文件位置
AUXLIBS= -L /usr/local/dtedu/mysql/lib/:用来指定额外的库文件位置。
-lz :支持压缩库文件
make install
Please specify the prefix for installed file names. Specify this ONLY
if you are building ready-to-install packages for distribution to OTHER
machines. See PACKAGE_README for instructions.
install_root: [/] //安装位置
Please specify a directory for scratch files while installing Postfix. You
must have write permission in this directory.
tempdir: [/root/postfix-3.1.4] //安装过程中的临时目录
Please specify the final destination directory for installed Postfix
configuration files.
config_directory: [/etc/postfix]
Please specify the final destination directory for installed Postfix
administrative commands. This directory should be in the command search
path of adminstrative users.
command_directory: [/usr/sbin]
Please specify the final destination directory for installed Postfix
daemon programs. This directory should not be in the command search path
of any users.
daemon_directory: [/usr/libexec/postfix] //服务进程
Please specify the final destination directory for Postfix-writable
data files such as caches or random numbers. This directory should not
be shared with non-Postfix software.
data_directory: [/var/lib/postfix] //数据
Please specify the final destination directory for the Postfix HTML
files. Specify "no" if you do not want to install these files.
html_directory: [no]
Please specify the owner of the Postfix queue. Specify an account with
numerical user ID and group ID values that are not used by any other
accounts on the system.
mail_owner: [postfix]
Please specify the final destination pathname for the installed Postfix
mailq command. This is the Sendmail-compatible mail queue listing command.
mailq_path: [/usr/bin/mailq.postfix]
Please specify the final destination directory for the Postfix on-line
manual pages. You can no longer specify "no" here.
manpage_directory: [/usr/share/man]
Please specify the final destination pathname for the installed Postfix
newaliases command. This is the Sendmail-compatible command to build
alias databases for the Postfix local delivery agent.
newaliases_path: [/usr/bin/newaliases.postfix]
Please specify the final destination directory for Postfix queues.
queue_directory: [/var/spool/postfix] //邮件队列存放位置
Please specify the final destination directory for the Postfix README
files. Specify "no" if you do not want to install these files.
readme_directory: [/usr/share/doc/postfix-2.6.6/README_FILES]
Please specify the final destination pathname for the installed Postfix
sendmail command. This is the Sendmail-compatible mail posting interface.
sendmail_path: [/usr/sbin/sendmail.postfix] //sendmail(软件)客户端
Please specify the group for mail submission and for queue management
commands. Specify a group name with a numerical group ID that is
not shared with other accounts, not even with the Postfix mail_owner
account. You can no longer specify "no" here.
setgid_group: [postdrop]
Please specify the final destination directory for Postfix shared-library
files.
shlib_directory: [no]
Please specify the final destination directory for non-executable files
that are shared among multiple Postfix instances, such as postfix-files,
dynamicmaps.cf, as well as the multi-instance template files main.cf.proto
and master.cf.proto.
meta_directory: [/etc/postfix]
Updating /etc/postfix/main.cf.proto...
Updating /etc/postfix/makedefs.out...
Updating /etc/postfix/master.cf.proto...
Updating /etc/postfix/postfix-files...
postfix: See http://www.postfix.org/COMPATIBILITY_README.html for details
postfix: To disable backwards compatibility use "postconf compatibility_level=2" and "postfix reload"
Editing /etc/postfix/master.cf, adding missing entry for postscreen TCP service
Editing /etc/postfix/master.cf, adding missing entry for smtpd unix-domain service
Editing /etc/postfix/master.cf, adding missing entry for dnsblog unix-domain service
Editing /etc/postfix/master.cf, adding missing entry for tlsproxy unix-domain service
Note: the following files or directories still exist but are no
longer part of Postfix:
/usr/libexec/postfix/main.cf /usr/libexec/postfix/master.cf
编译错误总结:
1、缺少-l sasl2的选项造成一下问题:
./../lib/libxsasl.a(xsasl_cyrus_server.o): In function `xsasl_cyrus_server_init':
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:200: undefined reference to `sasl_version_info'
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:220: undefined reference to `sasl_set_path'
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:237: undefined reference to `sasl_server_init'
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:238: undefined reference to `sasl_errstring'
../../lib/libxsasl.a(xsasl_cyrus_server.o): In function `xsasl_cyrus_server_done':
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:258: undefined reference to `sasl_done'
../../lib/libxsasl.a(xsasl_cyrus_server.o): In function `xsasl_cyrus_server_get_username':
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:608: undefined reference to `sasl_getprop'
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:610: undefined reference to `sasl_errstring'
../../lib/libxsasl.a(xsasl_cyrus_server.o): In function `xsasl_cyrus_server_get_mechanism_list':
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:407: undefined reference to `sasl_listmech'
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:412: undefined reference to `sasl_errstring'
../../lib/libxsasl.a(xsasl_cyrus_server.o): In function `xsasl_cyrus_server_auth_response':
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:472: undefined reference to `sasl_encode64'
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:475: undefined reference to `sasl_errstring'
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:481: undefined reference to `sasl_errstring'
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:481: undefined reference to `sasl_errstring'
../../lib/libxsasl.a(xsasl_cyrus_server.o): In function `xsasl_cyrus_server_next':
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:574: undefined reference to `sasl_decode64'
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:578: undefined reference to `sasl_errstring'
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:584: undefined reference to `sasl_server_step'
../../lib/libxsasl.a(xsasl_cyrus_server.o): In function `xsasl_cyrus_server_first':
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:527: undefined reference to `sasl_decode64'
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:531: undefined reference to `sasl_errstring'
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:540: undefined reference to `sasl_server_start'
../../lib/libxsasl.a(xsasl_cyrus_server.o): In function `xsasl_cyrus_server_free':
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:433: undefined reference to `sasl_dispose'
../../lib/libxsasl.a(xsasl_cyrus_server.o): In function `xsasl_cyrus_server_create':
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:317: undefined reference to `sasl_server_new'
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:322: undefined reference to `sasl_errstring'
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:324: undefined reference to `sasl_dispose'
../../lib/libxsasl.a(xsasl_cyrus_server.o): In function `xsasl_cyrus_server_set_security':
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:382: undefined reference to `sasl_setprop'
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:384: undefined reference to `sasl_errstring'
../../lib/libxsasl.a(xsasl_cyrus_server.o): In function `xsasl_cyrus_server_create':
/root/postfix-3.1.4/src/xsasl/xsasl_cyrus_server.c:346: undefined reference to `sasl_dispose'
collect2: ld 返回 1
make: *** [smtpd] 错误 1
make: *** [update] 错误 1
2、make install的时候在设置config路径的时候出现一下错误
bin/postconf: error while loading shared libraries: libmysqlclient.so.18:
通过ldconfig动态加载库文件,可以通过ld.so.conf来指定。
[root@37-test postfix-3.1.4]# ll /usr/local/dtedu/mysql/lib/
总用量 9428
-rw-r--r-- 1 mysql mysql 5446394 5月 31 2016 libmysqlclient.a
lrwxrwxrwx 1 root root 16 1月 20 01:43 libmysqlclient_r.a -> libmysqlclient.a
lrwxrwxrwx 1 root root 17 1月 20 01:44 libmysqlclient_r.so -> libmysqlclient.so
lrwxrwxrwx 1 root root 17 1月 20 01:45 libmysqlclient_r.so.18 -> libmysqlclient.so
lrwxrwxrwx 1 root root 17 1月 20 01:45 libmysqlclient_r.so.18.1.0 -> libmysqlclient.so
lrwxrwxrwx 1 mysql mysql 20 12月 1 05:52 libmysqlclient.so -> libmysqlclient.so.18
lrwxrwxrwx 1 mysql mysql 24 12月 1 05:52 libmysqlclient.so.18 -> libmysqlclient.so.18.1.0
-rwxr-xr-x 1 mysql mysql 4175269 5月 31 2016 libmysqlclient.so.18.1.0
-rw-r--r-- 1 mysql mysql 6834 5月 31 2016 libmysqlservices.a
drwxr-xr-x 3 mysql mysql 4096 5月 31 2016 plugin
[root@37-test postfix-3.1.4]#
解决办法:vi /etc/ld.so.conf加入一行即可/lib64
4、服务无法启动,提示postfix/postfix-script: fatal: mail system startup failed
步骤:
查看日志文件:
[root@37-test ~]# tail /var/log/maillog
Feb 4 01:39:15 37-test postfix[6415]: Postfix is running with backwards-compatible default settings
Feb 4 01:39:15 37-test postfix[6415]: See http://www.postfix.org/COMPATIBILITY_README.html for details
Feb 4 01:39:15 37-test postfix[6415]: To disable backwards compatibility use "postconf compatibility_level=2" and "postfix reload"
Feb 4 01:39:16 37-test postfix/postfix-script[6469]: warning: not owned by postfix: /var/lib/postfix/./master.lock
Feb 4 01:39:16 37-test postfix/postfix-script[6480]: starting the Postfix mail system
Feb 4 01:39:16 37-test postfix/master[6482]: fatal: open lock file /var/lib/postfix/master.lock: cannot open file: Permission denied
Feb 4 01:39:17 37-test postfix/master[6481]: fatal: daemon initialization failure
Feb 4 01:39:18 37-test postfix/postfix-script[6483]: fatal: mail system startup failed
确定问题为目录权限设置不当,修改目录权限。
[root@37-test ~]# chown postfix:postdrop /var/lib/postfix/master.lock
[root@37-test ~]# chmod 755 /var/lib/postfix/master.lock
再次查看运行状态:
[root@37-test ~]# postfix start
postfix: Postfix is running with backwards-compatible default settings
postfix: See http://www.postfix.org/COMPATIBILITY_README.html for details
postfix: To disable backwards compatibility use "postconf compatibility_level=2" and "postfix reload"
postfix/postfix-script: starting the Postfix mail system
[root@37-test ~]# netstat -tunlp |grep 25
tcp 0 0 ::1:25 :::* LISTEN 6906/master
You have new mail in /var/spool/mail/root
[root@37-test ~]# tail /var/lib/postfix/master.lock
6906
[root@37-test ~]# tail /var/log/maillog
Feb 4 01:46:01 37-test postfix/pickup[6907]: 299C641: uid=0 from=<root>
Feb 4 01:46:01 37-test postfix/cleanup[7116]: 299C641: message-id=<20170204014601.299C641@37-test.localdomain>
Feb 4 01:46:01 37-test postfix/qmgr[6908]: 299C641: from=<root@37-test.localdomain>, size=871, nrcpt=1 (queue active)
Feb 4 01:46:01 37-test postfix/local[7119]: 299C641: to=<root@37-test.localdomain>, orig_to=<root>, relay=local, delay=0.17, delays=0.13/0/0/0.04, dsn=2.0.0, status=sent (delivered to mailbox)
Feb 4 01:46:01 37-test postfix/qmgr[6908]: 299C641: removed
Feb 4 01:47:01 37-test postfix/pickup[6907]: 4452941: uid=0 from=<root>
Feb 4 01:47:01 37-test postfix/cleanup[7117]: 4452941: message-id=<20170204014701.4452941@37-test.localdomain>
Feb 4 01:47:01 37-test postfix/qmgr[6908]: 4452941: from=<root@37-test.localdomain>, size=871, nrcpt=1 (queue active)
Feb 4 01:47:01 37-test postfix/local[7118]: 4452941: to=<root@37-test.localdomain>, orig_to=<root>, relay=local, delay=0.17, delays=0.12/0/0/0.05, dsn=2.0.0, status=sent (delivered to mailbox)
Feb 4 01:47:01 37-test postfix/qmgr[6908]: 4452941: removed
5、远程访问25端口未开启
修改配置文件/etc/postfix/main.cf,将inet_interface(postfix监听的ip地址)的localhost改为本机“实际”ip地址并重启服务即可
#inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
inet_interfaces = 10.40.0.37
127.0.0.1表示只接受本机自己的邮件,不接受任何本局域网内其他主机的邮件。此特性适用于其他所有提供服务的软件上。
0.0.0.0表示监听本机所有ip地址的邮件信息,如果本机服务器有多个ip地址同样会造成冲突。
二、postfix的配置文件:
postfix模块化配置:
master:/etc/postfix/master.cf (主进程的配置文件)
mail:/etc/postfix/main.cf (功能性配置文件)
表示方法:参数 = 值 (参数定格写在行首,以空白开头的行认为是上一行的延续)
postfix配置命令工具postconf
-d(default):用来显示默认配置信息
-n(new):用来显示修改了的配置信息
-m:显示支持的查找表(数据库)类型
-A :查看postfix支持的sasl客户端认证方式
-a:查看服务器端支持的认证方式
-e 参数=value: 更改某参数配置信息,并保存到main.cf文件中。
-
smtp状态码:
1xx:纯信息
2xx:正确类信息
3xx:上一步操作未完成,仍需要进一步补充
4xx:暂时性错误
5xx:永久性错误
smtp协议命令源语
helo (smtp协议)
ehlo(esmtp协议)
mail from:senduser 指定发件人信息
rcpt to:reciver 指定收件人信息 对于公共邮箱必须有域名、A纪录、PTR解析。
data 指定发送的信息
配置DNS服务器,并实现域名解析
1、安装DNS服务器
[root@37-test ~]# yum install bind
2、配置/etc/named.conf文件
options {
# listen-on port 53 { 127.0.0.1; };
# listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
# allow-query { localhost; };
recursion yes;
# dnssec-enable yes;
# dnssec-validation yes;
3、编辑named.rfc1912.zone文件。
zone "dtedu.com" IN {
type master;
file "dtedu.com.zone";
};
zone “0.40.10” IN {
type master;
file "10.40.0.zone";
检查正确性:
[root@37-test ~]# named-checkconf
4、进入/etc/named目录并创建相应的文件,这里是dtedu.com.zone和10.40.0.zone.
dtedu.com.zone
$TTL 86400
@ IN SOA ns.dtedu.com admin@dtedu.com(
20170209212
2H
10M
3D
1D)
IN NS ns
IN MX 10 mail
ns IN A 10.40.0.37
mail IN A 10.40.0.37
www IN A 10.40.0.37
10.40.0.zone
$TTL 86400
@ IN SOA ns.dtedu.com. admin@dtedu.com.(
20170209212
2H
10M
3D
1D)
IN NS ns.dtedu.com.
37 IN PTR mail.dtedu.com.
37 IN PTR ns.dtedu.com.
37 IN PTR www.dtedu.com.
检查zone文件正确性
[root@37-test named]# named-checkzone "dtedu.com" dtedu.com.zone
zone dtedu.com/IN: loaded serial 2990340028
OK
[root@37-test named]# named-checkzone "0.40.10.in-addr.arpa" 10.40.0.zone
zone 0.40.10.in-addr.arpa/IN: loaded serial 2990340028
OK
修改本机的dns设置,并检查正确性
[root@37-test named]# dig -t MX mail.dtedu.com
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.47.rc1.el6_8.4 <<>> -t MX mail.dtedu.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10869
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;mail.dtedu.com. IN MX
;; AUTHORITY SECTION:
dtedu.com. 86400 IN SOA ns.dtedu.com.dtedu.com. admin\@dtedu.com.dtedu.com. 2990340028 7200 600 259200 86400
;; Query time: 0 msec
;; SERVER: 10.40.0.37#53(10.40.0.37)
;; WHEN: Tue Feb 7 08:45:54 2017
;; MSG SIZE rcvd: 93
5、修改named目录下文件的权限,并启动服务。
[root@37-test named]# chown root:named ./*
[root@37-test named]# ll
总用量 8
-rw-r--r-- 1 root named 195 2月 7 07:19 10.40.0.zone
-rw-r--r-- 1 root named 184 2月 7 07:09 dtedu.com.zone
[root@37-test named]# chmod 640 ./*
[root@37-test named]# ll
总用量 8
-rw-r----- 1 root named 195 2月 7 07:19 10.40.0.zone
-rw-r----- 1 root named 184 2月 7 07:09 dtedu.com.zone
问题排错:
1、注意bind运行的真实路径可能是/var/named,所有需要将zone配置文件复制到这里。
[root@37-test named]# pwd
/var/named
[root@37-test named]# ll
总用量 40
-rw-r----- 1 root named 197 2月 7 08:42 10.40.0.zone
drwxr-x--- 6 root named 4096 2月 7 08:06 chroot
drwxrwx--- 2 named named 4096 2月 7 08:42 data
-rw-r----- 1 root named 184 2月 7 08:32 dtedu.com.zone
drwxrwx--- 2 named named 4096 2月 7 08:42 dynamic
-rw-r----- 1 root named 3171 1月 11 2016 named.ca
-rw-r----- 1 root named 152 12月 15 2009 named.empty
-rw-r----- 1 root named 152 6月 21 2007 named.localhost
-rw-r----- 1 root named 168 12月 15 2009 named.loopback
drwxrwx--- 2 named named 4096 1月 17 13:04 slaves
2、检查区域文件域名的后缀“.”
[root@37-test ~]# telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 37-test.localdomain ESMTP Postfix
helo localhost //创建连接
250 37-test.localdomain
mail from:USA@USA.COM //指定发送者信息
250 2.1.0 Ok
rcpt to:gongbing //指定接受者信息
250 2.1.5 Ok
data //准备发送邮件内容
354 End data with <CR><LF>.<CR><LF>
ni hao a //邮件内容
. //“.”表示邮件接收
250 2.0.0 Ok: queued as 4E88487A001
quit //退出邮件系统
221 2.0.0 Bye
Connection closed by foreign host.
查看收件人信息:
[gongbing@37-test ~]$ mail 登录gongbing账户,并查看sendmail邮箱
Heirloom Mail version 12.4 7/29/08. Type ? for help.
"/var/spool/mail/gongbing": 1 message 1 new
>N 1 USA@USA.COM Sat Feb 4 02:40 13/434
& 1
Message 1:
From USA@USA.COM Sat Feb 4 02:40:59 2017
Return-Path: <USA@USA.COM>
X-Original-To: gongbing
Delivered-To: gongbing@37-test.localdomain
Date: Sat, 4 Feb 2017 02:40:41 +0000 (UTC)
From: USA@USA.COM
Status: R
NI HAO A
知识点:
postfix通过aliases(别名)来判断邮件的实际接受者,这个别名的配置文件通常在/etc/aliases,但是postfix并不能直接访问这个文件,而是通过newaliase命令将/etc/aliases转换成aliases.db这个文件后才能够直接访问。
[root@37-test ~]# ll /etc/aliases
aliases aliases.db
[root@37-test ~]# newaliases
默认情况下本地网段发送的邮件,服务器都是会进行邮件中继的(也就是转发)。
127.0.0.1在配置上是在自己的回环地址上走一圈,并不经过实际网卡。
1、基本配置文件
修改以下几项为自己需要的配置
myhostname = mail.gongbing.com.cn 邮件服务器自己的主机名。
myorigin = gongbing.com.cn 邮件地址伪装,也叫邮件地址重写
mydomain = gongbing.com.cn 邮件服务器所在的域
mydestination = $myhostname,localhost.$mydomain,localhost,$mydomain @后缀是以上几个域名的话,就认为是本地邮件,不发送邮件中继,否则认为需要中继。
mynetwork = 10.40.0.0/24,127.0.0.0/8 用来指定给那个网络的主机继续邮件中继,如果只有127或者没有的话就会停止对任何网络进行中继。限制邮箱中继还可以通过smtpd_recipient_restrictions 来实现
三、实现客户端接收邮件的功能(MRA)
基本组件:cyrus-imap,dovecot(安装包依赖于mysql客户端),建议将dovecot-mysql一并安装。
POP3:110/TCP 明文
IMAP4:143/TCP 明文
dove支持四种协议:POP3/IMAP4/POPS/IMAPS
配置文件:/etc/dovecot.conf
有SASL认证能力:
邮箱格式:
mbox:一个文件存储所有邮件,文件很大,默认存储方式。
maildir:一个文件存储一封邮件,所有邮件存储在一个目录中
1、安装dovecot
[root@37-test ~]# yum install dovecot*
2、修改配置文件/etc/dovecot/dovecot.conf
# Protocols we want to be serving.
protocols = imap pop3
3、启动服务
[root@37-test ~]# service dovecot status
dovecot 已停
[root@37-test ~]# service dovecot start
正在启动 Dovecot Imap: [确定]
4、查看监听的端口
[root@37-test ~]# netstat -tunlp |grep dovecot
tcp 0 0 0.0.0.0:110 0.0.0.0:* LISTEN 12662/dovecot
tcp 0 0 0.0.0.0:143 0.0.0.0:* LISTEN 12662/dovecot
tcp 0 0 0.0.0.0:993 0.0.0.0:* LISTEN 12662/dovecot
tcp 0 0 0.0.0.0:995 0.0.0.0:* LISTEN 12662/dovecot
tcp 0 0 :::110 :::* LISTEN 12662/dovecot
tcp 0 0 :::143 :::* LISTEN 12662/dovecot
tcp 0 0 :::993 :::* LISTEN 12662/dovecot
tcp 0 0 :::995 :::* LISTEN 12662/dovecot
故障汇总:
1、通过命令行工具TELNET登录服务器并进行身份验证出现一下错误,需要修改/etc/dovecot/conf.d/10-mail.conf文件
错误状态:
[root@37-test ~]# telnet localhost 110
Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user gongbing
+OK
pass 123123
Connection closed by foreign host.
修改方法:
mail_location = maildir:~/Maildir
# mail_location = mbox:~/mail:INBOX=/var/mail/%u
# mail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n
2、outlook客户端输入用户名、密码无法登陆,信息验证不过去,并且postfix的日志文件提示一下信息:
Feb 24 09:00:11 mail dovecot: pop3-login: Disconnected (tried to use disabled plaintext auth): rip=10.40.0.56, lip=10.40.0.37
需要进行一下操作:
# Space separated list of wanted authentication mechanisms:
# plain login digest-md5 cram-md5 ntlm rpa apop anonymous gssapi otp skey
# gss-spnego
# NOTE: See also disable_plaintext_auth setting.
auth_mechanisms = plain login
# Disable LOGIN command and all other plaintext authentications unless
# SSL/TLS is used (LOGINDISABLED capability). Note that if the remote IP
# matches the local IP (ie. you're connecting from the same computer), the
# connection is considered secure and plaintext authentication is allowed.
#disable_plaintext_auth = yes
disable_plaintext_auth = no
知识点:
1、mutt文本模式邮箱客户端工具基本使用方法
mutt -f protocol://username@hostname
例如:
[root@mail ~]# mutt -f pop://liuhaixiang@dtedugongbing.com@mail.dtedugongbing.com
注意一点,使用mutt发送邮件时,发件人是按照登录系统的账号进行发送的,而不是以登录邮箱的用户名进行发送的。
2、telnet查看邮件方法
[root@37-test ~]# telnet localhost 110 接受邮件需要登录pop3的110 端口
Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user gongbing 用户验证
+OK
pass 123123 输入密码
list 检索邮件记录
1 234
2 564
retr 1 查看指定邮件
+OK 593 octets
Return-Path: <root@mail.dtedugongbing.com>
X-Original-To: gongbing@dtedugongbing.com
Delivered-To: gongbing@dtedugongbing.com
Received: by mail.dtedugongbing.com (Postfix, from userid 0)
id AB1A961031; Fri, 24 Feb 2017 14:39:00 +0800 (CST)
Date: Fri, 24 Feb 2017 14:39:00 +0800
From: root <root@mail.dtedugongbing.com>
To: gongbing@dtedugongbing.com
Subject: test
Message-ID: <20170224063900.GA13241@mail.dtedugongbing.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: Mutt/1.5.20 (2009-12-10)
nihao wo shi liuhaixiang
.
本文转自 blackstome 51CTO博客,原文链接:http://blog.51cto.com/137783/1916982,如需转载请自行联系原作者