美文网首页
Ubuntu18.04服务器配置POSTFIX+SSL(TLS)

Ubuntu18.04服务器配置POSTFIX+SSL(TLS)

作者: SystemLight | 来源:发表于2020-01-14 20:57 被阅读0次

闲谈:关于Ubuntu18.04服务器配置POSTFIX+SSL(TLS)安全验证+FOXmail这个套件的配置网上的说明比较少,文档大多没说明白,可能我这套搭配比较少见,大部分可能还是在centos搭建,这方面文章比较多,我就不多提了,另外Ubuntu和centos配置是有区别的,请注意,另外这套配置我参考了许多篇国内外文章,然后加了自己的一些内容,最后终于成功了,里面的配置不是死的,请灵活应用。

搭建DNS服务解析

emmmm怎么说呢,如果你只是自己的邮箱服务内部几个账户来回发发邮件,这个不配置也可以。很多文章中也提到了要进行配置DNS服务器,但是里面有些坑,我列举一下。

  1. 如果你的服务器是阿里云平台,这种云平台服务器,25端口是默认被封禁的,但是我们配置SSL后,我们的邮箱服务是使用的465端口,理论上是不会拦截的,不过我没试过,如果是不配置SSL只在25端口上跑邮件服务是配置相对来说简单的,但是你在云平台的服务器一定调不通,除非你申请并通过了25端口解禁(一般来说不会允许你的,我申请好几次了)

  2. 我是本地配置的DNS服务器,阿里云配置的话直接云解析指过来就行了,不会本地配DNS服务器的小伙伴请百度。

更新软件源

使用Ubuntu默认源会有坑,我们更新阿里云的镜像源

vim /etc/apt/source.list

# 镜像内容来源这个网址:https://developer.aliyun.com/mirror/ubuntu?spm=a2c6h.13651102.0.0.53322f702T2seh
# 把下列内容加进去
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
# 更新镜像源
apt update

下载安装postfix+dovecot,具体参考:https://blog.csdn.net/cpu0606/article/details/89841784

apt-get install mailutils
apt-get install dovecot-pop3d

按照我说的安装好就行了,上面链接中的文章把SSL关掉了,不要学他的配置

配置SSL

如果你正常安装,且现在没动任何的配置文件,那么你已经完成一半了,
为什么是一半呢,因为dovecot-pop3d默认把SSL已经开启了

查看现在的端口

netstat -ntpul

正常情况能看到110,995,25这三个端口被监听了

配置SMTPS

由于postfix没有开启SSL认证,我们粗略配置下

vim /etc/dovecot/conf.d/10-master.conf
把文件中,这个位置的两个注释地方去掉注释标记

service auth {
  # auth_socket_path points to this userdb socket by default. It's typically
  # used by dovecot-lda, doveadm, possibly imap process, etc. Its default
  # permissions make it readable only by root, but you may need to relax these
  # permissions. Users that have access to this socket are able to get a list
  # of all usernames and get results of everyone's userdb lookups.
  unix_listener auth-userdb {
    #mode = 0600
    #user = 
    #group = 
  }

  # Postfix smtp-auth
  unix_listener /var/spool/postfix/private/auth {
    mode = 0660
    user = postfix  # 去掉注释
    group = postfix # 去掉注释
  }

# 退出来后重启服务
systemctl restart dovecot
vim /etc/postfix/main.cf

# 文件中这个位置,添加如下内容
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_local_domain =
smtpd_sasl_security_options = noanonymous
broken_sasl_auth_clients = yes
smtpd_sasl_auth_enable = yes
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,reject_unauth_destination
vim /etc/postfix/master.cf

# 更改并添加如下配置
# ==========================================================================
# service type  private unpriv  chroot  wakeup  maxproc command + args
#               (yes)   (yes)   (no)    (never) (100)
# ==========================================================================

smtp      inet  n       -       n       -       -       smtpd  # 你如果看到了这一行,在配置文件中,把chroot列的y改成n

# 启用465端口,添加如下内容
smtps     inet  n       -       -       -       -       smtpd
  -o smtpd_tls_wrappermode=yes
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
  -o milter_macro_daemon_name=ORIGINATING
# 退出文件编辑后重启服务
systemctl restart postfix 

查看现在的端口

netstat -ntpul

正常情况能看到110,995,25,465这四个端口被监听了

使用FOXmail进行SSL连接

点击其它邮箱,手动设置

域名就是你的DNS指向的域名了

收发验证

如果创建成功了,你可以给自己的qq邮箱发一封短信试一下,QQ默认只能465端口发送,
也就是说发送成功的话,你的SSL配置也就成功了,注意,邮件是会进入到QQ垃圾箱的,找一下

相关文章

网友评论

      本文标题:Ubuntu18.04服务器配置POSTFIX+SSL(TLS)

      本文链接:https://www.haomeiwen.com/subject/ugoaactx.html