Server administration Setting Up a Mail Server from Scratch – Part 1: System Preparation

  • Thread starter D•Jass
  • Start date
  • Tags
    server
D•Jass

D•Jass

Staff member
Verified
  • #1

System Preparation​

This guide describes the basic setup.

1.1. System Update​

Keep your system up to date.
apt update && apt upgrade -y

1.2. Hostname and DNS Configuration​

Set the server’s full domain name (FQDN).
# Replace mail.example.com with your actual FQDN
hostnamectl set-hostname mail.example.com

Add an entry to /etc/hosts
echo "127.0.1.1 mail.example.com mail" >> /etc/hosts

Make sure the following are configured in your DNS zone:
A record for mail.example.com pointing to your server’s IP address.​
MX record for example.com pointing to mail.example.com (with the appropriate priority, usually 10).​
* A record for
Please, Login or Register to view URLs content!
if the web interface will be hosted there.​

(SPF, DKIM, and DMARC records are critically important and will be covered later, partially in the OpenDKIM section.)

1.3. Installing Required Packages​

Install all necessary components: Postfix (MTA), Dovecot (IMAP/POP3/LDA), MariaDB (database), Nginx+PHP (web interface), Certbot (SSL), OpenDKIM.
apt install -y postfix postfix-mysql dovecot-core dovecot-imapd dovecot-pop3d dovecot-lmtpd dovecot-mysql mariadb-server nginx php-fpm php-mysql php-mbstring php-zip php-xml php-gd php-intl php-json php-bcmath certbot python3-certbot-nginx opendkim opendkim-tools

1.4. Initial MariaDB Hardening​

Run the script to set the root password, remove anonymous users, etc.
mysql_secure_installation
Make sure to set a strong password for root@localhost!

1.5. Starting Core Services​

Enable and start the web server and the database.
systemctl enable --now nginx mariadb
 
Last edited by a moderator:
Top