네트워크 및 서버/서버

Mail서버 구축 - Postfix/Dovecot (2)

잉여토끼 2024. 10. 18. 12:10
  1. postfix, telnet 다운
dnf -y install postfix telnet
  1. name서버 zone파일 수정
    • MX [우선순위] [MX서버 주소]
    • [MX서버 3차 도메인] IN A [MX서버 IP]
$TTL 1D
@       IN SOA  ns.iqsp.com. iqsp.google.com (
                                        24080601        ; serial
                                        1D      ; refresh
                                        1H      ; retry
                                        1W      ; expire
                                        3H )    ; minimum
        NS      ns.iqsp.com.
        A       127.0.0.1
        AAAA    ::1
        MX      10      mx1.iqsp.com.

ns      IN      A       172.16.20.6
r9      IN      A       172.16.20.6
w22     IN      A       172.16.20.3
mon     IN      A       172.16.1.15
lamp    IN      A       172.16.20.13
ub      IN      A       172.16.20.9
nk      IN      A       172.16.20.7
dw      IN      A       172.16.20.101
bw      IN      A       172.16.20.100
py      IN      A       172.16.20.6
mx1     IN      A       172.16.20.6
  1. postfix 설정파일 수정
vim /etc/postfix/main.cf
#src/dst도메인 설정
myhostname = [mx서버 도메인]  

mydomain = [MX서버 2차 도메인 까지]

myorigin = $mydomain

#인터페이스 및 프로토콜 설정
inet_interfaces = all

inet_protocols = all

#목적지 설정
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,

#네트워크 대역 설정
mynetwork = [IP/Prifix]

# Postfix에 메일 송신시 전달자로 동작. 이때 사용하는 설정값이 realy_domain/realy_host
relay_host = $mydomain

# 메일함 위치 설정
home_mailbox = Mailbox

# spooler 설정
# spooler => 작업 스캐줄러
mail_spool_directory = /var/mail

# banner 설정
# bannergrabing에 대한 대처를 위해 banner정보 변경 필요.
# 아래 내용 주석
smtpd_banner = $myhostname ESMTP $mail_name

# 이후는 마지막 줄에 추가

# 사이즈 제한 해제
message_size_limit = 10485760

# for SMTP-Auth
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
  1. postfix 재시작
 systemctl restart postfix 
  1. 방화벽 해제
#smtp 서비스 영구 등록
firewall-cmd --add-service=smpt --permanent

#방화벽 확인
firewall-cmd --list-all
  1. telnet 접속 확인
telnet [mx도메인] 25

접속확인

  • mail form : iqsp
    보내는 계정
  • rcpt to : test
    수신계정
  • data
    이메일 작성.
  • quit
  1. dovecot 설치
dnf -y install dovecot
  1. dovecot 설정
vim /etc/dovecot/dovecot.conf
# 프로토콜 설정
protocols = imap pop3 lmtp submission

# listen IP설정
# * --> IPv4 all, :: --> IPv6 all
listen = *, ::
vim /etc/dovecot/10-auth.conf
# 평문인증 사용
disable_plaintext_auth = no

auth_mechanisms = plain login
vim /etc/dovecot/10-mail.conf
# 메일함 위치
mail_location = maildir:~/Maildir
vim /etc/dovecot/10-master.conf
# Postfix smtp-auth
unix_listener /var/spool/postfix/private/auth {
  mode = 0666
  user = postfix
  group = postfix
}
vim /etc/dovecot/10-ssl.conf
ssl = no
  1. 환경변수 등록
vim /etc/bashrc
export MAIL=$HOME/Maildir
source /etc/bashrc
  1. 동작 테스트
telnet [MX서버] 25 
mail form: [보내는 계정]
rcpt to: [수신계정]
data
[이메일 작성]
quit
[root@rocky-9 conf.d]# telnet mx1.iqsp.com 25
Trying 172.16.20.6...
Connected to mx1.iqsp.com.
Escape character is '^]'.
220 mx1.iqsp.com ESMTP Postfix
mail from : root
250 2.1.0 Ok
rcpt to: kong
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
hi hello
haha
.
250 2.0.0 Ok: queued as 9061310D6CA
quit
221 2.0.0 Bye
[root@rocky-9 kong]# cat /home/kong/Mailbox
From root@iqsp.com  Fri Oct 18 11:50:54 2024
Return-Path: <root@iqsp.com>
X-Original-To: kong
Delivered-To: kong@iqsp.com
Received: from rocky-9 (rocky-9 [172.16.20.6])
        by mx1.iqsp.com (Postfix) with SMTP id 9061310D6CA
        for <kong>; Fri, 18 Oct 2024 11:48:55 +0900 (KST)
Message-Id: <20241018025043.9061310D6CA@mx1.iqsp.com>
Date: Fri, 18 Oct 2024 11:48:55 +0900 (KST)
From: root@iqsp.com

hi hello
haha