Home Operation and Maintenance Linux Operation and Maintenance Mail server configuration guide in Linux system

Mail server configuration guide in Linux system

Jun 18, 2023 am 10:16 AM
linux Mail Server Configuration Guide

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use docker desktop How to use docker desktop Apr 15, 2025 am 11:45 AM

How to use Docker Desktop? Docker Desktop is a tool for running Docker containers on local machines. The steps to use include: 1. Install Docker Desktop; 2. Start Docker Desktop; 3. Create Docker image (using Dockerfile); 4. Build Docker image (using docker build); 5. Run Docker container (using docker run).

How to view the docker process How to view the docker process Apr 15, 2025 am 11:48 AM

Docker process viewing method: 1. Docker CLI command: docker ps; 2. Systemd CLI command: systemctl status docker; 3. Docker Compose CLI command: docker-compose ps; 4. Process Explorer (Windows); 5. /proc directory (Linux).

What to do if the docker image fails What to do if the docker image fails Apr 15, 2025 am 11:21 AM

Troubleshooting steps for failed Docker image build: Check Dockerfile syntax and dependency version. Check if the build context contains the required source code and dependencies. View the build log for error details. Use the --target option to build a hierarchical phase to identify failure points. Make sure to use the latest version of Docker engine. Build the image with --t [image-name]:debug mode to debug the problem. Check disk space and make sure it is sufficient. Disable SELinux to prevent interference with the build process. Ask community platforms for help, provide Dockerfiles and build log descriptions for more specific suggestions.

What computer configuration is required for vscode What computer configuration is required for vscode Apr 15, 2025 pm 09:48 PM

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

vscode cannot install extension vscode cannot install extension Apr 15, 2025 pm 07:18 PM

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.

Can vscode be used for mac Can vscode be used for mac Apr 15, 2025 pm 07:36 PM

VS Code is available on Mac. It has powerful extensions, Git integration, terminal and debugger, and also offers a wealth of setup options. However, for particularly large projects or highly professional development, VS Code may have performance or functional limitations.

What is vscode What is vscode for? What is vscode What is vscode for? Apr 15, 2025 pm 06:45 PM

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages ​​and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

How to back up vscode settings and extensions How to back up vscode settings and extensions Apr 15, 2025 pm 05:18 PM

How to back up VS Code configurations and extensions? Manually backup the settings file: Copy the key JSON files (settings.json, keybindings.json, extensions.json) to a safe location. Take advantage of VS Code synchronization: enable synchronization with your GitHub account to automatically back up all relevant settings and extensions. Use third-party tools: Back up configurations with reliable tools and provide richer features such as version control and incremental backups.

See all articles