Mail server configuration guide in Linux system

WBOY
Release: 2023-06-18 10:16:42
Original
5720 people have browsed it

Linux system is a very common operating system. It has many advantages, including high security, strong reliability, open source freedom and many other advantages. For some industries that require email transmission, configuring a mail server is essential. This article will introduce in detail the configuration steps of the mail server in the Linux system for the convenience of readers.

Step 1: Install the necessary software

Before starting to configure the mail server, we need to install some necessary software, including mail server software and mail transfer agent (MTA) software. Commonly used mail server software includes Postfix, Sendmail, and Qmail, while commonly used MTA software includes Courier, Dovecot, etc. The following uses Postfix and Dovecot as examples to explain.

  • Install Postfix

On CentOS system, you can install Postfix through the following command:

yum install postfix
Copy after login

On Ubuntu system, you can use the following command to install Install Postfix:

apt-get install postfix
Copy after login
  • Install Dovecot

On CentOS system, you can install Dovecot through the following command:

yum install dovecot
Copy after login

On Ubuntu system, you can Install Dovecot through the following command:

apt-get install dovecot-core dovecot-imapd dovecot-pop3d
Copy after login

Step 2: Configure host name and domain name resolution

Before configuring the mail server, you need to configure the correct host name and domain name resolution. On the CentOS system, you can modify the host name through the following command:

hostnamectl set-hostname mail.example.com
Copy after login
Copy after login

On the Ubuntu system, you can modify the host name through the following command:

hostnamectl set-hostname mail.example.com
Copy after login
Copy after login

After modifying the host name, you also need Binding the host name and IP address can be achieved by modifying the /etc/hosts file. For example:

192.168.10.100 mail.example.com mail
Copy after login

Then, you also need to configure the correct domain name resolution, which can be achieved by modifying the DNS or hosts file. For example:

192.168.10.100 example.com
Copy after login

Step 3: Edit the Postfix main configuration file

1. Modify the main.cf file

Configure the Postfix main configuration file (main.cf) to configure email One of the keys to the server. You can edit the main.cf file through the following command:

vi /etc/postfix/main.cf
Copy after login

Before editing the main.cf file, it is recommended to back up the original file. Then, you can set the following parameters:

# 设置邮件服务器的域名
myhostname = mail.example.com

# 邮件服务器的IP地址
inet_interfaces = all

# 允许从本地网络中的其它邮件服务器转发邮件
mynetworks = 192.168.10.0/24

# 允许外部邮件服务器向本邮件服务器发送邮件
smtpd_recipient_restrictions = permit_mynetworks, reject_unauth_destination

# 设置发件人显示的名称
smtpd_sender_login_maps = hash:/etc/postfix/sender_login_maps

# 设置接收邮件的本地目录
home_mailbox = Maildir/
Copy after login

2. Configure the sender_login_maps file

Setting the name displayed by the sender is achieved by configuring the sender_login_maps file. Add the following content to the /etc/postfix/sender_login_maps file:

user@domain.com    name
Copy after login

Step 4: Configure Dovecot

Before configuring Dovecot, you need to delete the original Dovecot configuration file. The original file can be deleted through the following command:

rm -rf /etc/dovecot/*
Copy after login

1. Modify the dovecot.conf file

The dovecot.conf file can be edited through the following command:

vi /etc/dovecot/dovecot.conf
Copy after login

After editing dovecot Before creating the .conf file, it is recommended to back up the original file. Then, you can set the following parameters:

# 启用Dovecot服务
protocols = imap pop3 lmtp

# 邮件存储方式
mail_location = maildir:~/Maildir

# 邮件收发日志路径
log_path = /var/log/dovecot.log

# 收发SSL连接日志路径
ssl_log_path = /var/log/dovecot-ssl.log

# IMAP邮件下载时的缓存大小
mail_max_userip_connections = 100

# POP3邮件下载时的缓存大小
mail_max_userip_connections = 100

# 收发邮件时的超时时间
login_greeting_timeout = 30s

# 超过多长时间没有收到SMTP响应就断开连接
smtp_quit_timeout = 60s

# 超过多长时间没有收到IMAP响应就断开连接
imap_client_workarounds = delay-newmail

# 超过多长时间没有收到POP3响应就断开连接
pop3_client_workarounds = delay-newmail
Copy after login

2. Configure the 10-auth.conf file

Add the following content in the /etc/dovecot/conf.d/10-auth.conf file:

disable_plaintext_auth = no
auth_mechanisms = plain login
Copy after login

3. Configure the 10-master.conf file

Comment out the following content in the /etc/dovecot/conf.d/10-master.conf file:

#unix_listener /var/spool/postfix/private/auth {
#  mode = 0666
#}
Copy after login

Then, add the following content to the 10-master.conf file:

service auth {
  unix_listener auth-userdb {
      mode = 0600
      user = postfix
      group = postfix
  }
  user = dovecot
}
Copy after login

Step 5: Set up firewall rules

After configuring the mail server, you also need to set up firewall rules to protect mail Server security. You can set firewall rules through the following command:

# CentOS系统
iptables -I INPUT -p tcp --dport 25 -j ACCEPT
iptables -I INPUT -p tcp --dport 110 -j ACCEPT
iptables -I INPUT -p tcp --dport 143 -j ACCEPT

# Ubuntu系统
ufw allow 25/tcp
ufw allow 110/tcp
ufw allow 143/tcp
Copy after login

In summary, this article details the configuration steps of the mail server in the Linux system. Through the guidance of this article, readers can easily configure a powerful, safe and reliable mail server to meet the needs of mail transmission.

The above is the detailed content of Mail server configuration guide in Linux system. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template