5.30 电子邮件sendmail试验

5.30 电子邮件sendmail试验,第1张

估计时间: 2个小时

目标: 建立基本的MTA的配置的技能

试验的起点: 标准的Red Hat Linux安装

确保在Server1上的sednmailmc文件中的DAEMON_OPTIONS被注释并且重新编译sendmailcf文件使得能够接受来自其他主机的电子邮件。

介绍

本次实验作为一个安装和配置MTA的介绍。在介绍中我们将提及sendmail和postfix。您可以选择任何一个MTA,如果时间允许,您两个都可以做一下试验。在接下来的步骤中,您将

1 安装并且验证sendmail的“发件箱”

2 为您的sendmail的安装添加新的别名

3 使用m4工具来改变您的转发行为

4 安装POP3服务器并且配置POP客户端

在整个试验中,主机和域名取决于您的机器的IP地址。如果下面的试验出现了X字样的名称,您应该把X字样的名称替换成你的工作站的号码(您的IP地址的最后一个部分)。例如,如果您的工作站的IP的地址是19216802,您应该将stationXdomainXexamplecom转换成station2domain2examplecom。

将数据包过滤设定为无效状态。在本次试验开始之前,请您确保您的主机上的所有包过滤已被关闭(显然,在实际使用中您可以利用Linux内核的防火墙机制,然而我们在这里关掉它是为了减少潜在的问题)。

本次试验中以root身份来使用下面命令达成上面的要求:

service iptables stop

chkconfig iptables off

初始化安装-安装必要的软件包

下列软件包对于sendmail是必需的: sendmail,sendmail-cf,sendmail-doc,m4和procmail。对于postfix而言,您需要: postfix。如果需要他们,从CD上进行检视和安装,server1的NFS安装点,从: ftp://server1/pub/RedHat/RPMS/

为了安全的原因,sendmail和postfix的缺省的配置允许发邮件但是不允许从网络上接收邮件(缺省的它们只接受从回环接口上的连接)。按照如下配置您选择的MTA使得它接受传入的连接:

⑴ 对于sendmail: 修改 /etc/mail/sendmailmc使用dnl注释在下面的行之前,就像这样:

