首页 Linux网维 Linux服务器的构建Postfix文档

Linux服务器的构建Postfix文档

在CentOS中,默认的邮件服务器(SMTP方面)是sendmail,但sendmail有若干的缺点,比如,配置复杂、安全漏洞曾被多次发现–并且依然存在隐患、邮件发送速…

Linux服务器的构建Postfix文档插图

在CentOS中,默认的邮件服务器(SMTP方面)是sendmail,但sendmail有若干的缺点,比如,配置复杂、安全漏洞曾被多次发现–并且依然存在隐患、邮件发送速度慢等等,这里就不再一一叙述。

而另一个被广泛应用于邮件服务方面的“Postfix”的缺点就少得多,或者说它就是针对于sendmail的缺点,而被设计的对应sendmail的短处,它在各方面也比较成熟所以,无特殊要求,这里不推荐用sendmail

来构建邮件服务器本站介绍的邮件服务器配置方法,也将基于Postfix确认MX记录的添加是否生效的方法:[root@sample ~]#host -t mx centospub.comcentospub.com mail is handled by 10 mail.centospub.com.。

确认MX记录生效然后安装postfix[root@sample ~]#yum -y install postfix在线安装Postfix对postfix进行配置[root@sample ~]#vi /etc/postfix/main.cf

编辑Postfix的配置文件#myhostname = host.domain.tld找到此行,将等号后面的部分改写为主机名myhostname = sample.centospub.com变为此状态,设置系统的主机名

#mydomain = domain.tld找到此行,将等号后面的部分改写为域名mydomain = centospub.com变为此状态,设置域名(我们将让此处设置将成为E-mail地址“@”后面的部分)

#myorigin = $mydomain找到此行,将行首的#去掉myorigin = $mydomain变为此状态,将发信地址“@”后面的部分设置为域名(非系统主机名)inet_interfaces = localhost

找到此行,将“localhost”改为“all”inet_interfaces = all变为此状态,接受来自所有网络的请求mydestination = $myhostname, localhost.$mydomain, localhost

找到此行,在行为添加“$mydomain”mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain变为此状态,指定发给本地邮件的域名

#relay_domains = $mydestination找到此行,将行首的#去掉relay_domains = $mydestination变为此状态,定义允许转发的域名#mynetworks = 168.100.189.0/28, 127.0.0.0/8

找到此行,依照自己的内网情况修改mynetworks = 168.100.189.0/28, 127.0.0.0/8变为此状态,指定内网和本地的IP地址范围#home_mailbox = Maildir/

找到这一行,去掉行首的#home_mailbox = Maildir/变为此状态,指定用户邮箱目录# SHOW SOFTWARE VERSION OR NOT## The smtpd_banner parameter specifies the text that follows the 220

# code in the SMTP servers greeting banner. Some people like to see# the mail version advertised. By default, Postfix shows no version.

## You MUST specify $myhostname at the start of the text. That is an# RFC requirement. Postfix itself does not care.

##smtpd_banner = $myhostname ESMTP $mail_name#smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)

找到这一行,接此行添加如下行:smtpd_banner = $myhostname ESMTP unknow添加这一行,不显示SMTP服务器的相关信息在配置文件的文尾,添加如下行:smtpd_sasl_auth_enable = yes

服务器使用SMTP认证smtpd_sasl_local_domain = $myhostname指定SMTP认证的本地域名(主机名)smtpd_sasl_security_options = noanonymous

不允许匿名的方式认证smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination

message_size_limit = 15728640规定邮件最大尺寸为15MB2、 配置SMTP认证的相关选项为了提高安全性,我们不将系统用户的密码作为相应用户SMTP认证的密码,而将在后面为用户建立

SMTP认证专用的密码[root@sample ~]#vi /usr/lib/sasl2/smtpd.conf编辑SMTP认证的配置文件pwcheck_method: saslauthd找到此行,将“saslauthd”

改为“auxprop”pwcheck_method: auxprop不使用系统用户密码作为用户的SMTP认证密码[root@sample ~]# vi /etc/sysconfig/saslauthdMECH=shadow

找到这一行,在前面加# #MECH=shadow不使用shadow机制FLAGS=找到此行,在等号后面添加“sasldb”FLAGS=sasldb 定义认证方式为sasldb23、建立用户的邮箱目录首先建立用户模板下的邮箱目录,以便于建立新用户时,相应用户的邮箱目录自动被建立。

[root@sample ~]#mkdir /etc/skel/Maildir在用户模板下建立用户邮箱目录[root@sample ~]#chmod 700 /etc/skel/Maildir设置用户邮箱目录属性为

700然后再为已经存在的用户创建相应有项目了[root@sample ~]#mkdir /home/centospub/Maildir为用户(这里以centospub用户为例)建立邮箱目录[root@sample ~]#。

chmod 700 /home/centospub/Maildir设置该用户邮箱目录属性为700[root@sample ~]#chown centospub. /home/centospub/Maildir

设置该用户邮箱目录为该用户所有4、为用户设置smtp认证密码[root@sample ~]#saslpasswd2 -u sample.centospub.com -c centospub为centospub

用户设置SMTP认证密码Password:在这里输入密码(不会显示)Again (for verification):再次输入密码5、改变SALS的属性及归属[root@sample ~]#chgrp postfix /etc/sasldb2

将数据库归属改为postfix,[root@sample ~]#chmod 640 /etc/sasldb2将数据库属性改为6406、关闭sendmail服务及设置默认MTA因为在用Postfix作为SMTP

服务器的前提下,我们不准备再用sendmail,所以将sendmail服务关掉,以确保安全及节省系统资源[root@sample ~]#/etc/rc.d/init.d/sendmail stop关闭sendmail

服务Shutting down sendmail:[OK]Shutting down sm-client: [OK][root@sample ~]#chkconfig sendmail off关闭sendmail

自启动[root@sample ~]#chkconfig –list sendmail确认sendmail自启动已被关闭(都为off就OK)sendmail0:off 1:off 2:off 3:off 4:off 5:off 6:off

然后再将默认的MTA设置为Postfix[root@sample ~]#alternatives –config mta设置默认MTAThere are 2 programs which provide mta.。

Selection Command———————————————–1 /usr/sbin/sendmail.sendmail当前状态:sendmail

为默认MTA2 /usr/sbin/sendmail.postfixEnter to keep the current selection[+], or type selection number: 2

在这里输入2,使Postfix成为默认MTA启动相应服务最后,启动SMTP认证及Postfix服务,并设置相应服务为自启动[root@sample ~]#chkconfig saslauthd on将SMTP-Auth

设置为自启动[root@sample ~]#chkconfig –list saslauthd确认SMTP-Auth服务状态saslauthd 0:off 1:off2:on 3:on 4:on 5:on

6:off确认2~5为on的状态就OK[root@sample ~]#/etc/rc.d/init.d/saslauthd start启动SMTP-AuthStarting saslauthd: [OK

][root@sample ~]#chkconfig postfix on将Postfix设置为自启动[root@sample ~]#chkconfig –list postfix确认Postfix服务状态

postfix 0:off 1:off2:on 3:on 4:on 5:on6:off确认2~5为on的状态就OK[root@sample ~]#/etc/rc.d/init.d/postfix star

t启动PostfixStarting postfix: [OK]至此,就完成了SMTP服务器方面的配置,但目前只具从备客户端通过服务器发送邮件的功能做为完整的邮件服务器,还需具备从客户端通过POP/IMAP。

协议接受邮件到本地的功能。

免责声明:文章内容不代表本站立场,本站不对其内容的真实性、完整性、准确性给予任何担保、暗示和承诺,仅供读者参考,文章版权归原作者所有。如本文内容影响到您的合法权益(内容、图片等),请及时联系本站,我们会及时删除处理。

作者: 3182235786a

为您推荐

linux文件命令

linux文件命令

在 Linux 中,我们可以使用 `with open()` 语句和 `write()` 函数来写入文件。以下是一个简单...
linux的命令

linux的命令

以下是一个简单的 Linux 命令示例,该命令将显示当前日期和时间: “`c #include <st...
linux 命令

linux 命令

由于 Linux 命令是由 C 语言编写的,因此下面是一个简单的用中文编写的 Linux 命令示例,它将输出“Hello...
linux命令tar

linux命令tar

这个问题看起来有些模糊,我不确定您是想了解如何在 Linux 系统中使用 tar 命令,还是如何编写一个名为 tar 的...
linux压缩命令

linux压缩命令

Linux压缩命令:高效管理文件和目录 Linux操作系统提供了一系列强大的压缩命令,使您能够高效地管理文件和目录。无论...

发表回复

返回顶部