This article provides a step-by-step guide to setting up a mail server on Ubuntu VPS with iRedMail.
Guide to Setting Up a Mail Server on Ubuntu VPS with iRedMail
Setting up a mail server can seem complex, but with the help of iRedMail, the process becomes significantly streamlined. iRedMail is an open-source mail server solution that simplifies the configuration and maintenance of email services. This guide walks you through the process of setting up a mail server on an Ubuntu VPS.
Pre-requisites
Before starting, ensure the following:
- Ubuntu VPS: A server with a clean installation of Ubuntu (20.04 or later is recommended).
- Root Access: You need root or sudo privileges.
- Domain Name: A fully qualified domain name (FQDN) for your mail server (e.g.,
mail.example.com
). - DNS Configuration: Ensure you can manage DNS records for your domain.
Once you have collected the above requirements, it’s time to begin building mail server on Ubuntu VPS with iRedMail.
Setting Up a Mail Server on Ubuntu VPS with iRedMail
To setup a mail server on Ubuntu VPS with iRedMail, follow the steps provided.
-
Update and Upgrade the System
- SSH into your VPS:
ssh root@your-server-ip
- Update the package list and upgrade all packages:
apt update && apt upgrade -y
This ensures your system is up-to-date with the latest security patches.
- SSH into your VPS:
-
Set a Fully Qualified Domain Name (FQDN)
- Set the hostname of your server:
hostnamectl set-hostname mail.example.com
Replace
mail.example.com
with your domain’s subdomain for mail services. - Verify the hostname:
hostname -f
- Add the hostname to your
/etc/hosts
file:nano /etc/hosts
Add the following line, replacing the placeholders with your server’s IP and domain:
127.0.0.1 localhost your-server-ip mail.example.com mail
- Set the hostname of your server:
-
Configure DNS Records
Set up the necessary DNS records for your domain:
- A Record: Point
mail.example.com
to your VPS IP address. - MX Record: Set the mail server for your domain:
example.com MX 10 mail.example.com
- SPF Record: Add an SPF record to authorize your server to send emails:
example.com TXT "v=spf1 mx ~all"
- DKIM and DMARC: These will be configured later by iRedMail.
- A Record: Point
-
Install iRedMail
- Download the latest version of iRedMail:
wget https://github.com/iredmail/iRedMail/archive/refs/tags/1.7.2.tar.gz
Replace
1.7.2
with the latest version number. - Extract the downloaded archive:
tar -xvf 1.7.2.tar.gz cd iRedMail-1.7.2/
- Start the iRedMail installer:
bash iRedMail.sh
- Download the latest version of iRedMail:
-
Configure iRedMail During Installation
The installer will guide you through the setup process. Key steps include:
- Choose Installation Directory: Default is
/var/vmail
. You can accept this. - Select Web Server: Choose either
Nginx
orApache
. - Choose Backend Storage: Options include
OpenLDAP
,MySQL/MariaDB
, orPostgreSQL
. For small setups, MariaDB is recommended. - Domain and Administrator Email: Enter your domain (e.g.,
example.com
) and set an administrator email (e.g.,admin@example.com
). - Confirm Configuration: Review the options and confirm to proceed.
- Choose Installation Directory: Default is
-
Complete the Installation
- Once the installation finishes, note the summary output. It includes important details such as admin credentials and locations of configuration files.
- Reboot your server to apply changes:
reboot
-
Access the Web Interface
- Open your browser and navigate to:
https://mail.example.com/iredadmin
- Log in with the admin email and password configured during installation.
- Open your browser and navigate to:
-
Configure DKIM and DMARC
- DKIM Keys:
- Locate the generated DKIM key:
bash
cat /var/lib/dkim/example.com.pem - Add a TXT record in your DNS for
default._domainkey.example.com
with the DKIM key.
- Locate the generated DKIM key:
- DMARC Record:
Add a TXT record to your DNS:_dmarc.example.com TXT "v=DMARC1; p=quarantine; rua=mailto:postmaster@example.com"
- DKIM Keys:
-
Test Mail Functionality
- Send a test email using a mail client (e.g., Thunderbird or Outlook).
- Check DNS configurations using online tools like MXToolbox.
-
Secure Your Mail Server
- Enable Firewall:
ufw allow 25,80,443,465,587,993,995/tcp ufw enable
- Install Fail2Ban:
Protect your server from brute-force attacks:apt install fail2ban
- Enable SSL/TLS:
Ensure that SSL is enabled for all mail services. By default, iRedMail installs a self-signed certificate. Replace it with a Let’s Encrypt certificate if desired.
- Enable Firewall:
-
Maintain Your Server
- Regularly check logs for errors:
tail -f /var/log/mail.log
- Apply security updates frequently:
apt update && apt upgrade -y
- Regularly check logs for errors:
Conclusion and Takeaways
This guide provides a comprehensive overview of setting up a mail server using iRedMail on an Ubuntu VPS. With these steps, your server will be configured to send and receive emails securely and reliably.