码迷,mamicode.com
首页 > 系统相关 > 详细

Linux 第十周上课笔记(2)smtp服务的部署

时间:2016-12-03 02:36:15      阅读:298      评论:0      收藏:0      [点我收藏+]

标签:smtp

SMTP服务的部署

介绍:SMTP(Simple Mail Transfer Protocol)简单邮件传输协议是一种提供可靠且有效电子邮件传输的协议。 SMTP 是建模在 FTP 文件传输服务上的一种邮件服务,主要用于传输系统之间的邮件信息并提供来信有关的通知。

一.环境的部署。

迅速配置dns服务器

这里server虚拟机更名为maillinux.linux.com

desktop虚拟机更名为 maillyitx.lyitx.com

server虚拟机上:

1.关闭火墙.selinux

systemctl stop firewalld.service

setenforce 0

2.部署dns

yum install bind -y

systemctl start named

cd /var/named/

cp -p named.localhost linux.com.zone

vim linux.com.zone

 

 技术分享

vim /etc/named.conf

 

options {

//      listen-on port 53 { 127.0.0.1; };

//      listen-on-v6 port 53 { ::1; };

        directory       "/var/named";

        dump-file       "/var/named/data/cache_dump.db";

        statistics-file "/var/named/data/named_stats.txt";

        memstatistics-file "/var/named/data/named_mem_stats.txt";

//      allow-query     { localhost; };

 

vim /etc/named.rfc1912.zones

技术分享

 

cp -p linux.com.zone lyitx.com.zone

vim lyitx.com.zone

技术分享

systemctl restart named

vim /etc/resolv.conf

添加:

nameserver 172.25.254.66  #提供dns解析的主机ip

 

测试:

在客户端:

关闭火墙,selinux

 dig -t mx linux.com

技术分享

########邮件服务的部署###############

server

编辑配置文件:

vim /etc/postfix/main.cf

75 myhostname = maillinux.linux.com#本机的hostname

83 mydomain = linux.com#本机域名

99 myorigin = $mydomain

113 inet_interfaces = all#开放25端口

116 #inet_interfaces = localhost

164 mydestination = $myhostname, $mydomain, localhost

 

vim /etc/resolv.conf

nameserver 172.25.254.66

 

systemctl restart postfix.service

 

同样的,在desktop主机上

vim /etc/postfix/main.cf

75 myhostname = maillinux.linux.com#本机的hostname

83 mydomain = linux.com#本机域名

99 myorigin = $mydomain

113 inet_interfaces = all#开放25端口

116 #inet_interfaces = localhost

164 mydestination = $myhostname, $mydomain, localhost

 

vim /etc/resolv.conf

nameserver 172.25.254.166

systemctl restart postfix.service

测试:

server端发送邮件给desktop

[root@maillinux ~]# mail root@lyitx.com#邮件发送格式

Subject: westos#主题

Westos#内容

.#点,表示结束,发送

EOT

[root@maillinux ~]# mailq#查看邮件是否成功发送

Mail queue is empty#表示邮件已经成功发送

[root@maillinux ~]# mailq

-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------

2CA6024620F      421 Fri Dec  2 03:24:34  root@linux.com

              (connect to 172.25.254.166[172.25.254.166]:25: No route to host)

                                         root@lyitx.com

 

-- 0 Kbytes in 1 Request.#如此表示邮件发送失败

删除未能发送的邮件

[root@maillinux ~]# postsuper -d 2CA6024620F#-d表示删除,2C..为邮件id

postsuper: 2CA6024620F: removed

postsuper: Deleted: 1 message

 

desktop端可以查看到邮件

在发送邮件后稍等片刻就可以查看邮件是否接收成功

[root@maillyitx ~]# mailq

Mail queue is empty

您在 /var/spool/mail/root 中有邮件

技术分享

 

别名发送邮件

vim /etc/aliases

在最后一行添加:

ly:             root#ly相当于root

all:            :include:/etc/allusers

vim /etc/allusers

root

student

postalias /etc/aliases#重新读取文件

systemctl restart postfix.service

测试:

 mail ly@lyitx.com

 mail all@lyitx.com

 

 

###出栈地址伪装###

vim /etc/postfix/generic

在最后一行添加:

root@linux.com  1044088481@qq.com

||||

真实地址伪装地址

 postmap /etc/postfix/generic

postconf -d | grep generic

将显示内容中的“smtp_generic_maps =”复制下来

 postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"

 

[root@maillinux ~]# systemctl restart postfix.service

测试:

server

[root@maillinux ~]# mail root@lyitx.com

Subject: wammei

ma

.

EOT

 

接收方(desktop

 

[root@maillyitx ~]# mailq

Mail queue is empty

您在 /var/spool/mail/root 中有新邮件

[root@maillyitx ~]# mail

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/spool/mail/root": 7 messages 1 new

    1 root                  Fri Dec  2 04:09  26/744   "hello"

    2 root                  Fri Dec  2 04:11  22/733   "hh"

    3 root                  Fri Dec  2 04:25  22/736   "hh"

    4 root                  Fri Dec  2 04:27  22/742   "westos"

    5 root                  Fri Dec  2 05:00  22/739   "123"

    6 root                  Fri Dec  2 05:34  24/742   "111111"

>N  7 root                  Fri Dec  2 05:54  21/738   "wammei"

& 7

Message  7:

From 1044088481@qq.com  Fri Dec  2 05:54:08 2016

Return-Path: <1044088481@qq.com>

X-Original-To: root@lyitx.com

Delivered-To: root@lyitx.com

Date: Fri, 02 Dec 2016 05:13:03 -0500

To: root@lyitx.com

Subject: wammei

User-Agent: Heirloom mailx 12.5 7/5/10

Content-Type: text/plain; charset=us-ascii

From: 1044088481@qq.com (root)

Status: R

 

ma

 

& q

Held 7 messages in /var/spool/mail/root

 

####检测25端口#########

 

yum install telnet -y##server安装服务

telnet 172.25.254.166 25

[root@maillinux ~]# telnet 172.25.254.166 25

Trying 172.25.254.166...

Connected to 172.25.254.166.

Escape character is ‘^]‘.

220 maillyitx.lyitx.com ESMTP Postfix

ehlo hello##手动输入“ehlo hello”打招呼,出现以下内容表示操作正确

250-maillyitx.lyitx.com

250-PIPELINING

250-SIZE 10240000

250-VRFY

250-ETRN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250 DSN

mail from:root@linux.com##发送邮件方

250 2.1.0 Ok

rcpt to: root@lyitx.com##收件人

250 2.1.5 Ok

Data##输入内容

354 End data with <CR><LF>.<CR><LF>

hhhh

ds

 

as

.

250 2.0.0 Ok: queued as DC29717E853

 

500 5.5.2 Error: bad syntax

quit

221 2.0.0 Bye

Connection closed by foreign host.

 

测试:

接收方:

[root@maillyitx ~]# mailq

Mail queue is empty

您在 /var/spool/mail/root 中有新邮件

[root@maillyitx ~]# mail

Heirloom Mail version 12.5 7/5/10.  Type ? for help.

"/var/spool/mail/root": 8 messages 1 new

    1 root                  Fri Dec  2 04:09  26/744   "hello"

    2 root                  Fri Dec  2 04:11  22/733   "hh"

    3 root                  Fri Dec  2 04:25  22/736   "hh"

    4 root                  Fri Dec  2 04:27  22/742   "westos"

    5 root                  Fri Dec  2 05:00  22/739   "123"

    6 root                  Fri Dec  2 05:34  24/742   "111111"

    7 root                  Fri Dec  2 05:54  22/749   "wammei"

>N  8 root@linux.com        Fri Dec  2 06:16  13/317   

& 8

Message  8:

From root@linux.com  Fri Dec  2 06:16:59 2016

Return-Path: <root@linux.com>

X-Original-To: root@lyitx.com

Delivered-To: root@lyitx.com

Status: R

 

hhhh

ds

 

as

 

&

测试成功!


Linux 第十周上课笔记(2)smtp服务的部署

标签:smtp

原文地址:http://12150355.blog.51cto.com/12140355/1878989

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!