Linux 第十周上课笔记smtp服务的部署
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux 第十周上课笔记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
[[email protected] ~]# mail [email protected]#邮件发送格式
Subject: westos#主题
Westos#内容
.#点,表示结束,发送
EOT
[[email protected] ~]# mailq#查看邮件是否成功发送
Mail queue is empty#表示邮件已经成功发送
[[email protected] ~]# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
2CA6024620F 421 Fri Dec 2 03:24:34 [email protected]
(connect to 172.25.254.166[172.25.254.166]:25: No route to host)
-- 0 Kbytes in 1 Request.#如此表示邮件发送失败
删除未能发送的邮件
[[email protected] ~]# postsuper -d 2CA6024620F#-d表示删除,2C..为邮件id
postsuper: 2CA6024620F: removed
postsuper: Deleted: 1 message
在desktop端可以查看到邮件
在发送邮件后稍等片刻就可以查看邮件是否接收成功
[[email protected] ~]# 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 [email protected]
mail [email protected]
###出栈地址伪装###
vim /etc/postfix/generic
在最后一行添加:
[email protected] [email protected]
||||
真实地址伪装地址
postmap /etc/postfix/generic
postconf -d | grep generic
将显示内容中的“smtp_generic_maps =”复制下来
postconf -e "smtp_generic_maps = hash:/etc/postfix/generic"
[[email protected] ~]# systemctl restart postfix.service
测试:
在server端
[[email protected] ~]# mail [email protected]
Subject: wammei
ma
.
EOT
接收方(desktop)
[[email protected] ~]# mailq
Mail queue is empty
您在 /var/spool/mail/root 中有新邮件
[[email protected] ~]# 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 [email protected] Fri Dec 2 05:54:08 2016
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Date: Fri, 02 Dec 2016 05:13:03 -0500
Subject: wammei
User-Agent: Heirloom mailx 12.5 7/5/10
Content-Type: text/plain; charset=us-ascii
From: [email protected] (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
[[email protected] ~]# 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:[email protected]##发送邮件方
250 2.1.0 Ok
rcpt to: [email protected]##收件人
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.
测试:
接收方:
[[email protected] ~]# mailq
Mail queue is empty
您在 /var/spool/mail/root 中有新邮件
[[email protected] ~]# 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 [email protected] Fri Dec 2 06:16 13/317
& 8
Message 8:
From [email protected] Fri Dec 2 06:16:59 2016
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Status: R
hhhh
ds
as
&
测试成功!
以上是关于Linux 第十周上课笔记smtp服务的部署的主要内容,如果未能解决你的问题,请参考以下文章