Configure Postfix to Relay Mail to an External SMTP Server on CentOS 7.

We have two CentOS 7 (minimal) servers installed which we want to configure as follows:

admin1.hl.local (10.11.1.2) – will be configured as a Postfix relay
admin2.hl.local (10.11.1.3) – will be configured as a Postfix relay

Both servers have SELinux set to enforcing mode.

See the image below to identify the homelab part this article applies to.

https://www.lisenet.com/wp-content/uploads/2018/04/lisenet-homelab-diagram_admin.png

Software

Software used in this article:

CentOS 7

Postfix 2.10

Install Postfix

Note that this section applies to both servers.

Install Postfix and ensure that the service is enabled:

# yum install postfix cyrus-sasl-plain

# systemctl enable postfix

In case Sendmail is installed, remove it:

# yum remove -y sendmail*

Allow inbount firewall traffic:

# iptables -A INPUT -s 10.11.1.0/24 -p tcp -m state –state NEW –dport 25 -j ACCEPT

Configure Postfix Server as a Relay

Note that this section applies to both servers. Open /etc/postfix/main.cf for editing and configure the following:

smtpd_banner = $myhostname ESMTP

inet_interfaces = all

inet_protocols = ipv4

mynetworks = 127.0.0.0/8, 192.168.0.0/16

relayhost = [smtp.gmail.com]:587

smtp_sasl_auth_enable = yes

smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd

smtp_sasl_security_options = noanonymous

smtp_tls_CApath = /etc/ssl/certs

smtp_use_tls = yes

Create a new file /etc/postfix/sasl_passwd and add the authentication details of the external SMTP server:

[smtp.gmail.com]:587 hoanghd164@gmail.com:HadanghoangHathiyen19901993

Prevent non-root access:

# chmod 0600 /etc/postfix/sasl_passwd

Create a database file:

# postmap /etc/postfix/sasl_passwd

Check configuration and restart Postfix service:

# postfix check

# systemctl restart postfix

Configure Postfix on a Null Client

When we configure other homelab servers to us Postfix to relay emails via admin1 and admin2, we can have a fallback relay defined (taken from the Postfix configuration file /etc/postfix/main.cf that’s on the Katello server):

relayhost = [admin1.hl.local]

fallback_relay = [admin2.hl.local]

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *