编译安装postfix2.10邮件服务(linux系统为64位redhat6.0):
首先下载postfix2.10文章末尾有下载地址;
SMTP:(Simple Mail Transfer Protocol)即简单邮件传输协议
POP3:邮局协议 IMAP4:internet mail access protocol 互联网邮件访问协议
SASL:simple Authentication Secure layer 简单安全认证层 (版本v1,v2目前主流v2版本)
MDA:邮件投递代理(procmail,maildrop)
MUA:邮件用户代理(mutt)
mail relay: 邮件中继
MTA:报文传输代理 (sendmail,postfix,qmail,exim)
Postfix的配置文件:
postfix模块化:
master:/etc/postfix/master.cf 主进程配置文件
mail:/etc/postfix/main.cf 主配置文件(相关配置的主配置文件)
格式:参数 = 值:参数必须写在绝对行首(即行首不能有空格),以空白开头的行被认
为是上一行的延续(即行首有空白的行都是上一行没有写完的内容)。
postconfig: 可以直接配置修改postfix的主配置文件
-d: 显示默认的配置
-n: 修改了的配置
-m: 显示支持的查找表类型
-A:显示支持的SASL客户端插件类型
-e PARMATER=VALUE: 更改某参数配置信息,并保存至main.cf主配置文件中
-a: 服务器端支持的SASL插件类型
smtp状态码:
1xx:纯信息
2xx:正确信息
3xx:上一步操作尚未完成,需要继续补充
4xx:暂时性错误
5xx:永久性错误
smtp协议命令:
helo (smtp协议)
ehlo (esmtp协议)
mail from: 指定发件人
rcpt to:指定收件人
data 输入正文
Subject: 邮件主题
邮件正文以.结束
quit退出邮件
[root@lamp ~]# lftp test@10.109.134.247 #连接ftp服务器
口令:
lftp test@10.109.134.247:/> get postfix-2.10.10.tar.gz #从ftp服务器上下载软件包
3821154 bytes transferred
lftp test@10.109.134.247:/> bye #退出ftp服务器连接
[root@lamp ~]#ls
install.log postfix-2.10.10.tar.gz install.log.syslog xcache-2.0.1
[root@lamp ~]# tar xf postfix-2.10.10.tar.gz #解压postfix软件
[root@lamp ~]# ls
install.log postfix-2.10.10 install.log.syslog postfix-2.10.10.tar.gz
[root@lamp ~]# cd postfix-2.10.10 #进入解压目录
[root@lamp postfix-2.10.10]# groupadd -g 2525 postfix #新建组postfix
[root@lamp postfix-2.10.10]# useradd -g postfix -u 2525 -M -s /sbin/nologin postfix #新建用户postfix -g指定所属组,-u指定UID,-M不创建家目录,-s指定登录shell为不可登录nologin.
[root@lamp postfix-2.10.10]# id postfix #查看postfix用户信息
uid=2525(postfix) gid=2525(postfix) 组=2525(postfix)
[root@lamp postfix-2.10.10]# groupadd -g 2526 postdrop #新建组postdrop
[root@lamp postfix-2.10.10]# useradd -g postdrop -u 2526 -M -s /sbin/nologin postdrop 新建用户postdrop -g指定所属组,-u指定UID,-M不创建家目录,-s指定登录shell为不可登录nologin.
[root@lamp postfix-2.10.10]# id postdrop
uid=2526(postdrop) gid=2526(postdrop) 组=2526(postdrop)
[root@lamp postfix-2.10.10]# yum list all |grep sasl #查看安装的sasl,确保以下sasl组建已经安装。
This system is not registered with RHN.
RHN support will be disabled.
cyrus-sasl.x86_64 2.1.23-8.el6 @anaconda-RedHatEnterpriseLinux
cyrus-sasl-devel.x86_64 2.1.23-8.el6 @Server
cyrus-sasl-lib.x86_64 2.1.23-8.el6 @anaconda-RedHatEnterpriseLinux
cyrus-sasl-md5.x86_64 2.1.23-8.el6 @anaconda-RedHatEnterpriseLinux
cyrus-sasl-plain.x86_64 2.1.23-8.el6 @anaconda-RedHatEnterpriseLinux
开始执行编译安装:
[root@lamp postfix-2.10.10]# make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS' 'AUXLIBS=-L/usr/local/mysql/lib -lmysqlclient -lz -lm -L/usr/lib64/sasl2 -lsasl2 -lssl -lcrypto'
#编译安装指定mysql路径,以及支持的功能都编译。
make -f Makefile.in MAKELEVEL= Makefiles
(echo "# Do not edit -- this file documents how Postfix was built for your machine."; /bin/sh makedefs) >makedefs.tmp
No <db.h> include file found.
Install the appropriate db*-devel package first. #提示报错,需安装db*-devel
make: *** [Makefiles] 错误 1
make: *** [makefiles] 错误 2
[root@lamp postfix-2.10.10]# yum install db*-devel #安装db*-devel组件后再执行编译
Loaded plugins: refresh-packagekit, rhnplugin
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Resolving Dependencies
Transaction Test Succeeded
Running Transaction
Installing : glib2-devel-2.22.5-5.el6.x86_64 1/5
Installing : db4-cxx-4.7.25-16.el6.x86_64 2/5
Installing : 1:dbus-devel-1.2.24-3.el6.x86_64 3/5
Installing : dbus-glib-devel-0.86-5.el6.x86_64 4/5
Installing : db4-devel-4.7.25-16.el6.x86_64 5/5
Installed:
db4-devel.x86_64 0:4.7.25-16.el6 dbus-devel.x86_64 1:1.2.24-3.el6
dbus-glib-devel.x86_64 0:0.86-5.el6
Dependency Installed:
db4-cxx.x86_64 0:4.7.25-16.el6 glib2-devel.x86_64 0:2.22.5-5.el6
Complete! #安装完成后再次执行编译安装
[root@lamp postfix-2.10.10]# make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS ''AUXLIBS=-L/usr/local/mysql/lib -lmysqlclient -lz -lm -L/usr/lib64/sasl2 -lsasl2 -lssl -lcrypto'
(echo "# Do not edit -- this file documents how Postfix was built for your machine."; /bin/sh makedefs) >makedefs.tmp
set +e; if cmp makedefs.tmp conf/makedefs.out; then rm makedefs.tmp; \
else mv makedefs.tmp conf/makedefs.out; fi >/dev/null 2>/dev/null
set -e; for i in src/util src/global src/dns src/tls src/xsasl src/milter src/master src/postfix src/fsstone src/smtpstone src/sendmail src/error src/pickup src/cleanup src/smtpd src/local src/trivial-rewrite src/qmgr src/oqmgr src/smtp src/bounce src/pipe src/showq src/postalias src/postcat src/postconf src/postdrop src/postkick src/postlock src/postlog src/postmap src/postqueue src/postsuper src/qmqpd src/spawn src/flush src/verify src/virtual src/proxymap src/anvil src/scache src/discard src/tlsmgr src/postmulti src/postscreen src/dnsblog src/tlsproxy; do \
(set -e; echo "[$i]"; cd $i; rm -f Makefile; \
make -f Makefile.in Makefile MAKELEVEL=) || exit 1; \
done;
........
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/tlsproxy]
cat ../../conf/makedefs.out Makefile.in >Makefile
rm -f Makefile; (cat conf/makedefs.out Makefile.in) >Makefile
编译安装完成,没有报错,可以执行下一步操作。
[root@lamp postfix-2.10.10]# make #执行make报错
set -e; for i in src/util src/global src/dns src/tls src/xsasl src/milter src/master src/postfix src/fsstone src/smtpstone src/sendmail src/error src/pickup src/cleanup src/smtpd src/local src/trivial-rewrite src/qmgr src/oqmgr src/smtp src/bounce src/pipe src/showq src/postalias src/postcat src/postconf src/postdrop src/postkick src/postlock src/postlog src/postmap src/postqueue src/postsuper src/qmqpd src/spawn src/flush src/verify src/virtual src/proxymap src/anvil src/scache src/discard src/tlsmgr src/postmulti src/postscreen src/dnsblog src/tlsproxy; do \
(set -e; echo "[$i]"; cd $i; make 'CC=gcc -I. -I../../include -DHAS_MYSQL -I/usr/local/mysql/include -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS AUXLIBS=-L/usr/local/mysql/lib -lmysqlclient -lz -lm -L/usr/lib64/sasl2 -lsasl2 -lssl -lcrypto -DHAS_PCRE -Wmissing-prototypes -Wformat -Wno-comment' update MAKELEVEL=) || exit 1; \
done
[src/util]
gcc -I. -I../../include -DHAS_MYSQL -I/usr/local/mysql/include -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS AUXLIBS=-L/usr/local/mysql/lib -lmysqlclient -lz -lm -L/usr/lib64/sasl2 -lsasl2 -lssl -lcrypto -DHAS_PCRE -Wmissing-prototypes -Wformat -Wno-comment -g -O -I. -DLINUX2 -c alldig.c
gcc: AUXLIBS=-L/usr/local/mysql/lib:没有那个文件或目录 #提示报错没有目录,其实目录存在,解决方法如下步骤。需在make的时候AUXLIBS前面多加2个空格
make: *** [alldig.o] 错误 1
make: *** [update] 错误 1
报错解决方法:
[root@lamp postfix-2.10.10]# make makefiles 'CCARGS=-DHAS_MYSQL -I/usr/local/mysql/include -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS AUXLIBS=-L/usr/local/mysql/lib -lmysqlclient -lz -lm -L/usr/lib64/sasl2 -lsasl2 -lssl -lcrypto' #必须加2个分号。
........
cat ../../conf/makedefs.out Makefile.in >Makefile
[src/tlsproxy]
cat ../../conf/makedefs.out Makefile.in >Makefile
rm -f Makefile; (cat conf/makedefs.out Makefile.in) >Makefile
[root@lamp postfix-2.10.10]# make
..........
...........
master_monitor.o ../../lib/libglobal.a ../../lib/libutil.a -lpcre -ldb -lnsl -lresolv
gcc -I. -I../../include -DHAS_MYSQL -I/usr/local/mysql/include -DUSE_SASL_AUTH -DUSE_CYRUS_SASL -I/usr/include/sasl -DUSE_TLS -DHAS_PCRE -Wmissing-prototypes -Wformat -Wno-comment -g -O -I. -I../../include -DLINUX2 -o master master.o master_conf.o master_ent.o master_sig.o master_avail.o master_spawn.o master_service.o master_status.o master_listen.o master_vars.o master_wakeup.o master_watch.o master_flow.o master_monitor.o ../../lib/libglobal.a ../../lib/libutil.a -L/usr/local/mysql/lib -lmysqlclient -lz -lm -L/usr/lib64/sasl2 -lsasl2 -lssl -lcrypto -lpcre -ldb -lnsl -lresolv
[root@lamp postfix-2.10.10]# 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-2.10.10] /tmp/postfix #临时目录
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] #邮件队列执行路径
Please specify the final destination directory for the Postfix on-line
manual pages. You can no longer specify "no" here.
manpage_directory: [/usr/local/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] #新别名路径
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: [no] #帮助文档路径
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] #senmail客户端路径
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] #设定gid组用户
..........
BTW: Check your /etc/aliases file and be sure to set up aliases
that send mail for root and postmaster to a real person, then run
/usr/bin/newaliases.
安装结束。
[root@lamp ~]# postfix start #启动postfix进程
postfix/postfix-script: starting the Postfix mail system
[root@lamp ~]# netstat -tlnp #查看邮件服务25端口是否监听
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1553/cupsd
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 27814/master
tcp 0 0 :::111 :::* LISTEN 1385/rpcbind
tcp 0 0 :::80 :::* LISTEN 2001/httpd tcp 0 0 :::22 :::* LISTEN 1659/sshd
[root@lamp ~]# tail /var/log/maillog #查看postfix邮件服务日志信息
Feb 28 13:29:01 lamp postfix/postfix-script[27811]: starting the Postfix mail system
Feb 28 13:29:01 lamp postfix/master[27814]: daemon started -- version 2.10.10, configuration /etc/postfix
[root@lamp ~]# telnet localhost 25 #给本机发送邮件
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 lamp.com ESMTP Postfix
helo localhost
250 lamp.com
mail from:root #发件人
250 2.1.0 Ok
rcpt to:donggen #收件人
250 2.1.5 Ok
data #邮件正文
354 End data with <CR><LF>.<CR><LF>
Subject:How are you these days? #邮件主题
Are you gua le ma?
. #.结束正文
250 2.0.0 Ok: queued as 01311413
quit #quit退出发送邮件
221 2.0.0 Bye
Connection closed by foreign host.
[root@lamp ~]# tail /var/log/maillog #查看日志文件
Feb 28 14:56:20 lamp postfix/master[28749]: daemon started -- version 2.10.10, configuration /etc/postfix
Feb 28 14:56:44 lamp postfix/smtpd[28763]: warning: dict_nis_init: NIS domain name not set - NIS lookups disabled
Feb 28 14:56:44 lamp postfix/smtpd[28763]: connect from localhost.localdomain[127.0.0.1]
Feb 28 14:57:27 lamp postfix/smtpd[28763]: 01311413: client=localhost.localdomain[127.0.0.1]
Feb 28 14:58:12 lamp postfix/cleanup[28766]: 01311413: message-id=<20170228065727.01311413@lamp.com>
Feb 28 14:58:12 lamp postfix/qmgr[28751]: 01311413: from=<root@lamp.com>, size=332, nrcpt=1 (queue active)
Feb 28 14:58:12 lamp postfix/local[28776]: warning: dict_nis_init: NIS domain name not set - NIS lookups disabled
Feb 28 14:58:12 lamp postfix/local[28776]: 01311413: to=<donggen@lamp.com>, orig_to=<donggen>, relay=local, delay=56, delays=56/0.01/0/0.01, dsn=2.0.0, status=sent (delivered to mailbox)
Feb 28 14:58:12 lamp postfix/qmgr[28751]: 01311413: removed
Feb 28 14:58:17 lamp postfix/smtpd[28763]: disconnect from localhost.localdomain[127.0.0.1]
[donggen@lamp ~]$ mail #切换使用者,查看邮件。
Heirloom Mail version 12.4 7/29/08. Type ? for help.
"/var/spool/mail/donggen": 1 message 1 new
>N 1 root@lamp.com Tue Feb 28 14:58 14/452 "How are you these days?"
Status: R
Are you gua le ma?
postfix服务启动脚本:可以通过service postfix start|restart
脚本如下:vim /etc/init.d/postfix
1、编辑postfix服务启动脚本
[root@lamp ~]# vim /etc/init.d/postfix
#!/bin/bash
#
#postfix Postfix Mail Transfer Agent
#
#description: Postfix is a Mail Transport Ageent,which is the progrom
# that moves mail from one mochine to another.
#processname:master
#pidfile:/var/spool/postfix/pid/master.pid
#config: /etc/postfix/main.cf
#config: /etc/postfix/master.cf
#Source function library.
. /etc/rc.d/init.d/functions
#Source networking configuretion.
. /etc/sysconfig/network
#Check that networking is up.
[ $NETWORKING = "NO" ] && exit 3
[ -x /usr/sbin/postfix ] || exit 4
[ -d /etc/postfix ] || exit 5
[ -d /var/spool/postfix ] || exit 6
RETVAL=0
prog="postfix"
start() {
# start daemons.
echo -n $"Starting postfix: "
/usr/bin/newaliases >/dev/null 2>&1
/usr/sbin/postfix start 2>/dev/null 1>&2 && success || failure $"$prog start"
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/postfix
echo
return $RETVAL
}
stop() {
# stop daemons.
echo -n $"Shutting down postfix: "
/usr/sbin/postfix stop 2>/dev/null 1>&2 && success || failure $"$prog stop"
RETVAL=$?
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/postfix
echo
return $RETVAL
}
reload() {
echo -n $"Reloading postfix: "
/usr/sbin/postfix reload 2>/dev/null 1>&2 && success || failure $"$prog reload"
RETVAL=$?
echo
return $RETVAL
}
abort() {
/usr/sbin/postfix abort 2>/dev/null 1>&2 && success || failure $"$prog abort"
return $?
}
flush() {
/usr/sbin/postfix flush 2>/dev/null 1>&2 && success || failure $"$prog flush"
return $?
}
check() {
/usr/sbin/postfix check 2>/dev/null 1>&2 && success || failure $"$prog check"
return $?
}
restart() {
stop
start
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
reload)
reload
;;
abort)
abort
;;
flush)
flush
;;
check)
check
;;
status)
status master
;;
condrestart)
[ -f /var/lock/subsys/postfix ] && restart || :
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|abort|flush|check|status|condrestart}"
exit 1
;;
esac
exit $?
# END
[root@lamp ~]# chmod +x /etc/init.d/postfix
[root@lamp ~]# chkconfig --add postfix #把postfix添加至开机启动
[root@lamp ~]# chkconfig --list postfix #查看postfix开机是否自动启动
[root@lamp ~]# service postfix restart
关闭 postfix: [确定]
启动 postfix: [确定]
2、进行一些基本配置,测试启动postfix并进行发信。
修改/etc/postfix/main.cf
修改以下几项配置(红色部分):
myhostname = mail.lamp.com
myorigin =
mydomain =
mydestination =
mynetworks =
说明:
myorigin参数用来指明发件人所在的域名,即做发件地址伪装;
myhostname参数指定运行postfix邮件系统的主机的主机名,默认情况下,其值被设定为本地机器名;
mydomain参数指定自己的域名,默认情况下postfix将myhostname的第一部分删除而作为mydomain的值;
mydestination参数指定postfix接收邮件时收件人的域名,即你的postfix系统要接受到那个域名的邮件
mynetworks参数指定你所在的网络的网络地址,postfix系统根据其值来区别用户是远程的还是本地的,
如果是本地网络用户则允许其访问;
inet_interfaces参数指定postfix系统监听的网络接口;
注意:
1、在postfix的配置文件中,参数行和注释行是不能处在同一行中的;
2、任何一个参数的值都不需要加引号,否则,引号将会被当做参数值的一部分来使用;
3、每修改参数及其值后执行postfix reload即可令其生效,但若修改了inet_interfaces;
则需重新启动postfix;
4、如果一个参数的值有多个,可以将他们放在不同的行中,只需要在其后的每个行前多置一个空格
即可;postfix会把第一个字符为空格或tab的文本行视为上一行的延续;
3、修改主机名
[root@lamp ~]# hostname mail.lamp.com #临时修改主机名,立即生效,重启失效
[root@lamp ~]# hostname
mail.lamp.com
[root@lamp ~]# vim /etc/sysconfig/network #永久生效,修改主机名,重启后生效
NETWORKING=yes
HOSTNAME=mail.lamp.com
[root@mail ~]# hostname
mail.lamp.com
4、安装配置DNS服务器
[root@mail ~]# rpm -qa |grep bind #查看系统是否安装过DNS
PackageKit-device-rebind-0.5.8-13.el6.x86_64
bind-libs-9.7.0-5.P2.el6.x86_64
samba-winbind-clients-3.5.4-68.el6.x86_64
bind-utils-9.7.0-5.P2.el6.x86_64
rpcbind-0.2.0-8.el6.x86_64
[root@mail ~]# rpm -e bind-libs bind-utils #先卸载已经安装的bind
[root@mail ~]# yum install bind.x86_64 bind-libs bind-utils
Loaded plugins: refresh-packagekit, rhnplugin
This system is not registered with RHN.
RHN support will be disabled.
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package bind.x86_64 32:9.7.0-5.P2.el6 set to be updated
---> Package bind-libs.x86_64 32:9.7.0-5.P2.el6 set to be updated
---> Package bind-utils.x86_64 32:9.7.0-5.P2.el6 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================================================
Install 3 Package(s)
Upgrade 0 Package(s)
Total download size: 4.4 M
Installed size: 8.9 M
Is this ok [y/N]: y
Downloading Packages:
-----------------------------------------------------------------------------------------------------
Total 80 MB/s | 4.4 MB 00:00
Complete! #安装完成
[root@mail ~]# vim /etc/named.conf #编辑DNS配置文件
[root@mail ~]# service named start #启动DNS服务
启动 named: [确定]
[root@mail ~]# netstat -tlnp #查看监听的端口
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:56201 0.0.0.0:* LISTEN 1450/rpc.statd
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 1958/mysqld
tcp 0 0 10.109.134.237:53 0.0.0.0:* LISTEN 7794/named
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 7794/named
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN 2229/dnsmasq
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1659/sshd
tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 7794/named
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 6341/master
[root@mail ~]# vim /etc/named.rfc1912.zones #编辑正向和反向代理设置,
在最末尾增加以下内容:
zone "lamp.com" IN {
type master;
file "lamp.com.zone";
allow-update { none; };
allow-transfer { none; };
};
zone "134.109.10.in-addr.arpa" IN {
type master;
file "10.109.134.zone";
allow-update { none; };
allow-transfer { none; };
};
[root@mail ~]# named-checkconf #检查dns配置文件是否有语法错误
[root@mail ~]# named-checkconf /etc/named.conf #指定检查那个DNS配置文件是否有语法错误
[root@mail ~]# cd /var/named/
[root@mail named]# vim lamp.com.zone #编辑正向代理文件,内容如下;
[root@mail named]# vim 10.109.134.zone #编辑反向代理文件,内容如下;
[root@mail named]# chgrp named lamp.com.zone 10.109.134.zone #更改组为named
[root@mail named]# chmod 640 10.109.134.zone lamp.com.zone #修改权限为640
[root@mail named]# ll
总用量 36
-rw-r-----. 1 root named 285 3月 1 11:46 10.109.134.zone
drwxrwx---. 2 named named 4096 3月 1 11:01 data
drwxrwx---. 2 named named 4096 3月 1 11:02 dynamic
-rw-r-----. 1 root named 292 3月 1 11:43 lamp.com.zone
-rw-r-----. 1 root named 1892 2月 18 2008 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 5月 26 2010 slaves
[root@mail named]# named-checkzone "lamp.com" lamp.com.zone #检查正向代理文件是否正确
zone lamp.com/IN: loaded serial 2017030101
OK
[root@mail named]# named-checkzone "134.109.10.in-addr.arpa" 10.109.134.zone #检查反向代理配置文件是否正确
zone 134.109.10.in-addr.arpa/IN: loaded serial 2017030101
OK
[root@mail named]# service named restart #重启named服务
停止 named: [确定]
启动 named: [确定]
[root@mail named]# chkconfig named on #加入到开机启动列表
[root@mail named]# dig -t MX lamp.com @10.109.134.237 #测试解析MX记录是否正常
; <<>> DiG 9.7.0-P2-RedHat-9.7.0-5.P2.el6 <<>> -t MX lamp.com @10.109.134.237
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46065
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2
;; QUESTION SECTION:
;lamp.com.INMX
;; ANSWER SECTION:
lamp.com.600INMX10 mail.lamp.com.
;; AUTHORITY SECTION:
lamp.com.600INNSns.lamp.com.
;; ADDITIONAL SECTION:
mail.lamp.com.600INA10.109.134.237
ns.lamp.com.600INA10.109.134.237
;; Query time: 0 msec
;; SERVER: 10.109.134.237#53(10.109.134.237)
;; WHEN: Wed Mar 1 13:39:05 2017
;; MSG SIZE rcvd: 96
[root@mail named]# dig -t A mail.lamp.com @10.109.134.237 #测试邮件A记录解析是否正常
; <<>> DiG 9.7.0-P2-RedHat-9.7.0-5.P2.el6 <<>> -t A mail.lamp.com @10.109.134.237
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46985
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; QUESTION SECTION:
;mail.lamp.com.INA
;; ANSWER SECTION:
mail.lamp.com.600INA10.109.134.237
;; AUTHORITY SECTION:
lamp.com.600INNSns.lamp.com.
;; ADDITIONAL SECTION:
ns.lamp.com.600INA10.109.134.237
;; Query time: 0 msec
;; SERVER: 10.109.134.237#53(10.109.134.237)
;; WHEN: Wed Mar 1 13:46:39 2017
;; MSG SIZE rcvd: 80
[root@mail named]# cd /etc/postfix
[root@mail postfix]# vim main.cf #编辑postfix邮箱服务主配置文件,内容如下;
[root@mail postfix]# service postfix restart
关闭 postfix: [确定]
启动 postfix: [确定]
[root@mail postfix]# vim /etc/resolv.conf #编辑DNS配置
[root@mail postfix]# telnet mail.lamp.com 25
Trying 10.109.134.237...
Connected to mail.lamp.com.
Escape character is '^]'.
220 mail.lamp.com ESMTP Postfix
helo mail.lamp.com
250 mail.lamp.com
mail from:test@test.com
250 2.1.0 Ok
rcpt to:admin@xuelinux.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
hello
.
250 2.0.0 Ok: queued as 2623AE31
quit
221 2.0.0 Bye
Connection closed by foreign host.
postfix2.10下载地址:
ftp://ftp.cuhk.edu.hk/pub/packages/mail-server/postfix/index.html
本文转自wang650108151CTO博客,原文链接: http://blog.51cto.com/woyaoxuelinux/1902352,如需转载请自行联系原作者