Debian – Restrict relay with postfix to certain domain from single IP

debianpostfix

In my company we're using Postfix as a relay for Google Apps SMTP server in a Debian server. Legacy machines like scanners forward messages to our relay server.

How can i allow the scanner to only send mails through the relay only to certain domains (e.g. our .com)?

I'm pretty sure there's something here but I haven't found something working.

Thanks.

Best Answer

You can use postfwd to restrict the domains a specific IP address can send email to (regardless of relay):

action=REJECT; client_address=192.168.1.9; recipient_domain!~/dom1\.com|dom2\.com/

Easy installation on Ubutu server is as follows:

$ apt install postfwd
$ vi /etc/postfix/main.cf
  smtpd_recipient_restrictions = check_policy_service inet:127.0.0.1:10040
$ vi /etc/postfix/postfwd.cf
  action=REJECT; client_address=192.168.1.9; recipient_domain!~/dom1\.com|dom2\.com/
$ systemctl restart postfwd postfix