postfix 邮件1

######邮件部分######

 

前提

1.保证环境的纯净

postfix 邮件1

 

2.dns的配置

 

*此处关于dns不做解释,可参照之前dns博客理解


[[email protected] ~]# yum install bind -y

 postfix 邮件1

[[email protected] ~]# systemctl start named

 

[[email protected] ~]# vim /etc/named.conf

postfix 邮件1 

 

[[email protected] ~]# vim /etc/named.rfc1912.zones  

 postfix 邮件1

[[email protected] ~]# cd /var/named/

[[email protected] named]# ls

data     named.ca     named.localhost  slaves

dynamic  named.empty  named.loopback

[[email protected] named]# cp -p named.localhost westos.com.zone

[[email protected] named]# vim westos.com.zone

postfix 邮件1

 

[[email protected] named]# cp -p westos.com.zone qq.com.zone

[[email protected] named]# vim qq.com.zone

postfix 邮件1                                                 

[[email protected] named]# systemctl restart named

[[email protected] named]# systemctl stop firewalld

[[email protected] named]# systemctl disable firewalld  ##不关闭火墙,其他人不能dig到

rm '/etc/systemd/system/basic.target.wants/firewalld.service'

rm '/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service'

[[email protected] named]# vim /etc/resolv.conf

postfix 邮件1 


[[email protected] named]# dig -t mx westos.com

postfix 邮件1 

[[email protected] named]# dig -t mx qq.com

postfix 邮件1

 

######postfix#####

1.基本定义

postfix提供smtp协议用来投递邮件

默认端口25

 

[[email protected] named]# mail [email protected]

Subject: w

wq

.    ##用“.”来结束录入内容并发送

EOT

 

   ##默认情况下邮件端口只在127.0.0.1上开启

[[email protected] named]# netstat -antlpe | grep master

tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      0          21046      1378/master         

tcp6       0      0 ::1:25                  :::*                    LISTEN      0          21047      1378/master         

***邮件日志存储地址   /var/log/maillog

 

mail        ##邮件查看

mailq       ##查看邮件队列

postqueue -f    ##重新处理邮件队列 

 

 

2.配置

[[email protected] named]# vim /etc/postfix/main.cf

76 myhostname = westos-mail.westos.com    ##指定mta主机名称

83 mydomain = westos.com        ##指定mta的域名

99 myorigin = $mydomain         ##指定邮件来源结尾(@后面的字符内容)

116 inet_interfaces = all     ##25端口开启的网络端口

164 mydestination = $myhostname, $mydomain, localhost    ##接收邮件结尾字符的指定

 

[[email protected] named]# systemctl restart postfix.service

[[email protected] named]# systemctl stop firewalld

 

 

  ##更改后:

[[email protected] named]# netstat -antlpe | grep master

tcp        0      0 0.0.0.0:25              0.0.0.0:*               LISTEN      0          110726     928/master          

tcp6       0      0 :::25                   :::*                    LISTEN      0          110727     928/master          

 

 

3.邮件别名与群发

 

[[email protected] named]# vim /etc/aliases

 97 admin:          root        ##邮件别名(用admin发送但是接收端显示的是root)

 98 moreuser:       :include:/etc/postfix/moreuser   ##邮件群发

 

[[email protected] named]# vim /etc/postfix/moreuser

  1 student

  2 root

~                                                  

[[email protected] named]# postalias /etc/aliases   ##立即生效

 

测试:

1)别名测试

[[email protected] ~]# mail [email protected]     发送端)

Subject: wq

wq

wq

wq

.

EOT

 

 

[[email protected] named]# mail        接收端)

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

"/var/spool/mail/root": 1 message 1 new

>N  1 root                  Sat May 20 04:13  24/859   

& 1

Message  1:From [email protected]  Sat May 20 04:11:21 2017

Return-Path: <[email protected]>

X-Original-To: [email protected]

Delivered-To: [email protected]

Date: Sat, 20 May 2017 04:11:21 -0400

To: [email protected]

Subject: wq

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

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

From: [email protected] (root)

Status: RO

 

wq

wq

wq

 

& q

 

2)群发测试

[[email protected] ~]# mail [email protected]     发送端)

Subject: wqq

hahaha

.

EOT

