Author Topic: postfix Restricting what users can send mail to off-site destinations  (Read 12031 times)

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
postfix Restricting what users can send mail to off-site destinations
« on: มกราคม 23, 2011, 10:18:10 PM »
    โจทย์ ใช้ MTA : Postfix
    OS : Freebsd
    ครับ

    จะ set ให้ บาง user= golf@example.com สามารถส่งเมลออกไป domain ข้างนอกไม่ได้ (Ex.
    golfreeze@hotmail.com , sss@yahoo.com )
    แต่ว่ามีให้ user= golfreeze@example.com ส่งได้ จะต้อง set อย่างไงบ้าง

    ก่อนอื่นต้องทำความเข้าใจก่อนว่า ไฟล์ไหนของ postfix ทำงานอย่างไร ทำงานอะไร

    ในกรณีนี้ เราต้องแก้ไขที่ไฟล์ main.cf ครับ

    เพิ่มในส่วนของ

    ###Allow some user sending email off-site #####
    smtpd_sender_restrictions=check_sender_access hash:/usr/local/etc/postfix/sender_restrictions
    smtpd_restriction_classes = local_only
    local_only =
    check_recipient_access hash:/usr/local/etc/postfix/local_domains, reject
    ##### End of Config ########

    แล้วทำการแอด mail account ที่จะใช้กับ policy check_sender_access นีัครับ

    #vi /usr/local/etc/postfix/sender_restrictions
    golf@example.com local_only

    #postmap /usr/local/etc/postfix/sender_restrictions

    #vi /usr/local/etc/postfix/local_domains
    เพิ่ม domain ที่จะให้บังคับใช้งาน policy นี้
    example.com OK
    #postmap /usr/local/etc/postfix/local_domains

    แล้วทำการ restart postfix 1 รอบ แล้วลองส่งดูครับ

    smtp00# telnet localhost 25
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    220 smtp.packetlove.com ESMTP Postfix
    helo e
    250 smtp.packetlove.com
    ehlo e
    250-smtp.packetlove.com
    250-PIPELINING
    250-SIZE 102400000
    250-ETRN
    250-AUTH LOGIN
    250-AUTH=LOGIN
    250-ENHANCEDSTATUSCODES
    250-8BITMIME
    250 DSN
    mail from: golf@example.com
    250 2.1.0 Ok
    rcpt to: golfreeze@hotmail.com
    554 5.7.1 < golf@example.com>;: Sender address rejected: Access denied
    quit
    221 2.0.0 Bye
    Connection closed by foreign host.

    ### ใช้งานได้แล้ว ###

m_golfreeze.gif golfreeze [2009-12-08 15:54:50] mail not show 116.68.146.74

1

Comment : 1

    ### อ่านเพิ่มเติมได้ที่

    http://www.postfix.org/RESTRICTION_CLASS_README.html#external

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: postfix Restricting what users can send mail to off-site destinations
« Reply #1 on: มกราคม 23, 2011, 10:18:16 PM »
### อ่านเพิ่มเติมได้ที่

http://www.postfix.org/RESTRICTION_CLASS_README.html#external

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: postfix Restricting what users can send mail to off-site destinations
« Reply #2 on: มกราคม 23, 2011, 10:18:26 PM »
มีอีกกรณีครับ สมมติว่า ไม่การให้ user บาง คน รับเมลจาก ภายนอกได้

ก็สามารถ config ที่ไฟล์ main.cf ของ postfix ได้ตามนี้นะครับ

###Not allow to receive email from External domain
smtpd_recipient_restrictions =
check_recipient_access hash:/usr/local/etc/postfix/protected_destinations
smtpd_restriction_classes = insiders_only
insiders_only =
check_sender_access hash:/usr/local/etc/postfix/insiders, reject
##############################################

เพิ่มconfig file "insiders" ด้วย domain ที่จะทำการจำกัดสิทธิ์ดังนี้
example.com OK
เพิ่มconfig file "protected_destinations" ด้วย email account
ที่จะทำการจำกัดสิทธิ์ดังนี้
pass@example.com insiders_only

#postmap /usr/local/etc/postfix/insiders

#postmap /usr/local/etc/postfix/protected_destinations

#/usr/local/etc/rc.d/postfix restart

โดยที่ ถ้ามี account ss@hotmail.com คือปลายทางส่งเข้ามาถึง user "pass@example.com ที่อยู่ใน
list ปลายทางจะได้รับ error message ว่า
################################################
This message was created automatically by mail delivery software.

A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:

pass@example.com
SMTP error from remote mail server after RCPT TO:<pass@example.com>;:
host mx1.example.com [11.111.11.1]: 554 5.7.1 <pass@example.com>;:
Recipient address rejected: Access denied
#########################################

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: postfix Restricting what users can send mail to off-site destinations
« Reply #3 on: มกราคม 23, 2011, 10:18:40 PM »
ถ้าต้องการให้ account ใน example.com ส่งเข้าได้เฉพาะ domain

example.com
hotmail.com

ก็เพิ่มในไฟล์ local_domains เป็น
example.com OK
hotmail.com OK

postmap /etc/postfix/local_domains
/etc/init.d/postfix restart

mahnok

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
Re: postfix Restricting what users can send mail to off-site destinations
« Reply #4 on: กุมภาพันธ์ 09, 2011, 10:18:11 AM »
เราสามารถทำ relayhost  ได้ปล่าวครับ

relayhost ไปที่ smtp.3bbmail.com

ขอบคุณครับ

golfreeze

  • Administrator
  • Hero Member
  • *****
  • Posts: 2140
    • View Profile
    • นั่งสมาธิ สติปัฏฐานสี่ พาเที่ยววัด แนะนำวัด แจกcd ธรรมะฟรี
    • Email
Re: postfix Restricting what users can send mail to off-site destinations
« Reply #5 on: กุมภาพันธ์ 10, 2011, 11:08:25 AM »
เราสามารถทำ relayhost  ได้ปล่าวครับ

relayhost ไปที่ smtp.3bbmail.com

ขอบคุณครับ

ปกติพวก mta อย่าง postfix , exim , sendmail สามารถทำ relayhost ได้อยู่แล้วนะครับผม

แต่ในส่วนนี้จะเป็นการทำ restriction อ่าครับ ระบุเฉพาะเจาะจง ว่า user ใดสามารถส่งหาใครได้บ้าง ห้ามส่งหาใครบ้างครับผม