Setting up a mail server on ubuntu vps with iredmailThis 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.

  1. Update and Upgrade the System

    1. SSH into your VPS:
      ssh root@your-server-ip
    2. 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.

  2. Set a Fully Qualified Domain Name (FQDN)

    1. Set the hostname of your server:
      hostnamectl set-hostname mail.example.com

      Replace mail.example.com with your domain’s subdomain for mail services.

    2. Verify the hostname:
      hostname -f
    3. 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
  3. Configure DNS Records

    Set up the necessary DNS records for your domain:

    1. A Record: Point mail.example.com to your VPS IP address.
    2. MX Record: Set the mail server for your domain:
      example.com MX 10 mail.example.com
    3. SPF Record: Add an SPF record to authorize your server to send emails:
      example.com TXT "v=spf1 mx ~all"
    4. DKIM and DMARC: These will be configured later by iRedMail.
  4. Install iRedMail

    1. 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.

    2. Extract the downloaded archive:
      tar -xvf 1.7.2.tar.gz cd iRedMail-1.7.2/
    3. Start the iRedMail installer:
      bash iRedMail.sh
  5. Configure iRedMail During Installation

    The installer will guide you through the setup process. Key steps include:

    1. Choose Installation Directory: Default is /var/vmail. You can accept this.
    2. Select Web Server: Choose either Nginx or Apache.
    3. Choose Backend Storage: Options include OpenLDAP, MySQL/MariaDB, or PostgreSQL. For small setups, MariaDB is recommended.
    4. Domain and Administrator Email: Enter your domain (e.g., example.com) and set an administrator email (e.g., admin@example.com).
    5. Confirm Configuration: Review the options and confirm to proceed.
  6. Complete the Installation

    1. Once the installation finishes, note the summary output. It includes important details such as admin credentials and locations of configuration files.
    2. Reboot your server to apply changes:
      reboot
  7. Access the Web Interface

    1. Open your browser and navigate to:
      https://mail.example.com/iredadmin
    2. Log in with the admin email and password configured during installation.
  8. Configure DKIM and DMARC

    1. 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.
    2. DMARC Record:
      Add a TXT record to your DNS:

      _dmarc.example.com TXT "v=DMARC1; p=quarantine; rua=mailto:postmaster@example.com"
  9. Test Mail Functionality

    1. Send a test email using a mail client (e.g., Thunderbird or Outlook).
    2. Check DNS configurations using online tools like MXToolbox.
  10. Secure Your Mail Server

    1. Enable Firewall:
      ufw allow 25,80,443,465,587,993,995/tcp ufw enable
    2. Install Fail2Ban:
      Protect your server from brute-force attacks:

      apt install fail2ban
    3. 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.
  11. Maintain Your Server

    1. Regularly check logs for errors:
      tail -f /var/log/mail.log
    2. Apply security updates frequently:
      apt update && apt upgrade -y

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.

Share this:
Avatar of editorial staff

Editorial Staff

Rad Web Hosting is a leading provider of web hosting, Cloud VPS, and Dedicated Servers in Dallas, TX.
lg