linux运维-postfix邮件的处理

postfix
定义:提供smtp协议用来投递邮件,默认端口25


    重置两台虚拟机,配置yum源及正向解析
1.发送邮件 

 mail [email protected]
        Subject: hello
        hello world
        .                       ##
用“.”来结束录入内容并发送
linux运维-postfix邮件的处理


    mailq       ##查看邮件队列
linux运维-postfix邮件的处理


    postqueue -f    ##重新处理邮件队列
linux运维-postfix邮件的处理


    postsuper -d    ##删除邮件队列


    mail        ##查看邮件

linux运维-postfix邮件的处理
    默认情况下邮件端口只在127.0.0.1上开启

 
2.
配置
    vim /etc/postfix/main.cf
        76 myhstname = westos-mail.westos.com  ##
指定mta主机名
linux运维-postfix邮件的处理
        83 mydomain = westos.com       ##指定mta域名

linux运维-postfix邮件的处理
        99 myorigin = westos.com       ##指定邮件来源结尾(@后面的内容)

linux运维-postfix邮件的处理
        116 inet_interfaces = all       ##25端开启的网络接口

linux运维-postfix邮件的处理
        164 mydestination = $myhostname,$mydomain, localhost   ##接收邮件结尾字符的指定

linux运维-postfix邮件的处理
    systemctl restartpostfix.service
    systemctl stop firewalld   
linux运维-postfix邮件的处理

3.邮件别名

  设置别名:
qq
    vim /etc/aliases   
   
别名: 真名
    postalias /etc/aliases   ##重新读取配置文件
linux运维-postfix邮件的处理


linux运维-postfix邮件的处理

westos:
    mail [email protected]

测试:

linux运维-postfix邮件的处理


linux运维-postfix邮件的处理  

群发邮件:
qq
    vim /etc/aliases
    moreuser
  :include:/etc/postfix/moreuser
linux运维-postfix邮件的处理
    postalias /etc/aliases
    vim /etc/postfix/moreuser
linux运维-postfix邮件的处理
westos:
    mail [email protected]   
linux运维-postfix邮件的处理

linux运维-postfix邮件的处理



linux运维-postfix邮件的处理

 

4.远程发送邮件:
    telnet 172.25.254.122 25    ##连接到122的25端口
    Trying 172.25.254.122...
    Connected to 172.25.254.122.
    Escape character is '^]'.
    220 westos-mail.westos.com ESMTPPostfix
    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>
    cndkjsfnhvkjnfdkjgnrejne    ##
邮件内容
    .
    250 2.0.0 Ok: queued as 8956D246244
    quit
    221 2.0.0 Bye
    Connection closed by foreignhost.
linux运维-postfix邮件的处理

 

 


linux运维-postfix邮件的处理

 

5.邮件客户端的访问控制:
在mta上:
    postconf -e"smtpd_client_restrictions = check_client_accesshash:/etc/postfix/access"  ##更改postfix默认配置,增加客户端的访问控制,将被限制访问的客户端写入/etc/postfix/access中
    vim /etc/postfix/main.cf            ##检查主配置文件是否添加了访问控制
linux运维-postfix邮件的处理
    vim /etc/postfix/access             ##将拒绝连接的客户端写入此配置文件

    172.25.254.22 REJECT
linux运维-postfix邮件的处理
    postmap /etc/postfix/access         ##加密/etc/postfix/access文件

    systemctl restart postfix           ##重启服务
linux运维-postfix邮件的处理

测试:

linux运维-postfix邮件的处理


   
6.限制用户发送:(只能接受不能发送)
    postconf -d |grep sender
    postconf -e “smtpd_sender_restrictions= check_sender_access hash:/etc/postfix/sender” ##
更改postfix配置,限制用户发送邮件,将被限制的用户名将被写入/etc/postfix/sender中
    vim /etc/postfix/main.cf            ##检查主配置文件是否添加了用户限制
linux运维-postfix邮件的处理
    vim /etc/postfix/sender             ##将被限制的用户名写入此文件中

        [email protected] REJECT
linux运维-postfix邮件的处理
    postmap /etc/postfix/sender         ##加密/etc/postfix/sender文件

    systemctl restart postfix           ##重启服务
linux运维-postfix邮件的处理

测试:

linux运维-postfix邮件的处理


linux运维-postfix邮件的处理



linux运维-postfix邮件的处理

 

7.限制用户接受:(只能发送不能接受)
    postconf -e"smtpd_recipient_restrictions = check_recipient_accesshash:/etc/postfix/recip"   ##更改postfix配置,限制用户接受邮件,将被限制的用户名将被写入/etc/postfix/recip中
    vim /etc/postfix/main.cf            ##检查主配置文件是否添加了用户限制
linux运维-postfix邮件的处理   
    vim /etc/postfix/recip              ##将被限制接受的用户写入此文件中

        [email protected] REJECT  
linux运维-postfix邮件的处理
    postmap /etc/postfix/recip          ##加密/etc/postfix/recip文件

    systemctl restart postfix           ##重启服务
linux运维-postfix邮件的处理

测试:

linux运维-postfix邮件的处理


linux运维-postfix邮件的处理
linux运维-postfix邮件的处理

 

8.出站伪装
    postconf -e "smtp_generic_maps =hash:/etc/postfix/generic"
    vim /etc/postfix/main.cf            ##
检查主配置文件是否添加了出战伪装
linux运维-postfix邮件的处理
    vim /etc/postfix/generic
    真实地址            伪装地址

    [email protected]      [email protected]
linux运维-postfix邮件的处理
    postmap /etc/postfix/gemeric
    systemctl restart postfix
linux运维-postfix邮件的处理

测试:

linux运维-postfix邮件的处理


linux运维-postfix邮件的处理

 

9.入站地址转换
    dns mx 将伪装地址的域的记录解析先做好
    vim /etc/named.rfc1912.zones    ##增加girl.com的正向解析
    cd /var/named
    ls
    cp -p westos.com.zonegirl.com.zone
    postconf -e "virtual_alias_maps =hash:/etc/postfix/virt"
linux运维-postfix邮件的处理
    vim /etc/postfix/virt
    虚拟名字            真实用户

    [email protected]      [email protected]
linux运维-postfix邮件的处理
    postmap /etc/postfix/virt
    systemctl restart postfix  
linux运维-postfix邮件的处理

测试:

linux运维-postfix邮件的处理

linux运维-postfix邮件的处理