이 글은 다음 글의 연장선에 있는 글입니다.
https://ryans-note.tistory.com/32
Centos S9 - 이메일 서버 설치 roundcube + postfix + dovecot (2/3)
이메일 서버를 운용하기 위해서는 도메인이 필요하다. 아래 예제에서 이메일 도메인은 mydomain.com 이라고 하고, 테스트 이메일 사용자는 user1 이라고 하겠다. 세팅후 테스트 하게될 이메일 주소는
ryans-note.tistory.com
이 글에서는 이메일 백업 메일 서버를 설치하는 것이며 CentOS S9 대신 Ubuntu 22.04 에 설치하고, 백업 서버기 때문에 웹메일은 제외하고 dovecot (IMAP) + postfix (SMTP) 설치만 적어보겠습니다. SPF, DMARC, DKIM 설정은 생략하였는데, 원하는 분은 저의 블로그에 글을 참고해 주세요.
[NTP 시간 동기화]
시간이 제대로 동기화가 안되면 메일 배달이 되지 않고, 가장 중요합니다.
파일과 로그에는 시간이 기록되므로 모든 설치에 앞서 가장 먼저 설치해야 하길 권장합니다.
# sudo apt-get install -y ntp
# sudo vi /etc/ntp.conf
아래 부분을 주석 처리하고 server 추가
#pool 0.ubuntu.pool.ntp.org iburst
#pool 1.ubuntu.pool.ntp.org iburst
#pool 2.ubuntu.pool.ntp.org iburst
#pool 3.ubuntu.pool.ntp.org iburst
server 203.248.240.140 iburst
서비스 실행
# sudo systemctl start ntp
서비스 상태 확인
# sudo systemctl status ntp
시간 존 설정
# sudo timedatectl set-timezone Asia/Seoul
동기화 상태 확인
# ntpq -p
시스템 날짜 확인
# date
[postfix (SMTP) 설치]
# apt -y install postfix sasl2-bin
# cp /usr/share/postfix/main.cf.dist /etc/postfix/main.cf
# vi /etc/postfix/main.cf
줄 78 : 주석해제
mail_owner = postfix
줄 94 : 주석해제 하고 메일 도메인 지정
myhostname = mail2.mydomain.com
줄 102 : 주석해제 하고 서브도메인 제외한 메인 도메인 지정
mydomain = mydomain.com
줄 123 : 주석해제
myorigin = $mydomain
줄 137 : 주석해제
inet_interfaces = all
줄 185 : 주석해제
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
줄 228 : 주석해제
local_recipient_maps = unix:passwd.byname $alias_maps
줄 270 : 주석해제
mynetworks_style = subnet
줄 287 : 로컬 네트워크 추가
mynetworks = 127.0.0.0/8, 10.0.0.0/24
ec2에서는 ifconfig 하고 ip 확인 후 다음과 같이 설정하였다
mynetworks = 127.0.0.0/8, 172.31.0.0/20
줄 407 : 주석해제
alias_maps = hash:/etc/aliases
줄 418 : 주석해제
alias_database = hash:/etc/aliases
줄 440 : 주석해제
home_mailbox = Maildir/
줄 576: 주석해제 하고 추가
#smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
smtpd_banner = $myhostname ESMTP
줄 650 : 추가
sendmail_path = /usr/sbin/postfix
줄 655 : 추가
newaliases_path = /usr/bin/newaliases
줄 660 : 추가
mailq_path = /usr/bin/mailq
줄 666 : 추가
setgid_group = postdrop
줄 670 : 추가
#html_directory =
줄 674 : 주석해제
#manpage_directory =
줄 679 : 주석해제
#sample_directory =
줄 683 : 주석해제
#readme_directory =
줄 684 : 만약 IPv6 도 사용한다면 all 로 하라
inet_protocols = ipv4
# 마지막 줄 이후에 추가
# disable SMTP VRFY command
disable_vrfy_command = yes
# require HELO command to sender hosts
smtpd_helo_required = yes
# limit an email size
# example below means 10M bytes limit
message_size_limit = 10240000
# SMTP-Auth settings
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_mynetworks, permit_auth_destination, permit_sasl_authenticated, reject
# newaliases
# systemctl restart postfix
[참고] 설정이 모두 끝나고 메일이 안받아졌는데 아래 설정과 NTP 시계 설정을 하니 받아지기 시작했다. (어떤 것 때문이었는지 나중에 다시 설치하며 확인 필요)
# postconf -e 'mailbox_size_limit = 0'
# postconf -e 'virtual_mailbox_limit = 0'
# sudo /etc/init.d/postfix restart
[dovecot (IMAP) 설치]
# apt -y install dovecot-core dovecot-pop3d dovecot-imapd
# vi /etc/dovecot/dovecot.conf
30번째 줄 주석해제
listen = *, ::
# vi /etc/dovecot/conf.d/10-auth.conf
10번째 줄 주석해제하고 내용변경
disable_plaintext_auth = no
100번째 줄 추가
auth_mechanisms = plain login
vi /etc/dovecot/conf.d/10-mail.conf
30번째 줄 추가
mail_location = maildir:~/Maildir
vi /etc/dovecot/conf.d/10-master.conf
107-109번째 줄 주석해제 및 내용 다음과 같이 수정
# Postfix smtp-auth
unix_listener /var/spool/postfix/private/auth {
mode = 0666
user = postfix
group = postfix
}
# systemctl restart dovecot
[무료 인증서 설치]
이 부분은 꼭 안해도 되는데 혹시 필요하면 한다.
https://ryans-note.tistory.com/60
Ubuntu 22.04 - 무료 SSL 인증서 - Letsencrypt 발급 받기
https://ryans-note.tistory.com/39 Centos S9 - 무료 SSL 인증서 - Letsencrypt 발급 받기 Letsencrypt 무료 SSL 인증서를 다음과 같이 신청한다. dnf --enablerepo=epel -y install certbot certbot certonly --webroot -w /var/www/mydomain.com/w
ryans-note.tistory.com
[메일 로그 확인]
https://doc.dovecot.org/admin_manual/logging/
Dovecot Logging — Dovecot documentation
Dovecot Logging Dovecot always logs a detailed error message if something goes wrong. If it doesn’t, it’s considered a bug and will be fixed. However, almost always the problem is that you’re looking at the wrong log file; error messages may be logge
doc.dovecot.org
# doveadm log find
Looking for log files from /var/log
Debug: /var/log/syslog
Info: /var/log/syslog
Warning: /var/log/syslog
Error: /var/log/syslog
Fatal: /var/log/syslog
#cat /var/log/syslog
...
Jul 27 06:25:54 postfix/smtpd[38192]: warning: unknown[45.129.14.31]: SASL LOGIN authentication failed: UGFzc3dvcmQ6
Jul 27 06:27:10 postfix/smtpd[38183]: warning: hostname love.explorethebest.com does not resolve to address 45.129.14.31
...
잘 실행되는지 얼마의 시간후에 로그를 확인하니 정체 불명의 이상한 IP 에서 계속 로그인 시도를 실패하고 있다. 각자의 환경에 맞게 위 IP 를 차단해주면 되는데 이 글에서는 ec2 에서 IP 차단하는 방법을 살펴보겠다.
[특정 IP 차단]
위와 같은 식으로 차단IP를 추가해주면 된다. 단, 규칙 번호를 100보다 작게 해야 우선 적용된다.
[방화벽 허용]
[참고]
https://www.server-world.info/en/note?os=Ubuntu_22.04&p=mail&f=2
https://www.server-world.info/en/note?os=Ubuntu_22.04&p=mail&f=1
도움이 되었다면 공감과 댓글 한번 부탁드립니다.
'Linux' 카테고리의 다른 글
Ubuntu 22.04 - 무료 SSL 인증서 - Letsencrypt 발급 받기 (0) | 2023.07.26 |
---|---|
아마존 ec2 ubuntu 서버 세팅 (0) | 2023.07.26 |
EC2 redhat 9 에서 Java 개발 환경 구성 (0) | 2023.07.20 |
Centos 7 에 Jenkins 설치하기 (0) | 2023.03.16 |
Centos 7 에 Glassfish 3.1.2.2 설치하기 (0) | 2023.03.16 |