- Postfix settings.
- SMTP authentication settings.
- Creation of Maildir format mailboxes.
- Open TCP25 and TCP587 ports.
- Port open test.
- OP25B measures for mail servers.
- Forward mail addressed to root (using free mail).
- Email sending test.
- Email forwarding settings for Gmail.
- Receipt confirmation of mail addressed to root.
- Install Dovecot.
- Open TCP110 or TCP143 port.
- Adding mail users.
- Check sendmail path.
- Email software registration.
- Obtaining a server certificate.
- SSL settings.
- Open port TCP465.
- Port open test.
- Close TCP port 587.
- Port open test.
- Open port TCP995 or TCP993.
- Port open test.
- Change email settings.
- Cooperation with anti-virus software (Clamav + Amavisd).
Postfix settings.
Allow external web access.
[root@www ~]# vi /etc/httpd/conf.d/virtualhost-00-fedoraserver.jp.conf <VirtualHost *:80> ServerName fedoraserver.jp DocumentRoot /var/www/html ServerAlias mail.fedoraserver.jp RewriteEngine On RewriteCond %{HTTP_HOST} ^www.fedoraserver.jp RewriteRule ^(.*)$ http://fedoraserver.jp/$1 [R=301,L] </VirtualHost>
[root@www ~]# dnf install postfix
[root@www ~]# vi /etc/postfix/main.cf
myhostname = mail.fedoraserver.jp
mydomain = fedoraserver.jp
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
home_mailbox = Maildir/
smtpd_banner = $myhostname ESMTP unknown
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions =
permit_mynetworks
permit_sasl_authenticated
reject_unauth_destination
message_size_limit = 10485760
[root@www ~]# vi /etc/postfix/master.cf
submission inet n - n - - smtpd
-o smtpd_sasl_auth_enable=yes
SMTP authentication settings.
Install cyrus-sasl.
[root@www ~]# dnf install cyrus-sasl cyrus-sasl-plain
[root@www ~]# systemctl start saslauthd
[root@www ~]# systemctl enable saslauthd
Creation of Maildir format mailboxes.
Set to automatically create a Maildir format mailbox when adding a new user.
[root@www ~]# mkdir -p /etc/skel/Maildir/{new,cur,tmp}
[root@www ~]# chmod -R 700 /etc/skel/Maildir/
[root@www ~]# systemctl restart postfix
[root@www ~]# wget https://rcg.jp/perfect_maildir/perfect_maildir.pl -O /usr/local/bin/perfect_maildir.pl [root@www ~]# chmod +x /usr/local/bin/perfect_maildir.pl
[root@www ~]# dnf -y install perl-TimeDate
[root@www ~]# systemctl stop postfix
[root@www ~]# vi migrate-maildir.sh #!/bin/bash # #Maildir batch conversion script # #Mailbox => Maildir format conversion script #http://perfectmaildir.home-dn.net/ FOLDERCONVERT=/usr/local/bin/perfect_maildir.pl #general user list USERLIST=`ls /home/` #log MIGRATELOG=/tmp/migrate-maildir.log rm -f $MIGRATELOG #Argument (conversion source mailbox format) check if [ "$1" != "mbox" ] && [ "$1" != "Mailbox" ]; then echo "Usage: migrate-maildir.sh {mbox|Mailbox}" exit fi #Migrate general user mailboxes for user in $USERLIST; do if [ "$1" = "mbox" ]; then inbox="/var/spool/mail/${user}" else inbox="/home/${user}/Mailbox" fi if [ -f "${inbox}" ]; then newdir="/home/${user}/Maildir/" mkdir -p "$newdir" mkdir -p "$newdir"/cur mkdir -p "$newdir"/new mkdir -p "$newdir"/tmp chmod -R 700 "${newdir}" $FOLDERCONVERT "$newdir" < "${inbox}" >> $MIGRATELOG 2>&1 chown -R ${user}. "$newdir" find "$newdir" -type f -exec chmod 600 {} ; fi done #root user mailbox migration user="root" if [ "$1" = "mbox" ]; then inbox="/var/spool/mail/${user}" else inbox="/${user}/Mailbox" fi if [ -f "${inbox}" ]; then newdir="/${user}/Maildir/" mkdir -p "$newdir" mkdir -p "$newdir"/cur mkdir -p "$newdir"/new mkdir -p "$newdir"/tmp chmod -R 700 "${newdir}" $FOLDERCONVERT "$newdir" < "${inbox}" >> $MIGRATELOG 2>&1 chown -R ${user}. "$newdir" find "$newdir" -type f -exec chmod 600 {} ; fi [ -a $MIGRATELOG ] && cat $MIGRATELOG;rm -f $MIGRATELOG
[root@www ~]# sh migrate-maildir.sh mbox
[root@www ~]# rm -f migrate-maildir.sh
[root@www ~]# rm -f /usr/local/bin/perfect_maildir.pl
[root@www ~]# systemctl restart postfix
[root@www ~]# vi /etc/aliases
#webmaster: root
[root@www ~]# newaliases
Open TCP25 and TCP587 ports.
Open TCP25 and TCP587 ports in your router settings. (Check the setting method according to your own environment.)
Port open test.
“Host name (fedoraserver.jp)” and “Port number (25, 587)” are open.
OP25B measures for mail servers.
As a countermeasure against OP25B on the mail server, set to send outgoing mail via Gmail.
Configure Postfix.
Postfixを設定します。
[root@www ~]# vi /etc/postfix/main.cf
relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_tls_security_options = noanonymous
smtp_sasl_mechanism_filter = plain
[root@www ~]# echo [smtp.gmail.com]:587 Gmailアドレス:Gmailパスワード > /etc/postfix/sasl_passwd
[root@www ~]# chmod 640 /etc/postfix/sasl_passwd
[root@www ~]# postmap /etc/postfix/sasl_passwd
[root@www ~]# systemctl reload postfix
Forward mail addressed to root (using free mail).
Forward mail to root.
[root@www ~]# vi /etc/aliases
# Person who should get root's mail #root: marc root: 転送用メールアドレス
[root@www ~]# newaliases
Email sending test.
Send test mail to root.
[root@www ~]# echo test|sendmail root
Email forwarding settings for Gmail.
First, configure Thunderbird’s Gmail (outgoing email) settings.
Thunderbird Gmail (outgoing mail) settings
Receipt confirmation of mail addressed to root.
First, set Thunderbird’s Gmail (mail for forwarding).
Thunderbird Gmail (forwarding mail) settings
Install Dovecot.
Install Dovecot.
[root@www ~]# dnf -y install dovecot
[root@www ~]# vi /etc/dovecot/dovecot.conf
protocols = imap pop3 lmtp submission
listen = *
[root@www ~]# vi /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:~/Maildir
[root@www ~]# vi /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no
[root@www ~]# vi /etc/dovecot/conf.d/10-ssl.conf
ssl = no
[root@www ~]# systemctl start dovecot
[root@www ~]# systemctl enable dovecot
Open TCP110 or TCP143 port.
“Host name (fedoraserver.jp)” and “Port number (110 or 143)” are open.
Adding mail users.
Add users. (User example: fedora)
[root@www ~]# useradd fedora
[root@www ~]# passwd fedora Changing password for user fedora. New UNIX password: Retype new UNIX password:
Edit “/etc/ssh/sshd_config” to disable authentication connection with private key.
Edit sshd_config.
[root@www ~]# vi /etc/ssh/sshd_config
PasswordAuthentication yes
[root@www ~]# systemctl restart sshd
Set SSH server public key authentication method connection.
Setting up an SSH server public key authentication method connection
Check sendmail path.
Open a file.
[root@www ~]# vi /etc/postfix/main.cf
sendmail_path = /usr/sbin/sendmail.postfix
Email software registration.
Launch Thunderbird and click Mail.
Server hostname | port number | SSL | Authentication method | ||
Incoming server | POP3 | mail.fedoraserver.jp | 110 | No connection protection | normal password authentication |
Outgoing server | SMTP | mail.fedoraserver.jp | 587 | No connection protection | normal password authentication |
Obtaining a server certificate.
Install Certbot.
[root@www ~]# dnf -y install certbot
Document root: /var/www/html/
Email address: webmaster@fedoraserver.jp
Mail server name:mail.fedoraserver.jp
[root@www ~]# certbot certonly --webroot -w /var/www/html/ -m webmaster@fedoraserver.jp -d mail.fedoraserver.jp --agree-tos
[root@www ~]# vi /etc/cron.d/letsencrypt
00 16 * * 2 root /usrobin/certbot renew --post-hook "service httpd restart"
SSL settings.
set the file.
[root@www ~]# vi /etc/postfix/main.cf
smtp_tls_security_level = may
smtpd_tls_security_level = may
smtpd_tls_cert_file = /etc/letsencrypt/live/mail.fedoraserver.jp/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/mail.fedoraserver.jp/privkey.pem
smtpd_tls_session_cache_database = btree:/var/lib/postfix/smtpd_scache
tls_high_cipherlist = kEECDH:+kEECDH+SHA:kEDH:+kEDH+SHA:+kEDH+CAMELLIA:kECDH:+kECDH+SHA:kRSA:+kRSA+SHA:+kRSA+CAMELLIA:!aNULL:!eNULL:!SSLv2:!RC4:!MD5:!DES:!EXP:!SEED:!IDEA:!3DES
smtp_tls_ciphers = high
smtpd_tls_ciphers = high
smtpd_tls_mandatory_ciphers = high
smtpd_tls_mandatory_protocols=!SSLv2,!SSLv3
smtp_tls_mandatory_protocols=!SSLv2,!SSLv3
smtpd_tls_protocols=!SSLv2,!SSLv3
smtp_tls_protocols=!SSLv2,!SSLv3
[root@www ~]# vi /etc/postfix/master.cf
#submission inet n - n - - smtpd
# -o smtpd_sasl_auth_enable=yes
smtps inet n - n - - smtpd
-o smtpd_tls_wrappermode=yes
-o smtpd_sasl_auth_enable=yes
tlsmgr unix - - n 300 1 tlsmgr
[root@www ~]# systemctl restart postfix
Open port TCP465.
Open TCP port 465 in your router settings. (Check the setting method according to your own environment.)
Port open test.
On the release confirmation site, enter “host name (mail.fedoraserver.jp)” and “Port number (465)” are open.
Close TCP port 587.
Block TCP port 587 in your router settings. (Check the setting method according to your own environment.)
Port open test.
set the file.
[root@www ~]# vi /etc/dovecot/conf.d/10-ssl.conf
ssl = yes
ssl_cert = </etc/letsencrypt/live/mail.fedoraserver.jp/fullchain.pem
ssl_key = </etc/letsencrypt/live/mail.fedoraserver.jp/privkey.pem
[root@www ~]# systemctl restart dovecot
Open port TCP995 or TCP993.
Open port TCP995 or TCP993 in your router settings. (Check the setting method according to your own environment.)
Port open test.
On the release confirmation site, enter “host name (mail.fedoraserver.jp)” and “Port number (995 or 993)” are open.
Change email settings.
Launch Thunderbird, select your email address, and click “View settings for this account”.
Cooperation with anti-virus software (Clamav + Amavisd).
Install Amavisd and Clamav Server.
[root@www ~]# dnf -y install amavisd-new clamd perl-Digest-SHA1 perl-IO-stringy
[root@www ~]# vi /etc/amavisd/amavisd.conf
$mydomain = 'fedoraserver.jp';
$myhostname = 'mail.fedoraserver.jp';
$notify_method = 'smtp:[127.0.0.1]:10025';
$forward_method = 'smtp:[127.0.0.1]:10025';
[root@www ~]# vi /etc/clamd.d/scan.conf
#Example
LogFile /var/log/clamd.scan
PidFile /var/run/clamd.scan/clamd.pid
TemporaryDirectory /var/tmp
LocalSocket /var/run/clamd.scan/clamd.sock
[root@www ~]# touch /var/log/clamd.scan [root@www ~]# chown clamscan. /var/log/clamd.scan
[root@www ~]# systemctl enable --now clamd@scan amavisd
[root@www ~]# vi /etc/postfix/main.cf
content_filter=smtp-amavis:[127.0.0.1]:10024
[root@www ~]# vi /etc/postfix/master.cf
smtp-amavis unix - - n - 2 smtp
-o smtp_data_done_timeout=1200
-o smtp_send_xforward_command=yes
-o disable_dns_lookups=yes
127.0.0.1:10025 inet n - n - - smtpd
-o content_filter=
-o local_recipient_maps=
-o relay_recipient_maps=
-o smtpd_restriction_classes=
-o smtpd_client_restrictions=
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o mynetworks=127.0.0.0/8
-o strict_rfc821_envelopes=yes
-o smtpd_error_sleep_time=0
-o smtpd_soft_error_limit=1001
-o smtpd_hard_error_limit=1000
[root@www ~]# systemctl restart postfix
コメント