本文基本centos6.10,postfix2.11.11
postfix基本配置
myhostname:定义主机名,判断当前主机工作在什么位置,跟mx记录对应的主机名称一致
mydomain:自己所处的核心域
mynetworks:定义本地网络,允许给中继的网络或地址
mydestination:自己为哪些发往目标收取邮件,如目标不是此处定义的域的,则要进行中继
myorigin:发件人地址伪装,通常是本地域名,会为发件人补充地址
inet_interfaces:定义postfix进程监听的IP地址
postfix基于客户端的访问控制
查找表
访问控制文件,
/etc/postfix/access —Hash格式 ---->/etc/postfix/access.db
tye@test.com reject
edison@test.com ok
自定义访问表的条件通常使用check_client_access,check_helo_access,check_sender_access,check_recipient_access进行,它们后面跟上type:mapname格式的访问表类型和名称。其中check_sender_access和check_recipient_access用来检查客户端提供的邮件地址,因此,其访问表中可以使用完整的邮件地址,如admin@test.com;也可以使用域名,如test.com还可以只使用用户的一部分:admin@
拒绝客户端192.168.88.1发送邮件
#修改/etc/postfix/access文件
192.168.88.1 REJECT
#将access文件转换为hash格式
postmap /etc/postfix/access
[root@mail ~]# ls /etc/postfix/access*
/etc/postfix/access /etc/postfix/access.db
#配置postfix使用此文件对客户端进行检查
#编辑/etc/postfix/main.cf文件,添加以下参数
smtpd_client_restrictions = check_client_access hash:/etc/postfix/access #hash表示带有.db的文件,后面文件名不用加.db
#重新启动postfix或重新载入配置文件
service postfix restart
#使用192.168.88.1这台机器测试发送邮件
[C:\~]$ telnet 192.168.88.135 25
Connecting to 192.168.88.135:25...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
220 Welcome to our mail.tye.com ESMTP,Warning:Version not Available!
helo mail.tye.com
250 mail.tye.com
mail from :root
501 5.5.4 Syntax: MAIL FROM:<address>
mail from: root
250 2.1.0 Ok
rcpt to: hadoop
**554 5.7.1 <unknown[192.168.88.1]>: Client host rejected: Access denied**
#使用本机测试,一切正常
[root@mail ~]# telnet localhost 25
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 Welcome to our mail.tye.com ESMTP,Warning:Version not Available!
helo mail.tye.com
250 mail.tye.com
mail from: root
250 2.1.0 Ok
rcpt to: hadoop
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
123
1
,
.
250 2.0.0 Ok: queued as D8457BF30C
quit
221 2.0.0 Bye
Connection closed by foreign host.
拒绝发件人域为whitehose.com的所有人发送邮件
#在/etc/postfix/access文件修改如下,来对发送者的域进行控制
whitehouse.com REJECT
#转换为hash格式文件
[root@mail ~]# postmap /etc/postfix/access
#在/etc/postfix/main.cf中配置中添加以下行
smtpd_sender_restrictions = check_sender_access hash:/etc/postfix/access
[root@mail ~]# telnet localhost 25
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 Welcome to our mail.tye.com ESMTP,Warning:Version not Available!
helo mail.tye.com
250 mail.tye.com
mail from: sender@whitehouse.com
250 2.1.0 Ok
rcpt to: hadoop
**554 5.7.1 <sender@whitehouse.com>: Sender address rejected: Access denied**
拒绝向haddoop域的所有人发送邮件
#编译/etc/postfix/recipient,建制所有人不能向hadoop发送邮件
[root@mail ~]# vim /etc/postfix/recipient
hadoop@ REJECT
#转换为hash格式文件
[root@mail ~]# postmap /etc/postfix/recipient
[root@mail ~]# ls /etc/postfix/recipient*
/etc/postfix/recipient /etc/postfix/recipient.db
#修改postfix配置文件,/etc/postfix/main.cf
[root@mail ~]# vim /etc/postfix/main.cf
smtpd_recipient_restrictions = hash:/etc/postfix/recipient,permit_mynetworks,permit_sasl_authenticated,reject_invalid_hostname,reject_non_fqdn_hostname,reject_unknown_sender_domain,reject_non_fqdn_sender,reject_non_fqdn_recipient,reject_unknown_recipient_domain,reject_unauth_pipelining,reject_unauth_destination
#测试发送邮件
[root@mail ~]# telnet localhost 25
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 Welcome to our mail.tye.com ESMTP,Warning:Version not Available!
helo mail.tye.com
250 mail.tye.com
mail from: tye@tye.com
250 2.1.0 Ok
rcpt to:hadoop
**554 5.7.1 <hadoop>: Recipient address rejected: Access denied**