Postfix

wwiki
이동: 둘러보기, 검색

설치

$ sudo apt-get install postfix

설정

main.cf : Postfix의 일반 구성 파일

postconf명령어로 main.cf 를 갱신할 수 있다.

버전 확인

$ postconf -d | grep mail_version

기본설정이 아닌 것 보기

$ postconf -n

설정추가

$ postconf -e "relay_domains = [도메인명]" 

SMTP 테스트

SMTP telnet으로 테스트

SMTP 인증설정과 StartTLS 설정

SMTP서버는 일반적으로 클라이언트의 IP주소가 서버의 IP주소와 동일한 네트워크에 있을 때 원격대상에 대한 메일을 수락한다.

SMTP 서버의 네트워크 외부에 있는 SMTP클라이언트는 "동일한 네트워크"권한을 얻기 위해 다른 방법이 필요하다. 이러한 요구를 해결하기 위해 Postfix는 SASL인증을 지원한다.

Postfix는 SASL 자체를 구현하지 않지만, 기존 구현된 모듈을 연결하여 사용한다.

sasl type을 dovecot로 설정하려면 Dovecot설치/설정 후 진행하여야 한다.

/etc/postfix/mail.cf의 TLS관련 설정이다.

#SASL관련 설정들 
smtpd_sasl_type = dovecot"
smtpd_sasl_path = private/auth
smtpd_sasl_security_options = noanonymous
smtpd_sasl_auth_enable = yes

#TLS관련 설정들
smtpd_use_tls=yes
smtpd_tls_security_level = encrypt
smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_cert_file = [인증서 경로]
# 키파일은 소유자는 root이어야하며 소유자 이외에는 파일 접근 권한이 없어야 한다. cert파일에 키가 포함되는 경우에는 cert_file도 동일한 권한이 요구된다.
smtpd_tls_key_file = [키파일 경로]

기본설정파일 파라미터들

설정파일 위치: /etc/postfix/main.cf

# myorigin 매개 변수는 로컬에서 보낸 편지가 어떤 도메인에서 오는 것처럼 보이는지를 지정합니다.
# 기본값은 현재 파일의 myhostname에 지정된 값(호스트명)이다.  
myorigin = $myhostname
#myorigin = $mydomain

# 호스트 명
myhostname = [호스트명]

# 도메인 명
mydomain = [도메인명]

# 메일을 송신을 허용하는 컴퓨터의 아이피
mynetworks=127.0.0.0/8

# 최종 목적지를 지정한다. 
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

# 릴레이할 도메인 지정. (외부서버를 경유하여 메일을 보내는 것을 릴레이라고 한다.)
relay_domains = $mydestination

# SMTP Server가 STARTTLS를 지원한다고 알려주면 TLS를 사용하고 그렇지 않으면 평문으로 보낸다. default: no
smtp_use_tls = yes

# 원격 SMTP 클라이언트에서 STARTTLS를 지원한다고 알리지만, 클라이언트가 TLS암호화를 사용하지 않아도 된다. SMTP 데몬은 메일받는 데몬
smtpd_use_tls = yes

#기본 사서함 파일은  /var/spool/mail/user 또는 /var/mail/user이다. qmail 형식을 사용하고자 한다면  Maildir/ 라고 지정한다. 
home_mailbox = Maildir/

# 메일을 보낼 때 인증과 관련된 부분 (순서에 의해 결정된다.)
# permit_inet_interfaces: inet_interfaces 에 정의된 값으로, 메일을 받을 아이피
# permit_mynetworks: mynetworks 에 정의된 값으로, 동일 네트워크이면 허용
# permit_sasl_authenticatedRFC: RFC 4954 프로토콜에 의한 인증에 성공한 클라이언트 허용

smtpd_recipient_restrictions =permit_inet_interfaces, permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination

# Postfix SMTP 서버가 인증을 위해 사용할 SASL 플러그인 타입 default: smtpd, SASL(Simple Authentication and Security Layer)은 인터넷 프로토콜에서 인증과 데이터보안을 위한 프레임워크이다.

sasl관련 설정

# SASL 플러그인이 사용할 추가정보 default: smtpd
smtpd_sasl_path

# Postfix SMTP서버에서 SASL인증을 활성화할지 여부 default: no
smtpd_sasl_auth_enable

# 보안옵션 default: noanonymous, 익명연결은 허용하지 않는다.
smtpd_sasl_security_options

# MicroSoft Outlook Express version 4 and MicroSoft Exchange version 5.0.호환성 이슈를 해결하려면 yes로 변경
broken_sasl_auth_clients=no

서비스(서버) 실행관련 설정

설정파일: /etc/postfix/master.cf (smtps(465)와 submission(587)을 활성화 하기 위하여 수정할 파일)

LDAP연동

LDAP이 계정은 posixAccount인 경우를 기준으로 함.

패키지 설치

$ sudo apt install postfix-ldap

가상메일 계정생성 및 그룹생성

# groupadd -g 5000 vmail

# useradd -g vmail -u 5000 -d /var/vmail -s /bin/false vmail

~/Maildir을 사용하는 경우에 vmail이 ~폴더에 대한 쓰기권한이 있어야 한다.

[/etc/skel 사용자가 추가될 때 생성한 기본디렉토리 설정]

home_mailbox = Maildir 인 경우에 해당

# mkdir -p /etc/skel/Maildir/new

# mkdir -p /etc/skel/Maildir/cur

# mkdir -p /etc/skel/Maildir/tmp

별칭관련 메인설정 수정

수정할 파일: /etc/postfix/main.cf

virtual_alias_maps = ldap:/etc/postfix/ldap-valias.cf

# 별칭 데이터베이스의 목록을 지정한다. LDAP 검색을 사용하려면 LDAP 소스를 검색 테이블로 정의합니다. 이 설정이 메일폴더와 관련이 있는 듯.
alias_maps = hash:/etc/aliases, ldap:/etc/postfix/ldap-mailbox.cf

# 로컬 배달 소프트웨어가 배송할 때 사용하는 기본권한을 지정한다. 
default_privs = vmail

별칭 매핑파일 생성

/etc/postfix/main.cf 파일의 virtual_alias_maps 에 설정한 파일 생성

파일명: /etc/postfix/ldap-valias.cf

server_host = 127.0.0.1

server_port = 389

search_base = ou=[users],dc=example,dc=com

# (기본 : mailacceptinggeneralid = %s) 
query_filter = (uid=%u)

result_attribute = uid

메일박스 매핑파일 생성

/etc/postfix/main.cf 파일의 alias_maps 에 설정한 파일 생성

파일명: /etc/postfix/ldap-mailbox.cf

server_host = 127.0.0.1

server_port = 389

search_base = ou=[users],dc=example,dc=com

query_filter = (uid=%u)

result_attribute = homeDirectory

# Maildir방식인 경우 /etc/postfix/main.cf파일의 home_mailbox = Maildir/ 으로 설정한 경우 포맷을 지정해준다.
result_format = %s/Maildir/

테스트

$ postalias -q [메일주소] ldap:/etc/postfix/ldap-mailbox.cf

SMTP테스트

메일함 관련 권한 수정

$ sudo chmod o+w /home

외부링크

http://www.postfix.org/