$7.49 .com domain with free InstantPage Website Builder$1.99 Web Hosting   捷飞网络官方淘宝店   Godaddy 优惠码
返回列表 发帖
分享到:




[共享] 分享Linux(Redhat/centos)下配置sendmail 和 smtp

一: 本文目的! e' t5 [( [/ A9 Z
利用RedHat 7.1中的默认配置方便地设置一台利用SASL库进行用户名和密码认证的SMTP服务器,以允许外面的用户以用户名和密码认证来relay邮件。
. ~! W4 ~. y+ F: m2 u: b二: 网络系统
( {4 f! ^( J  S+ _5 `
0 G( y. t- ~, \2 v" d公司域名 : domain.com
5 Z% C; ?) b% q9 f. t4 S用来认证的SMTP服务器全称域名: smtp.domain.com
# B; `( p0 n9 g0 t( x: l, G三: 为什么要这样用?& k4 x% ]. d& S& Z. ?8 [: s9 l
假设上面的公司有专线接入Internet, 且在其它城市有多个分支机构,公司有统一的域名domain.com,2 ~& u  d, V) {; Q9 z
所有员工的邮件地址类似如staffname@domain.com。但是分支机构大多数没有专线接入,用ISDN或者普通拨号方式入网,并且越来越多的ISP不允许以非ISP的邮件地址域名后缀发送邮件,即使你是他们的拨号用户。6 z0 Q' u; W, {3 ]) r4 X5 x2 t- L
还有一种情况是移动用户,经常地,公司派遣用户在外出差旅行期间,用户需要发送邮件,则也同样需要一种认证方案去允许正确的用户relay邮件。9 F- V6 l) M! D( r
现在我们考虑做公司自己内部的邮件relay系统。
3 z& @6 K+ m5 N就是设置一台SMTP服务器在防火墙之外,安装Redhat 7.1,选择‘服务器系统’方式安装所有需要的包,然后设置Sendmail,配置一台基于SASL的用户名和密码认证的邮件服务器,以relay自己公司的员工的邮件。! ~( p( `8 ~# z9 X; v. Q  `9 q% g# h
四: 配置Sendmail& ^# {) Y8 ^: y0 Z% e8 ^
1. 选择‘服务器系统’安装Redhat 7.1
7 g8 u, y3 m: ?" {0 l2. 进入目录 /usr/share/sendmail-cf/cf 。* \, B9 u5 U# z7 t, ?
如果你没有该目录,说明你还没有安装sendmail-cf-8.11.2-14 RPM包,从你的安装CD中安装它。
6 C5 J% C  F5 x0 l3. 修改文件redhat.mc如下
" M" {, {# _0 N% K" Vdivert(-1)
+ z/ U( ?9 {+ j( \: _- Y. wdnl This is the sendmail macro config file. If you make changes to this file,& i  v1 l' j; D; F' M3 ^
dnl you need the sendmail-cf rpm installed and then have to generate a
$ x. M; J/ w5 \, F$ ]2 r1 r5 Gdnl new /etc/sendmail.cf by running the following command:
2 O# u1 t8 {  Y: sdnl+ n  G* b# M5 U4 z. i! k2 x' l
dnl m4 /etc/mail/sendmail.mc > /etc/sendmail.cf5 p- O+ }( N1 {- u8 _. X
dnl
- u/ n# j5 a8 S9 |7 A$ W5 I; [; Qinclude(`../m4/cf.m4')
1 g* ^" [) v5 ]1 a) wVERSIONID(`linux setup for Red Hat Linux')dnl
0 s: ]; I2 D; ^# J: u2 ~! Q9 v* \OSTYPE(`linux'), c( o& o8 U" Y
define(`confDEF_USER_ID',``8:12'')dnl
* ?( h4 ~$ D# N6 U/ }undefine(`UUCP_RELAY')dnl
% {9 g" v  f) C# y! ?# _8 Iundefine(`BITNET_RELAY')dnl
! A2 P! V. S$ ?3 wdefine(`confAUTO_REBUILD')dnl9 V* T3 ?6 u  y% k$ L; L1 o
define(`confTO_CONNECT', `1m')dnl
3 e1 j) S4 C( M. T; ], n; edefine(`confTRY_NULL_MX_LIST',true)dnl  e( e# i5 ?2 n; j3 R, M% J% @
define(`confDONT_PROBE_INTERFACES',true)dnl2 L- C3 J! i3 c$ ~- g2 m+ w8 [
define(`PROCMAIL_MAILER_PATH',`/usr/bin/procmail')dnl5 t' O& s4 l8 A6 ]/ d
define(`ALIAS_FILE', `/etc/aliases')dnl+ \1 G- l4 s! q+ W- A$ G2 J
define(`STATUS_FILE', `/var/log/sendmail.st')dnl
$ S: Q- t. I9 P+ ~define(`UUCP_MAILER_MAX', `2000000')dnl' t6 S% z6 a% V  ~
define(`confUSERDB_SPEC', `/etc/mail/userdb.db')dnl
4 }3 }: V- ^# N- ^/ G) rdefine(`confPRIVACY_FLAGS', `authwarnings,novrfy,noexpn,restrictqrun')dnl
1 U' z# \+ k% y, N% |define(`confAUTH_OPTIONS', `A')dnl5 t+ e% y& Y! u
define(QUEUE_DIR,`/var/spool/mqueue/q*')
1 h, g4 E3 ]  O6 h" |9 ZTRUST_AUTH_MECH(`DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl0 V5 {" R8 Y! [" F
define(`confAUTH_MECHANISMS', `DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
' d& C4 w4 f( xDAEMON_OPTIONS(`Port=25,Name=MTA')dnl
! A- W% g. n2 ]* a2 l' i5 |7 s0 zDAEMON_OPTIONS(`Port=587,Name=MSA,M=Ea')dnl
" @0 p  @9 W. W( m7 k' k6 ednl define(`confTO_QUEUEWARN', `4h')dnl
% o- m6 }2 D/ u; m0 p( q0 n. Ndnl define(`confTO_QUEUERETURN', `5d')dnl! j( F. o( e3 r) N5 R  S" f
dnl define(`confQUEUE_LA', `12')dnl  t; U& r. N/ @; I: u" [/ L# n
dnl define(`confREFUSE_LA', `18')dnl# @# J7 d2 ]2 X- |# @2 w0 z
dnl FEATURE(delay_checks)dnl+ @" k, {% ^2 I  b! |5 H
FEATURE(`no_default_msa',`dnl')dnl5 g% b7 u+ F3 U7 {* ~
FEATURE(`smrsh',`/usr/sbin/smrsh')dnl
2 \" _9 d( P  A! F# ]FEATURE(`mailertable',`hash -o /etc/mail/mailertable')dnl
" V" O; r& T8 m! aFEATURE(`virtusertable',`hash -o /etc/mail/virtusertable')dnl
: |. p& A1 P/ }/ g& z" CFEATURE(redirect)dnl
& @+ @, o& a& bFEATURE(always_add_domain)dnl
# p" d) R* T; ?, `FEATURE(use_cw_file)dnl! p6 a( Q+ P' j' G5 o
FEATURE(use_ct_file)dnl" Z- l4 d1 S# R; X* _5 y( u
FEATURE(local_procmail)dnl
  p, ^. b+ b$ c( M$ _FEATURE(`access_db')dnl# ]0 d/ q6 h4 z. q  ~* t
FEATURE(`blacklist_recipients')dnl4 W* ]5 R- f4 p
EXPOSED_USER(`root')dnl4 c! @# V" z5 Q" ]5 P
dnl This changes sendmail to only listen on the loopback device 127.0.0.10 z+ x5 e# m3 n
dnl and not on any other network devices. Comment this out if you want. z0 i* T2 Z8 M& ?
dnl to accept email over the network.
9 Z2 e* V  R4 r/ b8 p" |9 r3 J* tdnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')
4 e: k' a* a2 f- q5 Zdnl We strongly recommend to comment this one out if you want to protect! q3 J* s- N% C8 y2 C7 S
dnl yourself from spam. However, the laptop and users on computers that do' W% B/ F6 Y6 F& g+ i5 d. a
dnl not have 24x7 DNS do need this.5 s. {' t) i$ `! ]5 C
dnl FEATURE(`accept_unresolvable_domains')dnl
2 g5 I8 ]' X2 c5 G* J. |, idnl FEATURE(`relay_based_on_MX')dnl
- t8 V7 \; u4 G2 l; `MAILER(smtp)dnl
$ w0 e, J/ g8 d( nMAILER(procmail)dnl
/ T$ I4 g) \3 b9 J其中,我加了下面的行:4 ?" Y% v, n4 P# D% _7 h
1. define(QUEUE_DIR,`/var/spool/mqueue/q*')
8 n: a2 F1 f, W% y' ]2. TRUST_AUTH_MECH(`DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl- X- b, l' d* s, S* U9 o
3. define(`confAUTH_MECHANISMS', `DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
  N1 K, B( R/ A  H4. DAEMON_OPTIONS(`Port=25,Name=MTA')dnl
/ A4 f5 k- {8 S4 E. U- G3 z& I" a5. DAEMON_OPTIONS(`Port=587,Name=MSA,M=Ea')dnl
9 w. b, `* F7 K& c+ Q3 v7 C" k注:" u0 U: k" y4 X8 y; J: g
第1行我启动了多个邮件队列,希望得到更好的队列处理和性能改进。
6 p% x% Q" r9 n& L; S第2,3行 移走前面的注释,打开相应的各种认证机制。- M+ C& o* P4 N7 X9 D0 W
第4,5行 设置相应的MTA和MSA所在的端口号。+ x  Z2 R% Q$ H* s; @8 C  U" T  \% B
且注释出了0 O  m5 ?( [6 D! k
1. dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')
9 i* `( r4 w8 x0 G2 k) q0 Q& K2. dnl FEATURE(`accept_unresolvable_domains')dnl
; @, v5 e! l" d; n第1行 允许通过网络连接Sendmail。- y( K9 |) ?( k; N; L' d, M9 F
第2行 禁止不可解析的域名relay邮件9 O, _* J+ W3 g: g
最后运行
9 ~- m. V5 u) A#m4 /etc/mail/sendmail.mc > /etc/sendmail.cf
2 l. ?5 K! L1 D% I1 E' [3 S, ^2 ^写到/etc/sendmail.cf文件中" l+ }) G& u8 D  j; p* L) ]; T
既然我们打开了多个队列,现在我们在/var/spool/mqueue/下创建任意多个队列目录如
) X6 S# s2 x! y5 O! G  u( g; n#cd /var/spool/mqueue! l+ C3 o$ |9 z( d6 v
#mkdir q1 q2 q3 q4 q5 q6: A+ A  C2 R6 \( f& H5 m+ F, U
这样Sendmail将会使用这六个目录做为队列目录,增加了性能。9 P* E8 Q, {$ R+ z4 j8 t5 A. S1 a
五: 设置SASL认证方案
: ?; N0 I) @  G7 C6 U* n1. 运行下面的命令,确保SASL被编译进Sendmail.
8 @( B# Q5 y4 M8 a9 j9 S. Z" I#/usr/sbin/sendmail -d0.1 -bv root |grep SASL+ K3 B& J3 e( n  J5 L$ k
输出应该类似如下面:2 e5 j" p2 I+ |2 F: M& d+ n
NETUNIX NEWDB QUEUE SASL SCANF SMTP USERDB XDEBUG
2 v) m9 J9 B6 p, Y7 q确保你能看见上面的文本中的 SASL* f6 J. M/ P6 k2 h0 j, ?9 W; L
2. 测试端口25,确保输出AUTH提示行。# k( V+ t4 z! v: H
#telnet localhost 255 ]& W" j; A! N2 o+ T( @
Trying 127.0.0.1...
3 J$ p* f8 l4 K& x2 CConnected to smtp.domain.com.
+ f( a% r% V8 @" _, |/ VEscape character is '^]'.6 L+ {* U5 h! [- O; y
220 smtp.domain.com ESMTP Sendmail 8.11.2/8.11.2; Sun, 1 July 2001 17:56:54 -0800+ U+ y  @" f5 S& a* C2 r
EHLO localhost
0 x) Y$ b% \4 O& l. Y9 C# N( p250-smtp.domain.com Hello IDENT:root@smtp.domain.com [127.0.0.1], pleased to meet you
! w$ _# u5 D7 A8 N# q# p* l250-ENHANCEDSTATUSCODES
0 Q; V3 ?( ]0 v250-EXPN
- B. h0 N3 l# y/ L$ I250-VERB
$ a$ v& {2 X- _6 J8 S! Q' A( z250-8BITMIME
5 P- L/ Y6 l$ o. T250-SIZE
2 F3 v- M' \- T! I" w3 K2 ~250-DSN/ |1 k  J1 E# R; f& B
250-ONEX$ k, B% I7 P- \5 S
250-ETRN6 s, b$ _7 A1 V9 y. T; C
250-XUSR
& e8 b" W/ r$ }250-AUTH LOGIN PLAIN DIGEST-MD5 CRAM-MD5* G6 g5 F, n: J/ H) i# z
250 HELP
" r: x4 g, x/ K' |. k. Q( @quit% N5 _( D3 b9 k) _" A8 Y$ X5 x
221 2.0.0 smtp.domain.com closing connection
0 v' b! o8 i! }6 |. s4 c. U: q9 zConnection closed by foreign host.
9 R( t' w3 Y: u) Y5 W/ ?; O你需要至少看见AUTH行中有LOGIN PLAIN在那里,否则不能relay mail。
3 ^! A7 O6 j% e! ?2 L! n4 g7 ~3. 增加SASL用户且更改密码
4 }4 T6 o4 F% B6 H* Y. [#/usr/sbin/saslpasswd jephe
+ Z8 {# n% o% S' `7 B, [/ BPassword: ******** l/ y! P! M3 X7 S; G) y. _
Again (for verification): *******. Z* {' G8 c: {3 d
#/usr/sbin/sasldblistusers
2 p4 h# u. K! |" l; K1 quser: jephe realm: smtp.domain.com mech: DIGEST-MD5
$ m. y- D5 W1 o  Suser: jephe realm: smtp.domain.com mech: PLAIN, E% X) Y) ?6 A- i
user: jephe realm: smtp.domain.com mech: CRAM-MD5$ i+ Y; S: {/ T4 j9 g; }/ V( ?0 ]
用户的密码DB文件在/etc/sasldb,用下面的命令确保正确的许可权设置。6 L9 o2 Z3 d5 D! @1 k
特别注意: 在下面的windows的Outlook Express中设置用户名和密码时并不是简单地使用用户名jephe,而是用象“user@realm”的用户名,在这里是 jephe@smtp.domain.com作为用户名。
: F! l( ]8 o1 |5 e4 C. Q% {#chmod 400 /etc/sasldb
3 X9 H' w. a4 e% v) E' \: B5 r. ]& b可以用/usr/sbin/saslpasswd加更多的用户,用/usr/sbin/sasldblistusers检查用户已经加入。5 N6 e1 L8 Z; U/ X, w+ e
4. 更改默认的Redhat 7.1密码认证方法- v4 t8 ~8 X$ V. y( }( B
默认地,Redhat 7.1中的Sendmail用PAM方法检查密码,这意味着用户必须是系统用户,为了
( V# c3 j: f! s# L  ?4 g增强安全性,我们改用/etc/sasldb中的用户,改下面的文件中的pam为sasldb。
. P$ E8 R- h+ u6 p- ^0 w#vi /usr/lib/sasl/Sendmail.conf 更改pwcheck_method行象下面7 G% h+ S: N- G, [) N
pwcheck_method:sasldb
6 i; i% c" p  z- M8 E5. 最后,运行/etc/rc.d/init.d/sendmail restart重新启动Sendmail。( g$ ~/ ]9 W$ @4 _% \8 a
六: 设置Windows的Outlook Express。
; ^0 f% `, J$ s9 s1. Outlook Express仅仅使用 PLAIN LOGIN 认证机制,确保上面的telnet localhost 25中的AUTH行
5 h% G1 k$ g5 z. G输出PLAIN LOGIN即可。5 p2 B$ t1 `' K% q% }4 F1 l
2. 在‘工具’-‘帐号’-‘属性’-‘服务器‘-5 |( z0 }, e5 q5 c# m
’发送邮件服务器’中选中‘我的服务器需要认证’5 i  x) t3 Y4 K/ F) p7 y
然后在‘登录用户帐号’上填上3 l) f* P1 A! D& M: A& p$ Q- O
“你的用户名@你的realm冒号后面的服务器全称域名”1 U5 E# f: q# s" B6 p- }
如:本文的情况是 jephe@smtp.domain.com
) ^% V/ P: U* x( u& w密码为你在前面输入的密码。' ~3 B0 [9 d1 ~# S2 F5 T: ?
注意: 用户名绝不是简单地 jephe,必须跟上realm:后面的域名。4 k( W5 b' b4 w$ t' N
3. 现在测试,发一封信给自己,检查tail -f /var/log/maillog有无任何错误
  p+ O: u/ U6 w. j+ l然后在收到自己发出的信之后检查邮件头,你能发现被服务器接收后有个(authenticated)在后面表示是通过允许的认证机制relay的邮件。
& ^# _& {$ O0 \' k) ^7 X5 t七: FAQ。
" R0 ~. ~, Y7 {" \8 Y1. 如果你没有命令saslpasswd,sasldblistusers在/usr/sbin/目录下面。- U6 E- B1 a4 U; L; e% ?1 @' G
答: 你需要安装cyrus-sasl-1.5.24-17 RPM包。
+ ?+ C( s6 S% a2. 如果不想用SASL认证,就用默认的Redhat 的PAM方法。
; B$ ]/ r1 B5 d( Y5 I3 |" |答: 忽略上面的SASL设置的部分,默认地 Redhat 7.1的 /usr/lib/sasl/Sendmail.conf文件里面为' M3 m6 M" ?$ b: T
pwcheck_method:pam
4 i( `7 z5 I+ R9 i' F; @3 e. ^则你就简单地用useradd增加一个系统用户并更改密码即可。
' s8 t- ]5 _1 v( ?) y* ]然后在Outlook Express中设置用户名时则只用如“jephe”即可,不需要跟全称域名。
% V( E2 I/ a) d! s验证pop3
0 q" w" ~) Q& s5 ^reahat 6.2 ----〉/ Q! R1 w) B+ A5 W3 x1 M' \1 r5 g9 S
1。/etc/inetd.conf( n+ X8 a' l* ]+ P1 M2 P; F
# pop3 stream tcp mowait$ t# M  d: g/ U6 ^
root /usr/sbin /tcpd/usr/sbin/in.popsd  (#去掉)
; L" P: \2 Q1 s# g2,存盘。/运行inetd. W7 T! ^/ s8 @  S( f1 X
3y验证:netstat -a |grep pop- s  H+ D% C& C& |

  B9 l; @. y, B3 n- X& i输出 ------tcp 0 0 * : pop3 *:* listen
! x- @+ K' V7 b: mok了!
5 @) i9 @. ^' kredhat 7.1以上:
* c& Q4 C4 |  j0 x( ~1、vi  etc/services5 `/ H, \, K1 G) m& D3 n6 ?: |
# pop3 110/tcp
8 v3 x# d0 C% Y' [# pop3 110/udp (去掉#)
, w0 {* X3 z4 V! _5 v6 [( eok了!
7 d8 m& T7 a$ z. C6 a! f( [9 [( T. e2 }+ E4 X
参考:http://www.phpwind.net/read/474365

美国VPS、域名代购:http://tu8l.taobao.com

返回列表
Namecheap
Namecheap.com - Cheap domain name registration, renewal and transfers - Free SSL Certificates - Web Hosting
互联网安全