ubuntu

ubuntu邮件服务器虚拟域名

小樊
45
2025-10-21 05:53:18
栏目: 云计算

Configuring Virtual Domains on an Ubuntu Mail Server with Postfix and Dovecot
Virtual domains allow a single mail server to host email addresses for multiple domains (e.g., user1@example.com, user2@test.com). Below is a step-by-step guide to setting up virtual domains using Postfix (MTA) and Dovecot (IMAP/SMTP server) on Ubuntu.

1. Prerequisites

Before starting, ensure your server has:

2. Install Postfix and Dovecot

Install the core mail server packages:

sudo apt update
sudo apt install postfix dovecot-core dovecot-imapd dovecot-lmtpd

During Postfix installation, select “Internet Site” as the configuration type and enter your domain name (e.g., example.com) when prompted.

3. Configure Postfix for Virtual Domains

Postfix needs to be set up to handle multiple domains. Edit the main configuration file:

sudo nano /etc/postfix/main.cf

Modify or add the following parameters (replace example.com with your primary domain):

myhostname = mail.example.com       # Server hostname (FQDN)
mydomain = example.com              # Primary domain
myorigin = $mydomain                # Default domain for outgoing emails
inet_interfaces = all               # Listen on all network interfaces
inet_protocols = ipv4               # Use IPv4 (or "all" for IPv6 support)
mydestination = $myhostname, localhost.$mydomain, localhost  # Local domains
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128  # Trusted networks
home_mailbox = Maildir/             # Mail storage format (Maildir)
virtual_alias_domains = example.com, test.com  # List of virtual domains
virtual_alias_maps = hash:/etc/postfix/virtual  # Mapping file for virtual aliases

Create Virtual Alias Mappings

Define how virtual addresses map to local users. Create/edit the virtual alias file:

sudo nano /etc/postfix/virtual

Add one line per virtual address (replace user1/user2 with local system users):

user1@example.com user1
user2@example.com user2
user3@test.com user2  # Map multiple virtual addresses to one local user

Convert the file to a Postfix-readable hash database:

sudo postmap /etc/postfix/virtual

Restart Postfix

Apply changes and restart the service:

sudo systemctl restart postfix

4. Configure Dovecot for Virtual Domains

Dovecot needs to support virtual users and mail storage. Edit the main configuration file:

sudo nano /etc/dovecot/dovecot.conf

Ensure the following lines are present (enable IMAP/LMTP protocols and set mail location):

protocols = imap lmtp
mail_location = maildir:~/Maildir  # Matches Postfix's home_mailbox setting

Configure Authentication

Edit the authentication file to allow local users (or databases for larger setups):

sudo nano /etc/dovecot/conf.d/10-auth.conf

Modify these parameters:

disable_plaintext_auth = no         # Allow plaintext passwords (for testing; disable in production)
auth_mechanisms = plain login       # Supported authentication methods

Set Up LMTP for Mail Delivery

Configure Dovecot to receive mail from Postfix via LMTP. Edit the LMTP settings:

sudo nano /etc/dovecot/conf.d/10-master.conf

Add/uncomment the following block (adjust permissions for Postfix):

service lmtp {
  unix_listener /var/spool/postfix/private/dovecot-lmtp {
    mode = 0600
    user = postfix
    group = postfix
  }
}

Restart Dovecot

Apply changes and restart the service:

sudo systemctl restart dovecot

5. Configure DNS Records

For your virtual domains to work, add the following DNS records (via your domain registrar or DNS provider):

6. Test the Configuration

Verify your setup using command-line tools:

7. Optional: Enhance Security

By following these steps, your Ubuntu mail server will be able to host email addresses for multiple virtual domains, providing a scalable solution for small to medium-sized email hosting needs.

0
看了该问题的人还看了