ubuntu postfix ubuntu插了网线没有有线连接

如何在Ubuntu或者Debian设置邮件服务器

1.先决条件

每个域必须有一个DNS服务器。建议不要使用Live域用于测试目的。在本教程中,将在实验室环境中使用测试域example.tst。在这个假设域名的DNS服务器应该在至少以下记录。

example.tst的forward zone配置:

IN MX 10 mail.example.tst.

mail.example.tst. IN A 192.168.10.1

example.tst的Reverse zone配置:

192.168.10.1 IN PTR mail.example.tst.

在配置邮件服务器的过程中,这些记录可以根据系统的要求进行修改。

2.设置主机名

首先,必须在/etc/hostname和/etc/hosts文件中指定邮件服务器的主机名。前者应仅包含主机名。

root@mail:~# vim/etc/hostname

mail

root@mail:~# vim/etc/hosts

## IP Fully Qualified Domain Name Hostname##

192.168.10.1 mail.example.tst mail

增加用户

每一个Linux用户,在默认情况下,系统会为其自动创建一个邮箱。这些用户和邮箱将被用作电子邮件帐户和它们各自的邮箱。创建一个用户是很容易的。

root@mail:~# adduser fourbyte

安装和配置SMTP

服务: postfix

配置文件路径/etc/postfix/

执行脚本/etc/init.d/postfix

日志文件/var/log/mail.log

端口 TCP/25

SMTP:安装postfix

postfix是广泛使用的SMTP服务器之一,因为它是稳定的、轻量级的、可扩展的、高度可定制的。安装postfix可以使用apt-get的完成。

root@mail:~# apt-get install postfix

在安装过程中,需要指定电子邮件服务器和域名的类型。

由于此邮件服务器就会直接向目的地发送电子邮件,我们选择Internet Site。

邮件服务器的域名也需要配置,这可以从确保该邮件服务器发送的所有邮件都有@ example.tst作为发件人域。

postfix的配置文件存储在/etc/postfix目录。下面的配置文件是非常重要的。他们中的一些可能不存在,因此需要手动创建。

transport:主要用于定义邮件如何被路由到特定的目标域。绕过DNS查询可以是一个很好的例子。在这种情况下,人们可以发送到域XYZ.com的电子邮件直接通过IP地址XYYX不考虑任何DNS查询的结果。

access:可用于安全目的,如阻止发件人/收件人和他们的域名。

aliases:用于定义用户别名。例如,发送到userA的邮件可以由userB和userC接收。

main.cf:是postfix的配置文件。

SMTP:准备配置文件

差不多可以准备配置文件了。transport与aliases配置文件没有默认提供,需要手动创建。

root@mail:~# cd/etc/postfix

root@mail:/etc/postfix# touch transport aliases

main.cf

首先需要备份main.cf然后再进行修改。根据下面的配置添加或修改配置文件。有关参数的更多详细信息,请参阅官方README和配置手册。

root@mail:/etc/postfix# vim main.cf

## the name of the server##

myhostname= mail.example.tst

## alias definitions##

alias_maps= hash:/etc/postfix/aliases

alias_database= hash:/etc/postfix/aliases

## transport definition##

transport_maps= hash:/etc/postfix/transport

## myorigin defines the domain name for emails originated from this server. In this case, all outgoing mail should have'@example.tst' as sender domain##

myorigin= example.tst

## mydestination parameter specifies what domains this machine will deliver locally, instead of forwarding to another machine.##

mydestination= mail.example.tst, localhost.example.tst, localhost, hash:/etc/postfix/transport

## the smarthost address. Not used in this tutorial and will be covered in the future##

relayhost=

## the trusted sender networks. postfix will not forward mails originated from other subnets##

mynetworks= 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 192.168.10.0/24

## mailbox size in bytes. 0 denotes no limit##

mailbox_size_limit= 0

## postfix will listen on all available interfaces i.e. eth0, eth1, eth2 and so on##

inet_interfaces= all

transport

邮件域example.tst被定义为在本地传递不需要任何DNS查询。

root@mail:/etc/postfix# vim transport

example.tst local:

.example.tst local:

root@mail:/etc/postfix# postmap transport

aliases

假设所有发送到userA的所有电子邮件可以由userB接收,别名文件需要按如下所述进行修改。

云上那些事: postfix 使用中继模式发送邮件

背景:

由于安全因素,阿里云会封掉25port,这导致我们自建的监控系统无法发送邮件,因为是轻量型应用,申请解封失败,遂按照推荐的方式采用了465 port和relay的模式进行告警邮件的发送

