如何在 Ubuntu 环境下搭建邮件服务器

如何在 Ubuntu 环境下搭建邮件服务器,第1张

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接收,别名文件需要按如下所述进行修改。

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu) //stmp banned(用于telnet操作修改)

biff = no

append_dot_mydomain = no

#delay_warning_time = 4h

readme_directory = no

mail_spool_directory = /var/mail

home_mailbox = .Mail///本机每登录linux用户邮件文件夹位置

virtual_alias_maps = hash:/etc/postfix/virtual

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

#两项自启用tls发邮件选项(要邮箱支持)

smtpd_tls_security_level = may

smtp_tls_security_level = may

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination

myhostname = (邮件服务器主机名需要/etc/hostname修改应服务域名再填写)

alias_maps = hash:/etc/aliases

alias_database = hash:/etc/aliases

myorigin = /etc/mailname

mydestination = (填写应服务器域名)

#mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 //允许连接主机设置

mailbox_size_limit = 0 //限制邮件附件设置

recipient_delimiter = +

inet_interfaces = all

inet_protocols = all


欢迎分享,转载请注明来源:夏雨云

原文地址:https://www.xiayuyun.com/zonghe/504827.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-06-17
下一篇2023-06-17

发表评论

登录后才能评论

评论列表(0条)

    保存