Change Mail Server Hostname

Change Mail Server Hostname (Master Domain)

At some point of time, your mail server hostname (master domain) which provides the MX DNS records to other domains might be expired or you don’t want to renew it, so what to do? don’t worry, we can change it easily in few minuets.

We will change the current hostname and add new hostname to the server. In our case, we will add new domain. It’s better not to use one of the mail domains that are already installed on your server because you will need to change DNS records for that domain and if your email which uses that domain is busy with sending/receiving, the service will stop (during the DNS propagation and setup). It’s better that the new hostname is an old domain name without any blocking specially to avoid being blocked by other email servers. New domains don’t perform well.

To change your mail server hostname, apply the following steps:

  1. Add your new email domain to the current iRedAdmin panel by copying the following link and pasting it on your browser address bar.

Login to iRedAdmin using your old hostname domain postmaster email address which is:

DNS Settings

2. Create Address record (to be used in TLS certificate generation) and MX record for your new hostname master domain in your registrar DNS settings panel.

DNS Record TypeHostContent, Value or the AnswerTTL (Time To Live)
A Recordmail166.91.72.551 min (or the minimum allowed)

Important Note: the address record is a must to generate the TLS certificate for the new hostname. Add it to your DNS settings as early as possible so the propagation will take effect before you request the TLS certificate.

DNS Record TypeHostContent, Value or the AnswerPriorityTTL (Time To Live)
MX Record@mail.motionaura.com01 min (or the minimum allowed)

We already explained this previously here: DNS Settings article (parts: Add A Record and Add MX Record).

3. [no need now] Configure DNS Settings on server’s side by following the steps here: DNS Settings article (Configure DNS Settings on Server’s Side part) — no need for this step because we edit the files related to the hostname.

4. Improve the new domain deliverability by applying the steps here: Improve Email Deliverability article for the new domain.

5. Don’t forget to replace the rDNS record on your VPS panel with the new hostname (

TLS Configuration

6. Request TLS certificate by running the following command on PuTTY SSH client or any Linux terminal. Note that you need to replace the email address and the domain in bold with your own email address and your domain in case you didn’t add your inputs on the golden box on top. Make sure the A record for the new hostname ( has propagated properly.

root@mail:~# certbot certonly --webroot --agree-tos --email -d -w /var/www/html/

Backup all the files that need to be changed

7. The files that we need to change are listed below. You don’t need any extra file to make this happen. We already tested them on Ubuntu 20.04 LTS and 22.04 LTS and the hostname got changed perfectly without any problem.

  • /etc/hosts
  • /etc/hostname
  • /etc/mailname
  • /etc/postfix/
  • /etc/dovecot/dovecot.conf
  • /etc/amavis/conf.d/50-user

In order to run a copy for each one, follow the commands below:

Hosts file:

root@mail:~# cp /etc/hosts /etc/hosts.backup

Hostname file:

root@mail:~# cp /etc/hostname /etc/hostname.backup

Mailname file:

root@mail:~# cp /etc/mailname/etc /mailname.backup

Postfix file:

root@mail:~# cp /etc/postfix/ /etc/postfix/

Dovecot file:

root@mail:~# cp /etc/dovecot/dovecot.conf /etc/dovecot/dovecot.conf.backup

Amavis file:

root@mail:~# cp /etc/amavis/conf.d/50-user /etc/amavis/conf.d/50-user.backup

Also, you can perform a full-text search in all the files in the /etc/ directory to find more files under the old domain by running the following command. In case you find extra files, you should replace the old domain in those files with the new domain.

root@mail:~# grep -Fr "" /etc/

[Optional] Nginx Virtual Hosts for the New Mail Server Hostname (you can skip this)

8. [NOT NEEDED] If you want to login to Roundcube using the new hostname domain (like:, you need to configure the virtual hosts of the new domain by applying the steps here: Add Extra Email Domain article (Configure Virtual Hosts part). If you want to login to Roundcube using the old hostname, you don’t need do the below.

You will need also to change the hostname in the nginx template file by running the command. Note that once you change the hostname in the ssl.tmpl file, the SSL certificate will be added to the new host domain name:, you don’t need to configure sites-available or sites-enabled.

root@mail:~# nano /etc/nginx/templates/ssl.tmpl

And change the below so when you login to Roundcube from the new hostname, you will not have SSL certificate issues.

ssl_certificate /etc/letsencrypt/live/; 
ssl_certificate_key /etc/letsencrypt/live/;

Now, try to login to your new hostname domain, you will be able to see the SSL added without configuring virtual hosts. Just make sure that it has an A record added.

9. In case some of your email domains use the MX record of the old hostname, you need to change the DNS record for them in the DNS registrar panel to the new MX record of the new hostname. For example, your MX record should look like below in the domain DNS settings.

@    MX

10. We are not sure that rebooting is important for the change to take effect. We recommend rebooting Postfix, Dovecot and Amavis but you can reboot all of them to guarantee that the change took effect.

root@mail:~# service postfix reboot
root@mail:~# service dovecot reboot
root@mail:~# service amavis reboot