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.


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

  1. Add your new domain to iRedAdmin panel by copying the following link and pasting it on your browser address bar.
https://mail.new-domain.com/iredadmin

DNS Settings

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

3. Configure DNS Settings on server’s side by following the steps here: DNS Settings article (Configure DNS Settings on Server’s Side part).

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.

TLS Configuration

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 postmaster@new-domain.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.

  • /etc/hosts
  • /etc/hostname
  • /etc/postfix/main.cf
  • /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

Postfix file:

root@mail:~# cp /etc/postfix/main.cf /etc/postfix/main.cf

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 "old-domain.com" /etc/

Nginx Virtual Hosts for the New Mail Server Hostname

7. Configure the virtual hosts of the new domain by applying the steps here: Add Extra Email Domain article (Configure Virtual Hosts part).

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.

Leave a Comment

Your email address will not be published.