Mail server
Setup Mail Server
Instailation
1 | sudo apt-get install opendkim opendkim-tools postfix |
新增使用者
1 | useradd -d -g mail -s /sbin/nologin me |
設定主機名
1 | sudo hostnamectl set-hostname mail.rogerdeng.net |
設定 SSL
1 | sudo apt-get install certbot |
Postfix ssl 設定 /etc/postfix/main.cf
1
2
3
4
5
6
7smtp_use_tls = yes
smtpd_use_tls = yes
smtp_tls_note_starttls_offer = yes
smtpd_tls_cert_file=/etc/ssl/mail/public_cert.pem
smtpd_tls_key_file=/etc/ssl/mail/private_key.pem
smtpd_tls_security_level=may
smtpd_tls_loglevel = 1Dovecot 安裝
1
sudo apt-get install dovecot-core dovecot-imapd dovecot-pop3d dovecot-lmtpd dovecot-mysql
設定 /etc/dovecot/conf.d/10-auth.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15unix_listener auth-userdb {
#mode = 0666
#user =
#group =
}
# Postfix smtp-auth
unix_listener /var/spool/postfix/private/auth {
mode = 0666
}
ssl = yes
ssl_cert = <證書位置
ssl_key = <私鑰位置
測試 SMTP IMAP
SMTP
1 | # using base64 encode account and passwd |
IMAP
1 | telnet DomainName 143 |
簽署 DKIM
1 | sudo mkdir -p /etc/opendkim/keys |
設定 DKIM 到 DNS Server
1 | sudo cat /etc/opendkim/keys/rogerdeng.net/default.txt |
測試 DNS record
1 | sudo opendkim-testkey -d rogerdeng.net -s default -vvv |
設定 OpenDKIM
1 | sudo vim /etc/opendkim.conf |
設定 /etc/opendkim.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22Syslog yes
SyslogSuccess yes
LogWhy no
Canonicalization relaxed/simple
Mode sv
SubDomains no
OversignHeaders From
AutoRestart yes
AutoRestartRate 10/1M
Background yes
DNSTimeout 5
SignatureAlgorithm rsa-sha256
UserID opendkim
UMask 007
KeyTable refile:/etc/opendkim/key.table
SigningTable refile:/etc/opendkim/signing.table
ExternalIgnoreList /etc/opendkim/trusted.hosts
InternalHosts /etc/opendkim/trusted.hosts設定 /etc/default/opendkim
1
2rogerdeng.net default._domainkey.rogerdeng.net
mail.rogerdeng.net default._domainkey.mail.rogerdeng.net設定 /etc/opendkim/trusted.hosts
1
2
3
4
5127.0.0.1
localhost
.rogerdeng.net
.mail.rogerdeng.netRestart OpenDKIM
1
sudo systemctl restart opendkim
讓 Postfix 使用 OpenDKIM
編輯 /etc/postfix/main.cf
1
Socket local:/var/spool/postfix/opendkim/opendkim.sock
編輯 /etc/default/opendkim
1
2sudo mkdir /var/spool/postfix/opendkim
sudo chown opendkim:postfix /var/spool/postfix/opendkim
1 | SOCKET="local:/var/spool/postfix/opendkim/opendkim.sock" |
OpenDKIM signed for Postfix
1 | milter_default_action = accept |
restart postfix and opendkim
1 | sudo systemctl restart postfix |
防止冒名發信
安裝資料庫
1
2sudo apt-get install mariadb-server
sudo mysql_secure_installation編輯 /etc/postfix/main.cf
1
2
3
4
5non_smtpd_milters = $smtpd_milters
smtpd_sender_login_maps = regexp:/etc/postfix/sender_login_map
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated reject_unauth_destination
smtpd_sender_restrictions = reject_non_fqdn_sender reject_unknown_sender_domain reject_sender_login_mismatch編輯 /etc/postfix/sender_login_map
1
/^(.+)@(mail\.)?rogerdeng\.net$/ $1
編輯 /etc/postfix/sender_check
1
<> REJECT null users are not allowed
SPF、DKIM 和 DMARC 的郵件輸入檢查
安裝 opendmarc
1
sudo apt-get install opendmarc
編輯 /etc/postfix/main.cf
1
2
3milter_default_action = accept
milter_protocol = 6
smtpd_milters = inet:127.0.0.1:8893 local:opendkim/opendkim.sock編輯 /etc/opendkim.conf
1
2
3
4
5
6
7
8
9
10
11
12
13UserID opendmarc
Socket inet:8893@localhost
SoftwareHeader true
SPFIgnoreResults true
SPFSelfValidate true
Syslog true
UMask 777
UserID opendmarc:mail
TrustedAuthservIDs mail.rogerdeng.net
RejectFailures true
RequiredHeaders false
IgnoreAuthenticatedClients true加入開機啟動
1
2systemctl enable opendmarc
systemctl start opendmarc
設定 Greylisting
安裝
1
sudo apt-get install postgrey
編輯 /etc/sysconfig/postgrey
1
POSTGREY_OPTS="--delay=30"
新增白名單(self) 編輯 /etc/postfix/postgrey_whitelist_clients.local
1
2rogerdeng.net
mail.rogerdeng.net編輯 /etc/postfix/main.cf
1
smtpd_recipient_restrictions = check_policy_service unix:postgrey/socket
1 | systemctl enable postgrey |
#合併並確認 main.cf
1 | smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU) |