组件构成:

一个main,cf

一个master.cf

一个sasl_password 和生成的sasl_password.db

一个generic和生成的generic.db文件

步骤:

由于我们使用的是ubuntu18.04,所以此处以此为例:

#安装postfix 

apt upgrade

apt install postfix ,选择 Internet Site( 如果安装了sendmail请将其停止或者卸载)

#添加465端口发信

vim/etc/postfix/master,cf

添加 smtps inet n---- smtpd

解除注释: -o smtpd_tls_wrappermode=yes

!wq保存退出

vim/etc/services

添加 smtps   465/tcp   mail2

     smtps   465/udp   mail2

#创建相关授权文件及虚拟映射文件

vim/etc/postfix/sasl_passwd

[smtp.163.com]:465   username@163.com:授权码

!wq 保存退出

postmap/etc/postfix/sasl_passwd生成sasl_passwd.db文件

vim/etc/postfix/generic

root@monitor   username@163.com    (#要和上面文件内的一样)

!wq保存退出

postmap/etc/postfix/generic  生成generic.db文件

#编辑主配置文件

vim/etc/postfix/main.cf

新增如下:

smtp_sasl_auth_enable= yes

#smtp_sasl_type= cyrus

smtp_sasl_security_options=noanonymous

smtp_sasl_password_maps= hash:/etc/postfix/sasl_passwd

smtp_tls_security_level= encrypt

smtp_tls_wrappermode= yes

smtp_generic_maps= hash:/etc/postfix/generic

修改如下:

inet_protocols= ipv4

#重启服务

systemctl restart postfix

测试发送,如有问题请检查log

主要报错:

1

status=deferred(delivery temporarily suspended: lost connection with smtp.163.com[220.181.12.12] while receiving the initial server greeting)

要配置relay模式

2:

status=deferred(SASL authentication failed; cannot authenticate to server smtp.163.com[220.181.12.17]: no mechanism available)

修改/etc/postfix/main.cf

smtp_sasl_security_options=noanonymous

3:

status=bounced(host smtp.163.com[220.181.12.16] said: 553 Mail from must equal authorized user(in reply to MAIL FROM command))

修改/etc/postfix/generic把主机名和邮箱名字修复正确。

4

postfix/smtp[3218]: SMTPS wrappermode(TCP port 465) requires setting"smtp_tls_wrappermode= yes", and"smtp_tls_security_level= encrypt"(or stronger)

按照报错提示在主文件添加相关配置项

参考资料:  

Ubuntu用Postfix+Dovecot搭建优秀的邮件服务器

搭建邮件服务器,使用Postfix+Dovecot模式,实现MTA与MDA的高效协同。Postfix负责邮件的发送与接收,提供smtp服务;Dovecot则负责邮件存储到邮箱,提供pop3和imap服务。通过Dovecot的SASL功能完成用户认证,使用MySQL存储虚拟用户信息。opendkim用于邮件的dkim签名,SpamAssassin实现反垃圾邮件功能。SSL配置确保邮件传输安全。

选择服务器时,确保有公网IP,开放25端口,主机名设置为域名或子域名,修改时区为北京时间。申请域名,添加A、MX、SPF与DMARC记录,实现邮件路由和反垃圾防护。

SSL证书申请,确保包含所有域名记录,配置postfix和dovecot,安装并设置MySQL数据库,创建表并添加内容。修改配置文件,集成Postfix与MySQL,实现与Dovecot的协同工作。配置Postfix的MySQL文件,包含域名、数据库、用户权限等信息。完成主配置文件的SSL和Dovecot身份验证规则配置。

创建和配置Dovecot用户,设置家目录,调整auth-sql.conf.ext和conf.d文件,启用SQL设置。配置dovecot.conf以启用SSL认证,并确保安全策略。执行权限修改和重启服务,邮件服务器搭建完成。

集成OpenDKIM,生成密钥对,将DKIM记录添加至域名,重启postfix和opendkim。配置SpamAssassin以实现反垃圾邮件功能。客户端如FoxMail或雷鸟连接服务器,输入正确的smtp、pop3和imap服务器地址与端口号。

测试邮件服务器,使用在线工具检查配置正确性,评估邮件质量。关注ip黑名单情况,必要时联系服务器运营商更换ip。本文总结了邮件服务器搭建过程与优化建议,欢迎提供反馈和咨询。

阅读剩余
THE END