We would like to set up a Postfix mail server on a UBUNTU VPS, but we are not entirely sure if it will work. Setting up a Postfix mail server on a VPS with Ubuntu, especially when it comes to someone with no experience or a novice specialist, is a process that is notoriously difficult. However, if you follow the instructions carefully and successfully complete all the necessary steps, you are guaranteed to be able to successfully deploy your own server. Below, we offer a more detailed look at each stage of this configuration process.
Server preparation
First of all, you must select a VPS hosting service and install Ubuntu. You can choose from VPS hosting services such as DigitalOcean, Linode, or Hetzner. Next, it is important to install the latest version of Ubuntu LTS. After that, you need to configure the basic environment:
- Using SSH, connect to the server. To do this, use
ssh user@your-server-ip
- Then be sure to update the system itself. Use the following code for this:
sudo apt update && sudo apt upgrade -y
- The final stage of setting up the base environment is installing the basic tools using a combination of
sudo apt install wget curl ufw -y
Installing Postfix
The next step is to install Postfix using a combination of
sudo apt install postfix -y
During installation, don’t forget to review the settings. To do this, first select the “Internet Site” type, and then enter your server domain.
Configuring DNS records
At this stage, you need to visit the domain’s DNS control panel and add the following important records:
- MX record
|
|
|
|
MX | @ | mail.example.com. | 10 |
- SPF record, namely
v=spf1 mx ~all
- DKIM. To do this, you must install OpenDKIM.
sudo apt install opendkim opendkim-tools -y
Don’t forget about the DKIM settings in Postfix. Don’t ignore the need to generate keys. Then add them to DNS.
- And last but not least – the DMARC record. Use
v=DMARC1; p=none; rua=mailto:dmarc@example.com
Postfix configuration is another important step in the setup process.
First, you need to edit the main configuration file. To do this, use the following combination
sudo nano /etc/postfix/main.cf
Don’t forget about such important parameters as:
myhostname = mail.example.com
mydomain = example.com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = ipv4
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
relayhost=
mynelworks = 127.0.0.0/8
home_mailbox = Maildir/
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.kev
smtpd_use _tls=yes
After configuration, you need to restart the Postfix you configured earlier. To do this, perform the following action:
sudo systemctl restart postfix
What other steps need to be taken when setting up your own Postfix mail server on UBUNTU VPS?
The next important step is the optional installation of Dovecot.
sudo apt install dovecot-core dovecot-imapd dovecot-pop3d -y
After installation, configure Dovecot. To do this, edit the /etc/dovecot/dovecot.conf file to enable IMAP and POP3.
protocols = imap pop3
After completing these steps, restart Dovecot using
sudo systemctl restart dovecot
Next, you must test the server and check that you can receive mail via a web client or email client. In addition to all this, you also need to take care of protecting the mail server. To start with, you should configure the UFW firewall. Open the necessary ports using:
sudo ufw allow 25,587,993,995/tcp
sudo ufw enable
Then it is important to install anti-spam and anti-virus software: SpamAssassin
sudo apt install spamassassin -y
and ClamAV
sudo apt install clamav -y
Be sure to activate all necessary services.
The final step in setting up your own mail server is support with monitoring. For effective monitoring, use the following logs
sudo tail -f /var/log/mail.log
Be sure to remember to update the server regularly using
sudo apt update && sudo apt upgrade -y
Conclusions
Thanks to these fairly simple steps, you can not only set up but also maintain your own Postfix-based mail server at any time. If you have any questions or need help with setup, please contact us. We will be happy to help you resolve any issues. We have many years of experience in this field, so we guarantee high-quality work.