-1

I have a postfix server that is on a public IPV4 address. I want to allow postfix to send emails ONLY to this IPV4 address (the same). Tried many things but no success...

Any idea ? Thanks in advance.

++EDIT01 : there are several domains on this server, and I want ONLY ONE domain to send emails to itself.

bv4nuf
  • 1
  • 1
  • Does this answer your question? [how can i disable outbound mail in postfix?](https://serverfault.com/questions/271260/how-can-i-disable-outbound-mail-in-postfix) – HBruijn Apr 18 '23 at 12:40
  • 1
    The alternative, block egress port 25 in your firewall rules and/or security groups or https://serverfault.com/a/106447/37681 – HBruijn Apr 18 '23 at 12:41
  • if @HBruijn's comments do not answer your question please explain why you want to use the public IP address – Jasen Apr 18 '23 at 13:03
  • @jasen there are several domains on this server, and I want ONLY ONE domain to send emails to itself – bv4nuf Apr 18 '23 at 15:21
  • 1
    so use localhost, you don't need the public address involved at all. – Jasen Apr 18 '23 at 20:24

1 Answers1

0

You can use the Postfix transport map to configure the delivery behavior for the specific domain.

Create a new file called /etc/postfix/transport

example.com smtp:[1.2.3.4]

Replace example.com with the domain that you want to restrict, and 1.2.3.4 with the IPv4 address of your Postfix server.

Create a new file called /etc/postfix/restrictions

/^example\.com$/     OK
/^example\..*/       REJECT
/.*@example\.com$/   OK
/.*@example\..*/     REJECT

Replace example.com with the domain you want to restrict. This file will help you restrict the domain to send emails only to itself.

Add the following lines to your /etc/postfix/main.cf file:

transport_maps = hash:/etc/postfix/transport
smtpd_sender_restrictions = check_sender_access pcre:/etc/postfix/restrictions

Run the following commands to compile the transport map and reload Postfix:

sudo postmap /etc/postfix/transport
sudo systemctl reload postfix

Now, the specified domain should only be able to send emails to the same IPv4 address, and other domains should continue to operate as before.

DenisZ
  • 38
  • 7