Processes for changing mailserver hostname
I have wrote in old post that hostname is very important to a mailserver.
Why hostname is so important in mail system
If you want to change hostname for mailserver, what processes should be taken? The follows are what I did.
change rDNS
You should change rDNS for your mailserver's IP, from old hostname to the new hostname.
/etc/hostname
Edit OS configuration file /etc/hostname to input the new hostname here, then run "hostname new_hostname" to activate it at once.
/etc/mailname
Edit OS configuration file /etc/mailname to input the new hostname here.
/etc/postfix/main.cf
Edit /etc/postfix/main.cf to update this line: myhostname = new_hostname.
/etc/opendmarc.conf
edit /etc/opendmarc.conf to update this line: "TrustedAuthservIDs new_hostname". Otherwise DKIM signed by new hostname will not be trusted by opendmarc, and you will see this info in logs:
May 21 08:06:11 mxin opendmarc[552889]: C5E826A116 ignoring Authentication-Results at 0 from new_hostname
That's bad!
create certificates for new hostname
The next, create certificates with certbot for new hostname. The new certificates will be used by either postfix or dovecot.
You could reference my old post below.
install postfix dovecot squirrelmail letsencrypt on ubuntu
edit /etc/postfix/main.cf to update certificates
edit main.cf for postfix to update the following two lines:
smtpd_tls_cert_file = /etc/letsencrypt/live/new_hostname/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/new_hostname/privkey.pem
edit /etc/dovecot/conf.d/10-ssl.conf to update certificates
edit 10-ssl.conf for dovecot to update the following two lines:
ssl_cert = </etc/letsencrypt/live/new_hostname/fullchain.pem
ssl_key = </etc/letsencrypt/live/new_hostname/privkey.pem
update hostnames for webmail
Now matter what webmail system (roundcube, squirrel, snappy) you are using, you have to setup SMTP and IMAP hostnames for it. So you have to change hostnames in webmail backend to the new value.
update MX records
Update MX records to include new hostname, and delete the old one.
restart all mailserver services
The last, restart all related services.
$ sudo systemctl restart postfix dovecot opendkim opendmarc
And you may also want to update documentation to let your users know it.
As you see, changing hostname for mailserver is quite complicated. You should be much careful in doing that.