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 Spamhaus.org to avoid being blocked by other email servers. New domains don’t perform well.
To change your mail server hostname, apply the following steps:
- 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: email@example.com
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 Type||Host||Content, Value or the Answer||TTL (Time To Live)|
|A Record||1 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 Type||Host||Content, Value or the Answer||Priority||TTL (Time To Live)|
|MX Record||@||0||1 min (or the minimum allowed)|
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 (mail.motionaura.com).
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 (mail.motionaura.com) has propagated properly.
root@mail:~# certbot certonly --webroot --agree-tos --email firstname.lastname@example.org -d mail.motionaura -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.
In order to run a copy for each one, follow the commands below:
root@mail:~# cp /etc/hosts /etc/hosts.backup
root@mail:~# cp /etc/hostname /etc/hostname.backup
root@mail:~# cp /etc/mailname/etc /mailname.backup
root@mail:~# cp /etc/postfix/main.cf /etc/postfix/main.cf.backup
root@mail:~# cp /etc/dovecot/dovecot.conf /etc/dovecot/dovecot.conf.backup
root@mail:~# cp /etc/amavis/conf.d/50-user /etc/amavis/conf.d/50-user.backup
Perform Full-Text Search (not needed)
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 "vpsprof.com" /etc/
[Optional] Nginx Virtual Hosts for the New Mail Server Hostname (you can skip this)
8. If you want to login to Roundcube using the new hostname domain (like: mail.motionaura.com), 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:
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/mail.vpsprof.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/mail.vpsprof.com/privkey.pem;
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 mail.motionaura.com.
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