Linux/CentOS Stream 9

Centos S9 - 이메일 서버 설치 roundcube + postfix + dovecot (2/3)

Ryan's Tech Note 2023. 2. 25. 22:02

https://saju.choeum.com/pos/front/sjuF0101.do?ref=s_BwgZAV1CS2tVJUAFBwEHCjMAAAAAbUJXUg

 

처음 사주 - 인생 7포인트

2026년 성공하는 시기·성향·연애운·금전운·10년 운까지 한눈에

saju.choeum.com

 


 

이메일 서버를 운용하기 위해서는 도메인이 필요하다. 아래 예제에서 이메일 도메인은 mydomain.com 이라고 하고, 테스트 이메일 사용자는 user1 이라고 하겠다. 세팅후 테스트 하게될 이메일 주소는 user1@mydomain.com 이다.

 

Postfix 설치

Postfix 를 설치한다.

dnf -y install postfix

환경파일 수정 (관련 구문을 / 로 검색해서 적용)

vi /etc/postfix/main.cf
# 코맨트를 해제하고 mail.도메인 과 같이 수정한다.
myhostname = mail.mydomain.com

# 코맨트를 해제하고 도메인으로 수정한다.
mydomain = mydomain.com

# 코맨트를 해제한다.
myorigin = $mydomain

# 값을 all 로 바꾼다.
inet_interfaces = all

# ipv4만 사용한다면 아래와 같이 바꾼다.
inet_protocols = ipv4

# 뒤에 $mydomain 을 추가한다.
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

# 코맨트를 해제하고, 자신의 로컬 내트워크에 맞게 수정한다.
mynetworks = 192.168.0.0/24, 127.0.0.0/8

# 코맨트를 해제하고 Maildir/ 으로 한다.
home_mailbox = Maildir/

# 코맨트를 해제하고 다음과 같이 수정한다.
smtpd_banner = $myhostname ESMTP

# 이하 마지막 줄에 다음 내용들을 추가한다.
# SMTP VRFY 명령 비활성화
disable_vrfy_command = yes

# 전송 호스트들에게 HELO 명령을 필요로 함
smtpd_helo_required = yes

# 이메일 사이즈 제한 (예: 아래는 10M 제한)
message_size_limit = 10240000

# SMTP 인증 세팅
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

 

자동 시작 등록

systemctl enable --now postfix

 

방화벽 오픈

# firewall-cmd --add-service=smtp
success
# firewall-cmd --runtime-to-permanent
success

 

필요하다면 아래 설정들을 마지막 줄에 추가한다.

vi /etc/postfix/main.cf
# reject unknown clients that forward lookup and reverse lookup of their hostnames on DNS do not match
smtpd_client_restrictions = permit_mynetworks, reject_unknown_client_hostname, permit

# rejects senders that domain name set in FROM are not registered in DNS or 
# not registered with FQDN
smtpd_sender_restrictions = permit_mynetworks, reject_unknown_sender_domain, reject_non_fqdn_sender

# reject hosts that domain name set in FROM are not registered in DNS or 
# not registered with FQDN when your SMTP server receives HELO command
smtpd_helo_restrictions = permit_mynetworks, reject_unknown_hostname, reject_non_fqdn_hostname, reject_invalid_hostname, permit

 

postfix 서비스를 시작한다.

systemctl restart postfix

 

혹시 문제가 발생한다면 아래 문서도 참조한다.

참조 : https://ixnfo.com/en/how-to-enable-port-587-in-postfix.html

 


Dovecot 설치

Dovecot 을 설치한다.

dnf -y install dovecot

 

환경설정을 한다 - dovecot.conf

vi /etc/dovecot/dovecot.conf
# 주석을 풀고 * 로 수정한다.
listen = *, ::

 

환경설정을 한다 - 10-auth.conf

vi /etc/dovecot/conf.d/10-auth.conf
# 주석을 해제하고 no로 변경한다. plain text 권한.
disable_plaintext_auth = no

# 추가한다.
auth_mechanisms = plain login

 

환경설정을 한다 - 10-auth.conf

vi /etc/dovecot/conf.d/10-mail.conf
# 주석을 해제하고 추가한다.
mail_location = maildir:~/Maildir

 