[[email protected] ~]# mailq

Mail queue is empty

[[email protected] named]# mail  接收端)

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

"/var/spool/mail/root": 1 message 1 new

>N  1 root                  Sat May 20 04:13  24/859   

& 1

Message  1:

From [email protected]  Sat May 20 04:13:15 2017

Return-Path: <[email protected]>

X-Original-To: [email protected]

Delivered-To: [email protected]

Delivered-To: [email protected]

Date: Sat, 20 May 2017 04:13:15 -0400

To: [email protected]

Subject: wqq

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

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

From: [email protected] (root)

Status: R

 

hahaha

 

& q

Held 1 message in /var/spool/mail/root

[[email protected] named]# mail -u student

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

"/var/mail/student": 1 message 1 new

>N  1 root                  Sat May 20 04:13  24/862   

& 1

Message  1:

From [email protected]  Sat May 20 04:13:15 2017

Return-Path: <[email protected]>

X-Original-To: [email protected]

Delivered-To: [email protected]

Delivered-To: [email protected]

Date: Sat, 20 May 2017 04:13:15 -0400

To: [email protected]

Subject: wqq

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

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

From: [email protected] (root)

Status: R

 

hahaha

 

& q

Held 1 message in /var/mail/student

 

 

 

 

 

4.远程主机测试邮件服务

[[email protected] kiosk]#  yum install telent -y   ##安装服务

 

[[email protected] kiosk]# telnet 172.25.254.113 25   ##连接113主机的25端口

Trying 172.25.254.113...

Connected to 172.25.254.113.

Escape character is '^]'.

220 westos-mail.westos.com ESMTP Postfix

ehlo hello    ##打招呼,查看是否回应

250-westos-mail.westos.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>

wq          ##邮件内容

haha

lalala

.

250 2.0.0 Ok: queued as E2A022461FD

 

测试端:

[[email protected] ~]# mail

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

"/var/spool/mail/root": 4 messages 1 new 3 unread

    1 root                  Sat May 20 03:46  22/730   

 U  2 Mail Delivery System  Sat May 20 04:12  76/2389  

 U  3 Mail Delivery System  Sat May 20 04:12  76/2389  

>N  4 [email protected]       Sat May 20 04:38  15/493   

& 4

Message  4:

From [email protected]  Sat May 20 04:38:35 2017

Return-Path: <[email protected]>

X-Original-To: [email protected]

Delivered-To: [email protected]

Status: R

 

wq

haha

lalala

 

& q

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

You have mail in /var/spool/mail/root

[[email protected] ~]#

 

 

 

5.邮件客户端的访问控制

##限制客户端

mta上

[[email protected] ~]# postconf -e "smtpd_client_restrictions = check_client_access hash:/etc/postfix/access"  ##用参数检测此文件使其识别文件内容

 

[[email protected] ~]# vim /etc/postfix/main.cf  ##自动生成在文件末尾

680 smtpd_client_restrictions = check_client_access hash:/etc/postfix/access

 

[[email protected] ~]# vim /etc/postfix/access

477 172.25.254.13 REJECT

 

[[email protected] ~]# postmap /etc/postfix/access    ##加密

[[email protected] ~]# cd /etc/postfix/

[[email protected] postfix]# ls    ##access.db即位加密文件

access     generic        master.cf  transport

access.db  header_checks  moreuser   virtual

canonical  main.cf        relocated

 

[[email protected] postfix]# systemctl restart postfix.service

  

测试:

实验前:

[[email protected] kiosk]# telnet 172.25.254.113 25

Trying 172.25.254.113...

Connected to 172.25.254.113.

Escape character is '^]'.

220 westos-mail.westos.com ESMTP Postfix

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>

wq

haha

lalala

.

250 2.0.0 Ok: queued as E2A022461FD

Connection closed by foreign host.    ##连接成功

实验后:

[[email protected] kiosk]# telnet 172.25.254.113 25

Trying 172.25.254.113...

Connected to 172.25.254.113.

Escape character is '^]'.

220 westos-mail.westos.com ESMTP Postfix

mail from:[email protected]

250 2.1.0 Ok

rcpt to:[email protected]

554 5.7.1 <unknown[172.25.254.13]>: Client host rejected: Access denied    ##连接被拒