Some time ago I was advised that the best way to upgrade server OS that - install new server and migrate users with their mailboxes.

I need help.
How can I get another server with the same IP and hostname as the final result of migration. Should I create new server with other hostname and change hostname to the original after migration?