How to correctly change the hostname on CentOS 6 & 7 servers Print

  • 1

Struggling to correctly change the hostname of your CentOS server? Not to worry, these simple steps will get you on track in no time at all. Firstly, let's log in to your server via console or SSH. Assuming you're ready:

1. Use the hostname utility
hostname myservernamehere
or, use a fully qualified hostname like
hostname server.domain.tld

2. Alter the hostname in /etc/sysconfig/network
nano /etc/sysconfig/network
Change your old hostname by editing the text on the line after HOSTNAME=


3. Alter the hostname in /etc/hosts
nano /etc/hosts
If your old hostname is present here, edit it out and replace it with your new one.


4. Don't forget rDNS / Reverse DNS / PTR !

Ask your web host (that's probably us) to alter your PTR/rDNS record to the fully qualified domain name you changed your hostname to. If you did not use a fully qualified domain name and it is not resolvable in DNS, you will not be able to complete this step, and you may experience difficulties when sending or receiving e-mail to/from your server.

Was this answer helpful?

« Back