Postfix smarthost,允许通过动态 IP 中继

Postfix smarthost,允许通过动态 IP 中继

我有几个安装了 postfix 的服务器(web、mysql、java),它们被设置为中继到智能主机 postfix 服务器。

DYNAMIC IP                              STATIC IP            INTERNET
[PHP -> sendmail -> 25:postfix:2525] -> [2525:postfix:25] -> [25:external]

问题是第一台服务器有动态 IP 地址,所以我不能简单地将它们的 IP 地址添加到中间 Postfix 服务器的 main.cf 中的 mynetworks 设置中。

我认为解决方案是 SASL,但我不知道如何在第一个上设置用户名:密码并在第二个上进行身份验证。

这是我在中继上所拥有的

apt-get install postfix libsasl2-modules

cat > /etc/postfix/main.cf << 'EOF'
myhostname = a-eu1-test-http
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
relayhost = [smarthost]:2525
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mydestination = a-eu1-test-http, localhost
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only

smtpd_banner = $myhostname ESMTP $mail_name
biff = no
append_dot_mydomain = no
readme_directory = no

smtp_tls_security_level = encrypt
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/relay_password
smtp_sasl_security_options = noanonymous
EOF

这是我在智能主机上拥有的,但我不知道如何定义 sasl 用户:

apt-get install postfix libsasl2-modules

cat > /etc/postfix/main.cf << 'EOF'
myorigin = /etc/mailname
myhostname = smarthost
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mydestination = smarthost, localhost
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all

smtpd_banner = $myhostname ESMTP $mail_name
biff = no
append_dot_mydomain = no
readme_directory = no

smtpd_tls_security_level = encrypt
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname

smtp_tls_security_level = may
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
EOF

答案1

你基本上错过了身份验证后端

在继电器上:

apt-get install postfix libsasl2-2 libsasl2-modules sasl2-bin

adduser postfix sasl

mkdir /etc/postfix/sasl
cat > /etc/postfix/sasl/smtpd.conf << EOF
pwcheck_method: saslauthd
mech_list: PLAIN LOGIN
EOF

cat > /etc/default/saslauthd << EOF
START=yes
MECHANISMS="sasldb"
OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd"
EOF

saslpasswd2 -c -u `postconf -h myhostname` relay-user

service saslauthd start

在客户端上:

cat > /etc/postfix/relay_passwords << EOF
your-relay:2525  relay-user:password
EOF
postmap /etc/postfix/relay_passwords

相关内容