基于CentOS搭建SMTP服务器

来源:互联网 发布:effective java电子版 编辑:程序博客网 时间:2024/04/20 06:06

1环境

[root@iZ11uh778whZMaildir]# uname –a


[root@iZ11uh778whZMaildir]# cat /etc/issue


2安装posfix

查看posfix的版本

[root@iZ11uh778whZMaildir]# postconf mail_version

一般是默认就安装了posfix的,如果没有暗转的话,是用yum -yinstall postfix安装

[root@iZ11uh778whZMaildir]# yum -y install postfix


3更改默认邮件传输代理(MTA)

查看默认的mta

[root@iZ11uh778whZMaildir]# alternatives --display mta

我们可以看到默认的mta就是postfix,也许是sendmail,如果不是postfix,则修改为postfix

[root@iZ11uh778whZMaildir]# alternatives --config mta

 

There is1 program that provides 'mta'.

 

  Selection   Command

-----------------------------------------------

*+1           /usr/sbin/sendmail.postfix

 

Enter to keepthe current selection[+], or type selection number: 1

4配置postfix

Postfix的配置文件主要有:/etc/postfix/main.cf和/etc/postfix/master.cf

我们主要修改/etc/postfix/main.cf

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

将#myhostname =virtual.domain.tld前面的‘#’去掉,改为

myhostname = localhost //系统的主机名称

 

将#mydomain = domain.tld前面的‘#’去掉,改为

mydomain = 51cs8.com //email的地址,为可用的域名

 

将#myorigin = $mydomain前面的‘#’去掉,改为

myorigin = $mydomain //指定本地发送邮件中来源和传递显示的域名

 

将#inet_interfaces =localhost前的‘#’去掉,改为

inet_interfaces = all //设置网络接口以便Postfix能接收到邮件

 

将#mydestination =$myhostname, localhost.$mydomain, localhost前面的‘#’去掉,改为

mydestination = $myhostname, localhost.$mydomain, localhost,$mydomain //指定哪些邮件地址允许在本地发送邮件

 

将#local_recipient_maps = 前面的‘#’去掉,改为

local_recipient_maps =

 

将#mynetworks =168.100.189.0/28, 127.0.0.0/8前面的‘#’去掉,改为

mynetworks = 10.47.200.0/21, 127.0.0.0/8 //根据自己内网的实际情况写,指定受信任SMTP的列表,具体的说,受信任的SMTP客户端允许通过Postfix传递邮件

 

将#home_mailbox = Maildir前面的‘#’去掉,改为

home_mailbox = Maildir/ //设置邮箱路径与用户目录有关,也可以指定要使用的邮箱风格。

 

将#smtpd_banner = $myhostnameESMTP $mail_name ($mail_version)前面的‘#’去掉,改为

smtpd_banner = $myhostname ESMTP unknow //不显示SMTP服务器的相关信息

在配置文件的最后追加如下内容:

#smtpd

smtpd_sasl_auth_enable = yes //使用smtp认证

broken_sasl_auth_clients = yes //让不支持RFC2554smtpclient也可以跟postfix做交互。

smtpd_sasl_local_domain = $myhostname //指定SMTP认证的本地域名 

smtpd_sasl_security_options = noanonymous //取消匿名登陆方式 

smtpd_recipient_restrictions = permit_mynetworks,permit_sasl_authenticated, reject_unauth_destination //设定邮件中有关收件人部分的限制

5安装cyrus-sasl、cyrus-imapd相关包

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

因为我之前安装过,所提提示已经安装。

6配置cyrus-sasl

Cyrus-sasl的配置文件路径:/etc/sasl2/smtpd.conf

[root@iZ11uh778whZ postfix]# vim /etc/sasl2/smtpd.conf

在文件尾部追加

log_level: 3 //记录log的模式  

saslauthd_path:/var/run/saslauthd/mux //设置一下smtp寻找cyrus-sasl的路径

下面是我/etc/sasl2/smtpd.conf的内容:

pwcheck_method: saslauthd

mech_list: plain login

log_level: 3

saslauthd_path: /var/run/saslauthd/mux

7启动postfix、cyrus-sasl、cyrus-imapd

[root@iZ11uh778whZ postfix]# /etc/init.d/postfix restart

Shutting down postfix:                                     [  OK  ]

Starting postfix:                                          [ OK  ]

[root@iZ11uh778whZ postfix]# /etc/init.d/saslauthd restart

Stopping saslauthd:                                        [  OK  ]

Starting saslauthd:                                        [  OK  ]

[root@iZ11uh778whZ postfix]# /etc/init.d/cyrus-imapd restart

Shutting down cyrus-imapd:                                 [  OK  ]

Exporting cyrus-imapd databases:                           [  OK  ]

Importing cyrus-imapd databases:                           [  OK  ]

Starting cyrus-imapd:                                      [  OK  ]

查看smtp启动情况:

[root@iZ11uh778whZ postfix]# netstat -tpnl | grep 25

tcp       0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      1714/master

查看imap启动情况:

[root@iZ11uh778whZ postfix]# netstat -tpnl | grep cyrus

tcp       0      0 0.0.0.0:110                0.0.0.0:*                  LISTEN      2687/cyrus-master  

tcp       0      0 0.0.0.0:143                0.0.0.0:*                  LISTEN      2687/cyrus-master  

tcp       0      0 0.0.0.0:4190                0.0.0.0:*                   LISTEN      2687/cyrus-master  

tcp       0      0 0.0.0.0:993                 0.0.0.0:*                   LISTEN      2687/cyrus-master  

tcp       0      0 0.0.0.0:995                 0.0.0.0:*                   LISTEN      2687/cyrus-master

8设置postfix、cyrus-sasl、cyrus-imapd开机自启动

[root@iZ11uh778whZ postfix]# chkconfig postfix on

[root@iZ11uh778whZ postfix]# chkconfigpostfix --list

postfix              0:off 1:off 2:on 3:on 4:on 5:on 6:off

[root@iZ11uh778whZ postfix]# chkconfig saslauthd on

[root@iZ11uh778whZ postfix]# chkconfigsaslauthd --list

saslauthd           0:off 1:off 2:on 3:on 4:on 5:on 6:off

[root@iZ11uh778whZ postfix]# chkconfig cyrus-imapd on

[root@iZ11uh778whZ postfix]# chkconfig cyrus-imapd--list

cyrus-imapd         0:off 1:off 2:on 3:on 4:on 5:on 6:off

9测试cyrus-sasl

添加账号、密码 system | system

[root@iZ11uh778whZ postfix]# useradd system

[root@iZ11uh778whZ postfix]# passwd system

Changing password for user system.

New password:

BAD PASSWORD: it is based on a dictionaryword

BAD PASSWORD: is too simple

Retype new password:

passwd: all authentication tokens updatedsuccessfully.

测试是否可用

 [root@iZ11uh778whZpostfix]# testsaslauthd -u system -p system

0: OK "Success."

10测试cyrus-imapd

安装完cysus-imapd会自动产生一个管理账号cyrus,所属用户组是mail

[root@iZ11uh778whZ tank]# id cyrus

uid=76(cyrus) gid=12(mail)groups=12(mail),76(saslauth)

将账户system的所在组切换到mail组

[root@iZ11uh778whZ tank]# usermod -g 12 system

[root@iZ11uh778whZ tank]# id system

uid=502(system) gid=12(mail)groups=12(mail)

添加测试账号:

[root@iZ11uh778whZtank]# cyradm -u cyrus localhost --auth plain
0 0
原创粉丝点击