dnl DAEMON_OPTIONS(`Port=smtp,Addr=127001, Name=MTA')

⑵ 将您的sendmailcf文件做一个备份:

cp /etc/mail/sendmailcf /etc/mail/sendmailcforig

⑶ 在同一个目录下,编译sendmailcf

m4 /etc/mail/sendmailmc > /etc/mail/sendmailcf

⑷ 重新启动sendmail,通过

service sendmail restart

对于postfix:修改/etc/postfix/maincf

⑴ 找到并注释如下行

inet_interfaces = localhost

⑵ 取消注释该行:

inet_interfaces = all

⑶ 保存文件并且进行到步骤2 的结束的地方。找到和上面一样的对应于postfix的配置的地方。

对于sendmail: 有几个步骤您应该采用,以确保sendmail被正确安装。

⑴ 确信sendmail已经被在适当的运行级别上运行

检查您的sendmail被适当的配置且能够在重新启动以后其能够运行。使用chkconfig是比较方便的。

chkconfig -–list sendmail

sendmail 0:off 1:off 2:on 3:on 4:on 5:on 6:off

如果sendmail在标准的用户运行级别时无效,使用chkconfig,ntsysv 或者serviceconf 之类的工具来激活服务。

⑵ 确定sendmail没有在启动的时候出现错误

Red Hat Linux安装的时候使用提供的syslog工具来记录所有的信息到文件/var/log/maillog中去。检查此文件中的最后出现“starting”的地方以确保sendmail在启动的时候没有任何错误。

sendmail可执行文件位于/usr/sbin/sendmail。为了确定sendmail是否正确标识您的主机名称,通过命令行开关开启其调试模式并且设定为0:

sendmail –d0 < /dev/null

Version 8116

Compiled with: LDAPMAP MAP_REGEX LOG MATCHGECOS MIME7TO8 MIME8TO7

NAMED_BIND NETINET NETINET6 NETUNIX NEWDB NIS QUEUE SASL SCANF

SMTP TCPWRAPPERS USERDB

============ SYSTEM IDENTITY (after readcf) ============

(short domain name) $w = station2

(canonical domain name) $j = station2examplecom

(subdomain name) $m = station2

(node name) $k = station2examplecom

Recipient names must be specified

如果sendmail返回您的主机名称为localhost,您可能错误配置了/etc/hosts文件。检查您的/etc/hosts文件,删除所有的但记住留下localhost的指向。如果/etc/hosts文件是正确的,那么检查一下在/etc/sysconfig/netwoek中的HOSTNAME的定义。

试图向root@server1发送简单的邮件。您可以看到一个合理的您的主机的转发服务器的SMTP交换。

#echo “hello root” | mail –v –s hello root@server1

root@server1 Connecting to [127001] via relay

220 localhostlocaldomain ESMTP Sendmail 8128/8128; Mon, 22 Sep 2003 14:29:24 +0800

>>> EHLO localhostlocaldomain

250-localhostlocaldomain Hello station1 [127001], pleased to meet you

>>> MAIL From: SIZE=52 AUTH=root@localhostlocaldomain

250 210 Sender ok

>>> RCPT To:

>>> DATA

250 215 Recipient ok

354 Enter mail, end with "" on a line by itself

>>>

250 200 h8M6TOU5026513 Message accepted for delivery

root@192168241182 Sent (h8M6TOU5026513 Message accepted for delivery)

Closing connection to [127001]

>>> QUIT

221 200 localhostlocaldomain closing connection

如果SMTP交换向上面一样正确,那么消息将被转发到您的工作站上的本地的转发服务器上,并且mailq –Ac将会报告一个空的对列。接下来检查mail(不使用参数)来检查一下消息是否从本地的转发到server1。这样对列也应该是空的。

您的消息是不是在/var/log/maillog中正确的记录呢?在下面的步骤中,监视文件/var/log/maillog。下面的命令将会十分的有用:

xterm –e tail –f /var/log/maillog &

对于postfix:

⑴ 运行‘service sendmail stop’,接下来使用redhat-switch-mail使得postfix成为活跃的MTA。您也可以使用如下的命令行:

alternatives –set mta /usr/sbin/sendmailpostfix

⑵ 确保postfix在合适的运行级别有效:

chkconfig -–list postfix

postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off

⑶ 确定hostname命令正确的返回您的主机名称。应该是您的FQDN。

如果sendmail返回您的主机名称为localhost,您可能错误配置了/etc/hosts文件。检查您的/etc/hosts文件,删除所有的但记住留下localhost的指向,然后再试一遍。如果/etc/hosts文件是正确的,那么检查一下在/etc/sysconfig/netwoek中的HOSTNAME的定义。当这些值都正确的时候,启动postfix服务。

⑷ 确定postfix在启动的时候没有错误

和sendmail一样,Red Hat Linux的安装使用提供的syslog工具来记录所有的信息到文件/var/log/maillog中去。检查此文件中的最后查找任何错误信息。

试图向root@server1发送简单的邮件并且检查/var/log/maillog的记录文

mail –s `echo $USER` root@server1 < /etc/redhat-release

应该是如下所示:

Sep 22 02:51:50 station1 postfix/pickup[2865]: A20ED348389: uid=0 from=

Sep 22 02:51:50 station1 postfix/cleanup[3534]: A20ED348389: message-id=<2003092

2065150A20ED348389@station1examplecom >

Sep 22 02:51:50 station1 postfix/nqmgr[2866]: A20ED348389: from=<root@station1e span=""> </root@station1e>

xamplecom>, size=341, nrcpt=1 (queue active)

Sep 22 02:51:51 station1 postfix/smtp[3536]: A20ED348389: to=<root@1921682411 span=""> </root@1921682411>

82>, relay=192168241182[192168241182], delay=1, status=sent (250 Message q

ueued)

对于sendmail:

在sendmail决定消息的接受者的目的地的之前,其先试图在别名中查找。Sendmail的主要的别名配置文件是/etc/aliases。为了优化查找,sendmail为其别名记录建立了一个哈希表数据库/etc/aliasesdb该文件通过newalias命令产生(该命令是sendmail –bi的同名)

下列命令将增加用户student(如果不存在的话)

useradd student

在/etc/aliases 行加入如下的行:

me: student

wizards: root, me

methere: student@stationXexamplecom

现在运行newalias 命令来更新数据库,尝试发送邮件给您定义的收件人:

newalias

echo “hello there” | mail –s “hello” m

echo “hello there” | mail –s “hello” wizards

echo “hello there” | mail –s “hello” methere

您是否得到了期望的结果?是否所有的位于wizards的收件人都收到了邮件?如果没有,su – 到不是root的用户再试一次。

在postfix决定消息的接受者的目的地的之前,其先试图在别名中查找。Postfix的主要的别名配置文件是/etc/postfix/aliases。为了优化查找,postfix为其别名记录建立了一个哈希表别名数据库/etc/postfix/aliasesdb(和sendmail类似)该文件通过newalias命令产生。

下列命令将增加用户student(如果不存在的话)

useradd student

在/etc/postfix/aliases 行加入如下的行:

注意:注释root别名的那一行为postfix

me: student

wizards: root, me

methere: student@stationXexamplecom

现在运行newalias 命令来更新数据库,尝试发送邮件给您定义的收件人:

newalias

echo “hello there” | mail –s “hello” me

echo “hello there” | mail –s “hello” wizards

echo “hello there” | mail –s “hello” methere

您是否得到了期望的结果?是否所有的位于wizards的收件人都受到了邮件?

转发允许邮件通过使用中间的“转发”及其传递到其目的地。尽管这个功能曾经有用,但是转发已经成为Internet上垃圾邮件的源泉了。人们希望发送主动提供的的邮件的时候希望使用转发机制,从而使得邮件发源地很难被侦测出来。

下列步骤将使用下面的主机。替换X,Y和Z为适合的工作站的号码:

stationX:源机器,邮件从这里发出

stationY:转发机器,这里邮件从发送者送出

stationZ:目的机器,邮件的最终目的

该步骤假设您是stationX,转发机器,与某人的stationY合作,该机器为邮件的源头。在该步骤中,注意/var/log/maillog的变化。下列命令将会显得十分的有用。

对于sendmail

步骤⑴ :允许转发

您具有控制允许谁在您的机器上转发的能力。通过控制您的机器的混杂转发,您可以使得任何人都能够将您的机器作为转发的主机。(我们对于这种的尝试表示反对,也希望通过该实验显示出其缺陷)。配置/etc/mail/sendmailmc, 通过加入如下行使得m4前置处理器允许混杂转发:

/etc/mail/sendmailmc

(…其他的内容…)FEATURE(promiscuous_relay)dnl

使用m4前置处理机通过这个模板文件生成一个新的sendmail配置文件,然后将新生成的文件与通过sendmail RPM软件包提供的进行比较

m4 /etc/mail/sendmailmc > /etc/mail/sendmailtest-relay

diff /etc/mail/sendmailtest-relay /etc/mail/sendmailcf

使用混杂转发以后会有多大的不同呢?现在将新建立的sendmailtest放置在恰当的位置上,重新启动sendmail

mv /etc/mail/sendmailcf /etc/mail/sendmailcfaccept-mail

cp /etc/mail/sendmailtest-relay /etc/mail/sendmailcf

service sendmail restart

让您的伙伴扮演恶意的垃圾邮件的发送者,该人能够通过telnet到您的机器上的smtp(sendmail)的25号断口,进行垃圾邮件发送地址的欺骗,在stationY键入如下命令:

这个例子对于stationY(源机器) station2,并且stationX(转发,在这里目的机器) station1

[root@station1 root]# telnet station1 25

Trying station1examplecom

Connected to station1examplecom (station1examplecom)

Escape character is '^]'

220 station1examplecom (IMail 800 8-1) NT-ESMTP Server X1

helo mailcrackerorg

250 hello station1examplecom

mail from: spammer@crackerorg

250 ok

rcpt to:root@station1examplecom

250 ok its for root@mailgridodsorg

data

354 ok, send it; end with

Subject: Faked

this was faked!

250 Message queued

quit

221 Goodbye

Connection closed by foreign host

垃圾邮件现在送到您的机器上了。下一步,看看您的伙伴能不能从您的机器转发给第三台机器:

这个例子对于stationY(源机器) station2,并且stationX(转发,在这里目的机器) station1,并且stationZ(目的机器) station3

[root@station1 root]# telnet station1 25

Trying station1examplecom

Connected to station1examplecom (station1examplecom)

Escape character is '^]'

220 station1examplecom (IMail 800 9-1) NT-ESMTP Server X1

helo mailcrakerorg

250 hello station1examplecom

mail from: spammer@crakerorg

250 ok

rcpt to root@station3examplecom

250 ok its for root@station3examplecom

data

354 ok, send it; end with

Subject: Relayed

this was faked any relayed!

250 Message queued

quit

221 Goodbye

Connection closed by foreign host

由于您的机器已经被配置成为允许混杂转发,垃圾邮件可以通过您的机器进行邮件转发。

对于postfix:

您具有控制允许谁在您的机器上转发的能力。缺省的postfix允许在子网上的任何人通过您的机器进行转发。但是并不是在每一个环境中都安全的。例如,您的机器和其他机器在一起,如果您的本地子网里有一台机器被其他人控制,那么其他的机器都会有麻烦。

让您的伙伴扮演恶意的垃圾邮件的发送者,该人能够通过telnet到您的机器上的postfix的25号断口,进行垃圾邮件发送地址的欺骗,在stationY键入如下命令:

[root@station1 root]# telnet station1 25

Trying 127001

Connected to station1 (127001)

Escape character is '^]'

220 station1examplecom ESMTP Postfix

helo mailcrakerorg

250 station1examplecom

mail from:spammer@crakerorg

250 Ok

rcpt to: root@station1examplecom

250 Ok

data

354 End data with

Subject: Faked

this was faked!

250 Ok: queued as 4FFA2348389

quit

221 Bye

Connection closed by foreign host

垃圾邮件现在送到您的机器上了。下一步,看看您的伙伴能不能从您的机器转发给第三台机器:

这个例子对于stationY(源机器) station2,并且stationX(转发,在这里目的机器) station1,并且stationZ(目的机器) station3

[root@station1 root]# telnet station1 25

Trying 127001

Connected to station1 (127001)

Escape character is '^]'

220 station1examplecom ESMTP Postfix

helo mailcrakerorg

250 station1examplecom

mail from: spammer@crackerorg

250 Ok

rcpt to: root@station3examplecom

250 Ok

data

354 End data with

subject: Relayed

this was faked and relayed!

250 Ok: queued as 69C7B348389

quit

221 Bye

Connection closed by foreign host

由于您的机器已经被配置成为允许混杂转发,垃圾邮件可以通过您的机器进行邮件转发。

步骤⑵ :不允许转发

对于sendmail

通过替换新的sendmailcf为接受传入的信件的配置文件来恢复缺省的sendmail的配置,并且重新启动sendmail:

mv /etc/mail/sendmailcfaccept-mail /etc/mail/sendmailcf

service sendmail restart

让您的伙伴再从stationY转发垃圾邮件。您的sendmail还是一个转发器么?任何一个转发的都会产生如下的消息:

550 root@station3examplecom Relaying denied

对于postfix

编辑文件/etc/postfix/maincf取消转发。

查找并且取消注释下面的行,并且重新启动postfix

mynetworks_style = host

让您的伙伴再从stationY转发垃圾邮件。您的postfix还是一个转发器么?任何一个转发的都会产生如下的消息:

554 : Recipient address rejected: Relay access denied

步骤⑶ :选择性的转发

对于sendmail

对于特定的主机,域或者网络,编辑/etc/mail/access并且重新启动sendmail。为了允许所有在examplecom域中的机器可以把您的机器作为邮件转发服务器,你在/etc/mail/acces中添加如examplecom域。和您的伙伴使用场景A中的命令进行测试。

对于postfix

对于特定的主机,域或者网络,编辑/etc/postfix/maincf并且重新启动postfix。对于特定的主机允许通过您的机器进行转发,找到并且取消注释该行:

mynetworks_style = host

然后添加新行来允许转发的主机和网络,在这里允许station1和本地转发

mynetworks = 19216801, 127000/8

和您的伙伴使用场景A中的命令进行测试。

在这个步骤中,你将配制您的机器stationX作为邮件的POP3服务器,使得您的在stationY的伙伴扮演POP客户端的角色。

步骤⑴ :安装POP3服务器

配置一个POP3服务器比较简单,只需要两个步骤:

① 安装相关的RPM软件包

② 在xinetd中允许服务

① 安装相关的RPM软件包

POP守护进程和其他的具有相同功能的守护进程,例如IMAP守护进程绑定在软件包imap中。再如xinetd,krb5-libs和imap软件包来检查imap软件包含有什么软件。

三个守护进程被包括进来:imapd,ipop2d和ipop3d。POP3被用在很多Internet服务提供商,POP2提供是为了向后兼容。IMAP守护进程提供了根加复杂的能力,包括了在服务器端的文件夹的管理。

② 在xinetd中允许服务

对于本实验,我们仅选定POP3服务。ipop3d通过xinetd在请求的时候被启动。为了激活,运行下面的命令:

service xinetd start

chkconfig ipop3 on

查看一下/etc/xinetdd/ipop3。显式的重新启动xinetd并不是必需的,由于chkconfig发送给xinetd 一个USR2信号告诉他重新调入其配置。

确认服务

运行下面的命令确认服务已经被正确的安装。下面的命令只是一个指导:

echo “mail to be poped” | mail –s “Hello student” student

[root@station1 root]# telnet localhost 110

Trying 127001

Connected to station1 (127001)

+OK POP3 station1 v200178rh server ready

USER student

+OK User name accepted, password please

PASS student

+OK Mailbox open, 1 messages

list

STAT

+OK 1 440

TOP 1 99999

retr 1

+OK Top of message follows

Return-Path: root@station1examplecom

Delivered-To: student@station1examplecom

Received: by station1examplecom (Postfix, from userid 0)

id 72314348390; Mon, 22 Sep 2003 08:02:27 -0400 (EDT)

To: student@station1examplecom

Subject: Hello student

Message-Id: 2003092212022772314348390@station1examplecom

Date: Mon, 22 Sep 2003 08:02:27 -0400 (EDT)

From: root@station1examplecom (root)

Status:

mail to be poped

DELE 1

+OK Message deleted

QUIT

+OK Sayonara

Connection closed by foreign host

如果一切顺利的话,您现在有一个安装好的POP服务器了。

步骤⑵ :使用POP客户端

所有的现在的邮件用户代理(MUA),例如netscape,elm,Outlook,pine和mutt都是使用POP的,可以被用作POP的客户端。每一个的配置都有所不同。同样有一个流行字符界面的的POP客户端叫做fetchmail。fetchmail是高度的可配置的,可以查询多个邮箱,可以作为守护进程运行,这样使得其每五分钟查询用户的邮箱。fetchmail在主机上递送邮件到邮件传送代理(MTA),例如sendmail。我们将勾画出以后如何安装fetchmail和使用其来查询我们装过的POP服务器。

从CD或者从 ftp://server1/pub/RedHat/RPMS来安装fetchmail软件包

注意到有很多选项可以影响fetchmail的行为。建立一个~/fetchmailrc文件如下所示:

~student/fetchmailrc

poll stationXexmaplecom with protocol pop3: user studentXX there is user studentXX here password “password”

由于密码存储在该文件中,因此fetchmail将会拒绝运行除非您把该文件的属性设定为对于仅仅文件的所有者只读。注意还可以使用chown改变由root创建的文件的所有者为studentXX。

chmod 600 ~student/fetchmailrc

chown studentstudent ~student/fetchmailrc

尝试使用studentXX登陆到POP3邮

echo “hello student” | mail –s “Hola” student

su – student

fetchmail –v

exit

fetchmail能不能接收到student的POP邮件?将递送student的邮件到哪里?比从本地获取POP邮件有意义么?

让您的伙伴在另外一台机器上建立相同的~/fetchmailrc文件(或者配置其它诸如mozilla的MTA)试图从您的服务器上进行收信。

⑴ m4宏语言提供给sendmail管理哪些东西?把所有的在xyzcom的用户邮件导向到本地用户xzplogin该使用什么语法?该在什么文件的和处填上这句话?

⑵ mailq命令用来作什么?您如何使用?

⑶ 当命令sendmail –q发出以后,sendmail将会试图仍在队列中等待的邮件。何时使用该命令是有用的?

⑷ 如果去除FEATURE(accept_unresolvable_domains)的注释将对垃圾邮件产生如何的影响?

⑸ m4有什么特征允许sendmail发送邮件作为整个域(例如,“examplecom”)而不是完全的符合标准的主机名称(例如,“mailexamplecom”)?

⑹ 在postfix中mynetworks_style如何影响转发?

请您查看文件/etc/postfix/maincf。

⑺ 在文件/etc/postfix/access中需要如何的活跃的变化?

电脑卡、慢原因很多,比如开机自启动程序过多、安全软件后台进行检测或升级数据库、病毒感染、硬盘碎片过多,长时间运行多个大型软件导致运行内存不足、使用迅雷全速下载等等。

(1)增加物理内存:如果主板有多余内存插槽,可增加与原内存型号规格相匹配的内存。

(2)定期整理硬盘:利用系统自带修复工具或腾讯电脑管家全面体检清除硬盘碎片。

(3)增加运行内存。可使用腾讯电脑管家,定期进行电脑清理和优化加速,以去除不必要的开机自启动程序和各种插件

(4)定期查杀木马病毒。不要加载过多的杀毒引擎。

以上就是关于5.30 电子邮件sendmail试验全部的内容,包括:5.30 电子邮件sendmail试验、为什么我得xzp用了不是很久就觉得很卡,有什、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/9525337.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-29
下一篇 2023-04-29

发表评论

登录后才能评论

评论列表(0条)

保存