zoukankan      html  css  js  c++  java
  • Linux postfix配置方法

    第七题 配置邮件服务器

    postfix学习网站:https://blog.csdn.net/mycms5/article/details/78773308 

    system1和systemc2分别执行

    [root@system2 ~]# postconf -e inet_interfaces=loopback-only
    [root@system2 ~]# postconf -e mydestindation=
    [root@system2 ~]# postconf -e local_transport=error:err
    [root@system2 ~]# postconf -e relayhost=[mail.group8.example.com]
    [root@system2 ~]# postconf -e myorigin=server.group8.example.com
    [root@system2 ~]# systemctl enable postfix
    [root@system2 ~]# systemctl restart postfix
    [root@system2 ~]# echo "hello" | mail -s testmail dave

    参数解释:

    relayhost 设定中心邮件服务器
      收到的邮件全部转交给配置的服务器
    inet_interfaces只在本地环回接口接受邮件
      loopback-only表示只接受本地邮件,只在127.0.0.1监听25号端口deli
    myorigin 设定发信人的域
      假设发信人为lily,那么会将信件的发信人改为lily@server.group8.example.com
      如果配置选项为188.com,那么发信人lily就会被改为lily@188.com
    mydestindation 将接收到的任何邮件都当做外部邮件,这样邮件才会转发的到中心邮件服务器
      收到的所有信件,不管收信人是谁,都不会保存。
      可以理解为收到的所有的邮件都要转出去。
    local_transport
      当配置local_transport=error: local delivery disabled时,表示禁止本地分发邮件到本地用户邮箱
    mynetworks 信任的网络
      只接受配置选项中网络的邮件

    验证:

    [root@system1 postfix]# curl http://server.group8.example.com/pub/received_mail/8
    From root@server.group8.example.com Wed Apr 10 19:18:39 2019
    Return-Path: <root@server.group8.example.com>
    X-Original-To: dave@server.group8.example.com
    Delivered-To: dave@server.group8.example.com
    Received: from system1.group8.example.com (system1.group8.example.com [172.24.8.11])
    by server.group8.example.com (Postfix) with ESMTP id B5F0E3089EFD
    for <dave@server.group8.example.com>; Wed, 10 Apr 2019 19:18:39 +0800 (CST)
    Received: by system1.group8.example.com (Postfix, from userid 0)
    id 9B87C22E33F0; Wed, 10 Apr 2019 19:18:39 +0800 (CST)
    Date: Wed, 10 Apr 2019 19:18:39 +0800
    To: dave@server.group8.example.com
    Subject: testmail
    User-Agent: Heirloom mailx 12.5 7/5/10
    MIME-Version: 1.0
    Content-Type: text/plain; charset=us-ascii
    Content-Transfer-Encoding: 7bit
    Message-Id: <20190410111839.9B87C22E33F0@system1.group8.example.com>
    From: root@server.group8.example.com (root)
    
    hello

    紧急情况补救措施:
    打开配置文件,搜索配错了的某一项,然后将该项进行删除,重新配置即可
    vim /etc/postfix/main.cf
    至此,考试内容结束

    实验:配置只发邮件服务器

    首先在两台机器上分别执行实验脚本

    [root@server0 ~]# lab smtp-auth setup 
    [root@desktop0 ~]# lab smpt-auth setup


    Server0:

    [root@server0 ~]# postconf -e "relayhost=[smtp0.example.com]:587" 
    [root@server0 ~]# postconf -e "inet_interfaces=loopback-only"
    [root@server0 ~]# postconf -e "mynetworks=127.0.0.0/8 [::1]/128"
    [root@server0 ~]# postconf -e "myorigin=desktop0.example.com"
    [root@server0 ~]# postconf -e "mydestination="
    [root@server0 ~]# postconf -e "local_transport=error: local delivery disabled"

    从下开始与普通邮件不同

    [root@server0 ~]# postconf -e "smtp_use_tls=yes" 
    将用户名和密码以tls的形式加密
    [root@server0 ~]# postconf -e "smtp_tls_loglevel=1"
    日志级别
    [root@server0 ~]# postconf -e "smtp_tls_security_level=encrypt"
    信息加密
    [root@server0 ~]# postconf -e "smtp_sasl_auth_enable=yes"
    启用smtp发送验证
    [root@server0 ~]# postconf -e "smtp_sasl_security_options=noanonymous"
    禁止匿名
    [root@server0 ~]# postconf -e "smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd"
    用户密码所在文件


    Server0配置

    解释:只要是将邮件转给smtp0.example.com的587端口的,我们就用student:student

    [root@server0 ~]# vim /etc/postfix/sasl_passwd 
    smtp0.example.com:587 student:student

    修改密码文件权限为0600

    [root@server0 ~]# chmod 0600 /etc/postfix/sasl_passwd

    修改文件格式

    [root@server0 ~]# postmap /etc/postfix/sasl_passwd

    其实真正使用的文件为/etc/postfix/sasl_passwd.db这个文件来验证也就是修改格式后的文件


    重载服务

    [root@server0 ~]# systemctl reload postfix

    发送邮件

    [root@server0 ~]# mail -s "server0 sasl tls" student@desktop0.example.com
    sasl tls test.      这一行写邮件内容
    .    用.来结束邮件内容
    EOT

    收信

    [root@server0 student]# su student
    [student@server0 ~]$ mutt -f imaps://imap0.example.com

    验证:

    Server0:

    [root@server0 student]# lab-smtp-auth grade
    Checking for Postfix configuration... PASS
    Checking for Postfix TLS and SASL configuration... PASS
    Desktop0:
    
    [root@desktop0 ~]# lab smtp-auth grade
    Checking E-mail is present in student inbox... PASS

    至此,实验结束

    如果有什么建议或者意见,请直接在评论区留言或者私信本人,看到了第一时间回复。

    本人Linux菜鸟,欢迎各位Linux大神指导。

  • 相关阅读:
    go-go协程
    linux-pclint代码检测
    linux-32位-交叉编译openssl
    go-json类
    mysql-定时任务
    go-IO操作
    go-异常处理-error-panic-recover
    go-defer语句
    go-select
    go-指针
  • 原文地址:https://www.cnblogs.com/despotic/p/10810251.html
Copyright © 2011-2022 走看看