postfix是一個流行的smtp伺服器。在不采用ssl/tls加密的情況下,smtp伺服器預設端口是25/TCP。下面介紹如何在CentOS6上安裝postfix。
1 . CentOS6預設已經安裝了postfix.如果系統沒有postfix的話,可以采用如下指令安裝它。
[[email protected] ~]# yum -y install postfix
2 . 配置postfix的main.cf,配置smtp-auth采用dovecot的sasl功能。需要安裝和配置dovecot,見下篇。
[[email protected] ~]# vi /etc/postfix/main.cf
# 第75行: 去掉注釋,并設定主機名。
myhostname = mail.sky.top
# 第83行: 去掉注釋,并設定域名。
mydomain = sky.top
# 第99行: 去掉注釋。
myorigin = $mydomain
# 第116行:
inet_interfaces = all
# 第119行: 如果隻使用ipv4,那麼設定如下。
inet_protocols = ipv4
# 第164行: 配置可接收郵件的域名。
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
# 第264行: 去掉注釋,并設定本地網絡号段.
mynetworks = 127.0.0.0/8, 10.0.0.0/24
# 第419行: 去掉注釋,采用Maildir格式。
home_mailbox = Maildir/
# 第571行:
smtpd_banner = $myhostname ESMTP
# 添加如下配置到檔案末尾
# 一封郵件大小限制為10M
message_size_limit = 10485760
# 一個郵箱大小限制為1G
mailbox_size_limit = 1073741824
# 配置SMTP-Auth采用dovecot的sasl功能
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
main.cf配置完畢後,啟動postfix,并設定自動啟動。
[[email protected]ail ~]# /etc/rc.d/init.d/postfix start
Starting postfix: [ OK ]
[[email protected] ~]# chkconfig postfix on
3 . 如果iptables在開啟狀态,那麼設定iptables開放smtp的25端口。
[[email protected] ~]# iptables -I INPUT 5 -p tcp -m state --state NEW -m tcp --dport 25 -j ACCEPT