限制部分用户只能进行内部收发邮件 配置
时间:2006-04-20 来源:y.kevin
转自postfix 在中国
限制部分Postfix用户只能内部收发的例子
其实原则比较简单,就是检查MAIL FROM:阶段的邮件地址,如果匹配规则中的地址,则应用相应的限制原则,否则按默认的规则。
配置方法:
1)在main.cf里定义如下的smtpd_restriction_classes:
# restrictions
smtpd_restriction_classes = local_only
local_only = check_recipient_access hash:/etc/postfix/local_domains, reject
2)将main.cf里的smtpd_recipient_restrctions定义为:
smtpd_recipient_restrictions =
check_sender_access hash:/etc/postfix/local_senders
permit_mynetworks,
permit_sasl_authenticated,
reject_non_fqdn_hostname,
reject_non_fqdn_sender,
reject_non_fqdn_recipient,
reject_unauth_destination,
reject_unauth_pipelining,
reject_invalid_hostname
3)编辑/etc/postfix/local_senders:
[email protected] local_only
[email protected] local_only
extmail.org local_only #对域名的限制
4)编辑/etc/postfix/local_domains:
internal.foo.com OK
internal.bar.com OK
5)为3,4的文件建立hash:
# postmap hash:/etc/postfix/local_senders
# postmap hash:/etc/postfix/local_domains
最好用root生成上述hash。
这样,就定义了extmail.org域里的foo和bar两个用户,只能给internal.foo.com和internel.bar.com 两个域名发邮件。这两个域名就是常规说的内部邮件域了。
如果这两个用户企图给外部发邮件,将遇到如下错误:
554 5.7.1 <[email protected]>: Sender address rejected: Access denied
这样就基本达到了目的了。
################################################
限制部分Postfix用户只能进行内部收发例子(改进版)
应redfox及其他一些用户的要求,给出一个通过识别客户端IP地址来限制客户只能进行内部收发的例子。
利用check_client_access 规则,检查客户端IP地址是否属于被限制的范围,如果匹配规则中的IP地址,则应用相应的限制原则,否则按默认的规则。
配置方法:
1)在main.cf里定义如下的smtpd_restriction_classes:
# restrictions for local users - by extmail.org
smtpd_restriction_classes = local_only
local_only =
check_recipient_access hash:/etc/postfix/local_domains,
check_sender_access hash:/etc/postfix/local_domains,
reject
2)将main.cf里的smtpd_recipient_restrctions定义为:
# local users restriction - by extmail.org
smtpd_recipient_restrictions =
check_client_access hash:/etc/postfix/local_users,
permit_mynetworks,
permit_sasl_authenticated,
reject_non_fqdn_hostname,
reject_non_fqdn_sender,
reject_non_fqdn_recipient,
reject_unauth_destination,
reject_unauth_pipelining,
reject_invalid_hostname
3)编辑/etc/postfix/local_users:
192.168.0 local_only
192.168.1.5 local_only
4)编辑/etc/postfix/local_domains:
internal.foo.com OK
internal.bar.com OK
5)为3,4的文件建立hash:
# postmap hash:/etc/postfix/local_users
# postmap hash:/etc/postfix/local_domains
最好用root生成上述hash。
这样,就定义了extmail.org域里的192.168.0.0/24网段及192.168.1.5这个客户机只能收发internal.foo.com和internel.bar.com 两个域名的邮件。这两个域名就是常规说的内部邮件域了。
如果这两类用户企图给外部发邮件,将遇到如下错误:
554 5.7.1 <[email protected]>: Sender address rejected: Access denied
这样就基本达到了目的了。