환경설정을 한다 - 10-master.conf

vi /etc/dovecot/conf.d/10-master.conf
# 주석을 해제하고 다음과 같이 없는 내용을 추가한다.

  # Postfix smtp-auth
  unix_listener /var/spool/postfix/private/auth {
    mode = 0666
    user = postfix
    group = postfix
  }

 

환경설정을 한다 - 10-ssl.conf

vi /etc/dovecot/conf.d/10-ssl.conf
# 내용을 바꾼다 (SSL 사용 여부)
ssl = yes
 
자동 시작 등록을 한다.
dovecot 서비스를 시작한다.
systemctl enable --now dovecot
systemctl restart dovecot

 


방화벽 예외 처리

방화벽을 예외 처리한다.

firewall-cmd --add-service={pop3,imap}

firewall-cmd --permanent --add-port=110/tcp --add-port=995/tcp

firewall-cmd --permanent --add-port=143/tcp --add-port=993/tcp

firewall-cmd --zone=public --add-service=smtp --add-service=smtps --add-service=imap --add-service=imaps --add-service=pop3 --add-service=pop3s --add-service=https --permanent

firewall-cmd --zone=public --add-port=587/tcp --add-port=8443/tcp --permanent


firewall-cmd --runtime-to-permanent
firewall-cmd --reload

참조 : https://access.redhat.com/documentation/ko-kr/red_hat_enterprise_linux/8/html/deploying_different_types_of_servers/proc_securing-dovecot_deploying-different-types-of-servers

 

Selinux 예외 처리를 한다.

setsebool -P httpd_read_user_content 1

 


 

로컬 사용자를 이메일 사용자로 연계

 

메일 클라이언트 프로그램 설치

dnf -y install s-nail

 

MailDir 을 사용하기 위한 환경변수 셋팅

echo 'export MAIL=$HOME/Maildir' >> /etc/profile.d/mail.sh

 

메일 사용자 추가

useradd user1
passwd user1

 

위에 까지 모두 실행했다면 이제 방금 추가한 user1 사용자로 메일 발송 테스트를 해본다. (아래 참조3에서 발췌했습니다)

$ mail user1@localhost

# input subject
Subject: Test Mail#1
# input messages
This is the first mail.

# to finish messages, push Ctrl + D key
-------
(Preliminary) Envelope contains:
To: user1@localhost
Subject: Test Mail#1
Send this message [yes/no, empty: recompose]? yes

# see received emails

$ mail
s-nail version v14.9.22.  Type `?' for help
/home/user1/Maildir: 1 message 1 new
►N  1 user1@mydomain.com        2022-03-18 19:23   14/405   "Test Mail#1"

# 이메일 번호를 입력해서 조회한다.
& 1
[-- Message  1 -- 14 lines, 405 bytes --]:
Date: Fri, 18 Mar 2022 19:23:33 +0900
To: cent@localhost
Subject: Test Mail#1
Message-Id: <20220318022333.B1738EA09@mail.srv.world>
From: cent@srv.world

This is the first mail.

# to quit, input [q]
& q

 

여기까지 됐다면 이제 SMTP, IMAP 준비까지 모두 끝난것이다.

그럼 다음 편에서 마지막으로 RoundCube 를 설치해 보자.

RoundCube 설치는 다행히 훨씬 쉽다.

 


 

위 설치 관련

참조1 : https://www.server-world.info/en/note?os=CentOS_Stream_9&p=httpd2&f=4 

참조2 : https://www.server-world.info/en/note?os=CentOS_Stream_9&p=mail&f=1

참조3 : https://www.server-world.info/en/note?os=CentOS_Stream_9&p=mail&f=2

참조4 : https://www.server-world.info/en/note?os=CentOS_Stream_9&p=mail&f=3 

 


 

https://saju.choeum.com/pos/front/sjuF0101.do?ref=s_BwgZAV1CS2tVJUAFBwEHCjMAAAAAbUJXUg

 

처음 사주 - 인생 7포인트

2026년 성공하는 시기·성향·연애운·금전운·10년 운까지 한눈에

saju.choeum.com