LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 737|回复: 0

实验:sendmail服务器的配置上机操作

[复制链接]
发表于 2005-4-8 11:23:22 | 显示全部楼层 |阅读模式
实验:sendmail服务器的配置上机操作
主机IP:192.168.0.254
主机域名:server1.office.com
linux os :REEL4
机器用户:root         密码自定
                student    密码自定
                sendmail设置的别名:
                student的别名为me,wizards,methere
                root 的别名wizards(发给wizards,root和student均可收到)
1.关闭防火墙,查看/etc/hosts和/etc/sysconfig/network文件,并改成类似以下内容:
/etc/hosts
-----------------------------------------
# Do not remove the following line, or various programs
# that require network functionality will fail.
192.168.0.254        server1.office.com        server1
--------------------------------------------
/etc/sysconfig/network
---------------------------------------------
NETWORKING=yes
HOSTNAME=server1.office.com
--------------------------------------------
以前配置dns服务器时,只要求能解析,考虑没过细,这里完善。
2.配置/etc/mail/access文件
-----------------------------------------------------
# Check the /usr/share/doc/sendmail/README.cf file for a description
# of the format of this file. (search for access_db in that file)
# The /usr/share/doc/sendmail/README.cf is part of the sendmail-doc
# package.
#
# by default we allow relaying from localhost...
localhost.localdomain                RELAY
localhost                        RELAY
127.0.0.1                        RELAY
# 增加以下两行:
server1.office.com                RELAY
192.168.0.254                RELAY
-------------------------------------------------------
3.修改 /etc/mail/sendmail.mc
使用dnl注释在下面的行之前,就象这样:
dnl DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')
4.在同一个目录下,编译sendmail.cf
m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
5.重新启动sendmail
service sendmail restart
关闭 sendmail:                                            [  确定  ]
关闭 sm-client:                                           [  确定  ]
启动 sendmail:                                            [  确定  ]
启动 sm-client:                                           [  确定  ]
6.检查sendmaul相关功能是否打开
[root@localhost ~]# chkconfig --list sendmail
sendmail        0:关闭  1:关闭  2:启用  3:启用  4:启用  5:关闭  6:关闭
打开相关功能:
chkconfig  sendmail on
[root@localhost ~]# chkconfig --list sendmail
sendmail        0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭
7.sendmail可执行文件位于/usr/sbin/sendmail。为了确定sendmail是否正确标识您的主机名称,通过命令行开关开启其调试模式并且设定为0:

sendmail –d0
Version 8.13.1
Compiled with: DNSMAP HESIOD HES_GETMAILHOST LDAPMAP LOG MAP_REGEX
                MATCHGECOS MILTER MIME7TO8 MIME8TO7 NAMED_BIND NETINET NETINET6
                NETUNIX NEWDB NIS PIPELINING SASLv2 SCANF STARTTLS TCPWRAPPERS
                USERDB USE_LDAP_INIT

============ SYSTEM IDENTITY (after readcf) ============
      (short domain name) $w = server1
  (canonical domain name) $j = server1.office.com
         (subdomain name) $m = office.com
              (node name) $k = server1
========================================================

Recipient names must be specified
8.发一封邮件给自己(root),并查看过程:
[root@server1 ~]# echo "root ==>root;hello root" | mail -v -s hello root@server1root@server1... Connecting to [127.0.0.1] via relay...
220 server1.office.com ESMTP Sendmail 8.13.1/8.13.1; Fri, 8 Apr 2005 10:51:54 +0800
>>> EHLO server1.office.com
250-server1.office.com Hello localhost [127.0.0.1] (may be forged), pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH DIGEST-MD5 CRAM-MD5
250-DELIVERBY
250 HELP
>>> MAIL From:<root@server1.office.com> SIZE=57 AUTH=root@server1.office.com
250 2.1.0 <root@server1.office.com>... Sender ok
>>> RCPT To:<root@server1.office.com>
>>> DATA
250 2.1.5 <root@server1.office.com>... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .
250 2.0.0 j382psNT011429 Message accepted for delivery
root@server1... Sent (j382psNT011429 Message accepted for delivery)
Closing connection to [127.0.0.1]
>>> QUIT
221 2.0.0 server1.office.com closing connection
查看一下邮件是否正确的收到:
[root@server1 ~]# mail
Mail version 8.1 6/6/93.  Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N  1 root@server1.office.  Fri Apr  8 10:51  16/649   "hello"
& 1
Message 1:
From root@server1.office.com  Fri Apr  8 10:51:54 2005
Date: Fri, 8 Apr 2005 10:51:54 +0800
From: root <root@server1.office.com>
To: root@server1.office.com
Subject: hello

root ==>root;hello root

& quit
Saved 1 message in mbox
[root@server1 ~]# mail
No mail for root
9.查看消息是不是在/var/log/maillog中正确的记录:
xterm –e tail –f /var/log/maillog &
将弹出tail观察窗口。
10.在/etc/aliases 行加入如下的行:

me: student
wizards: root, me
methere: student@server1.office.com
12.运行newalias 命令来更新数据库
[root@server1 ~]# sendmail -bi
/etc/aliases: 79 aliases, longest 10 bytes, 811 bytes total
13.发送邮件给定义的收件人:
[root@server1 ~]# echo "root==>me;hello" | mail -s "hello" me
[root@server1 ~]# echo "root==>wizards;hello" | mail -s "hello" wizards
[root@server1 ~]# echo "root==>methere;hello" | mail -s "hello" methere
14.在root里查收一下是否收到了一封邮件(wizards):
[root@server1 ~]# mail
Mail version 8.1 6/6/93.  Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N  1 root@server1.office.  Fri Apr  8 11:13  16/647   "hello"
& 1
Message 1:
From root@server1.office.com  Fri Apr  8 11:13:17 2005
Date: Fri, 8 Apr 2005 11:13:17 +0800
From: root <root@server1.office.com>
To: wizards@server1.office.com
Subject: hello

root==>wizards;hello

&
15.注销一下,用student登录。
查看一下,是否收到三封邮件。
在root登录后,用su student,并不能查看到邮件。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表