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.
To change your mail server hostname, apply the following steps:
- Add your new domain to iRedAdmin panel by copying the following link and pasting it on your browser address bar.
2. Create MX record and Address record for your new master domain in your registrar DNS settings panel. We explained this previously here: DNS Settings article (parts: Add A Record and Add MX Record).
4. Improve the new domain deliverability by applying the steps here: Improve Email Deliverability article for the new domain. Don’t forget to replace the rDNS record on your VPS panel with the new domain.
5. 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 red with your own email address and your domain in case you didn’t add your inputs on the golden box on top.
root@mail:~# certbot certonly --webroot --agree-tos --email email@example.com -d mail.new-domain.com -w /var/www/html/
Replace the Old Domain
6. Replace the old domain with the new domain in the below files but it’s better to make a copy first for all of them.
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/postfix/main.cf /etc/postfix/main.cf
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
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 "old-domain.com" /etc/
Nginx Virtual Hosts for the New Mail Server Hostname
8. 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.new-domain.com.