IT/linux

[linux] postfix 구축

주니- 2022. 8. 25. 23:06

환경 : Ubuntu 20.04

패키지 : postfix, sasl

# postfix install
apt-get install postfix

/etc/postfix/main.cf
# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# See http://www.postfix.org/COMPATIBILITY_README.html -- default to 2 on
# fresh installs.
compatibility_level = 2

# TLS parameters
smtpd_tls_cert_file=/root/cert/pem/*.pem
smtpd_tls_key_file=/root/cert/pem/*.key
smtp_tls_cert_file=/root/cert/pem/*.pem
smtp_tls_key_file=/root/cert/pem/*.key
# smtp_tls_security_level=may -> encrypt
smtpd_tls_security_level=encrypt

smtp_tls_CApath=/root/cert/pem/*.pem
# smtp_tls_security_level=may -> encrypt
smtp_tls_security_level=encrypt
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache


smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = mail.dreamcloud.co.kr
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, localhost, localhost.localdomain, localhost
#relayhost = [mail.hostname]:587
relayhost =
#mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128, x.x.x.x/24 x.x.x.x/24
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all


# 2022-08-23 add
# debug level 0~4
smtpd_tls_loglevel = 0
smtpd_tls_received_header = yes

# error 530 5.7.0 Must issue a STARTTLS command first
smtp_tls_note_starttls_offer = yes
smtp_use_tls = yes
smtpd_use_tls = yes

# Securing postfix with SSL/TLS on RHEL7 참조
# TLS_protocols
smtpd_tls_mandatory_protocols = !SSLv2,!SSLv3,!TLSv1,!TLSv1.1
smtp_tls_mandatory_protocols  = !SSLv2,!SSLv3,!TLSv1,!TLSv1.1
smtpd_tls_protocols           = !SSLv2,!SSLv3,!TLSv1,!TLSv1.1
smtp_tls_protocols            = !SSLv2,!SSLv3,!TLSv1,!TLSv1.1
smtpd_tls_mandatory_ciphers = high
smtpd_tls_mandatory_exclude_ciphers = aNULL, MD5
smtpd_tls_security_level = encrypt


# 인증서 확인
smtpd_tls_ask_ccert = yes

# Supporing AUTH over TLS only
smtpd_tls_auth_only = no
# touch /etc/postfix/tls_policy -> postmap /etc/postfix/tls_policy
#smtp_tls_policy_maps = hash:/etc/postfix/tls_policy
# touch /etc/postfix/sasl_passwd -> postmap /etc/postfix/sasl_passwd
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
# touch /etc/postfix/generic -> postmap /etc/postfix/generic
smtp_generic_maps = hash:/etc/postfix/generic

# Cyrus SASL Configuration
# postfix SMTP에서 SASL 인증 활성
smtpd_sasl_auth_enable = yes
smtpd_sasl_path = smtpd
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
/etc/postfix/sasl_passwd
mail.hostname:587 ${id}:${password}
/etc/postfix/tls_policy
[mail.hostname]:587 encrypt protocols=>=TLSv1.2 ciphers=high
/etc/postfix/generic
touch /etc/postfix/generic
/etc/postfix/sasl/smtpd.conf
pwcheck_method: saslauthd
mech_list: PLAIN LOGIN
# sasl install
apt-get install postfix-tls sasl2-bin libsasl2-2 libsasl2-modules

vi /etc/default/saslauthd
START=yes
MECHAINSMS=”pam”


vi /etc/postfix/sasl/smtpd.conf
pwcheck_method: saslauthd


vi /etc/postfix/main.cf
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes


vi /etc/default/saslauthd
PWDIR="/var/spool/postfix/var/run/saslauthd"
PARAMS="-m ${PWDIR}"
PIDFILE="${PWDIR}/saslauthd.pid"
OPTIONS="-c -m /var/spool/postfix/var/run/saslauthd"

systemctl restart saslauthd.service
systemctl status saslauthd.service
systemctl restart postfix

 

 

환경 : Ubuntu 20.04

패키지 : postfix (gmail 연동)

## google smtp use
apt-get update
apt-get upgrade

# postfix install
apt-get install -y postfix mailutils libsasl2-2 ca-certificates libsasl2-modules

<Internet Site> -> Enter

# gmail smtp setting
vi /etc/postfix/main.cf

settingrelayhost = [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_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes

# security file create
vi /etc/postfix/sasl_passwd

[smtp.gmail.com]:587 ${username}@gmail.com:${password}

# convert file
chmod 400 /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd

# cacert create
openssl req -new -x509 -nodes -out ${filename}.pem -keyout ${name}.

# service reload
/etc/init.d/postfix reload

# test mail
echo "postfix로 발송한 메일입니다" | mail -s "Postfix 메일 테스트" 수신이메일주소