How to change the hostname in CentOS 7

To change the hostname in CentOS 7, you have to do four things:

1. Modify /etc/sysconfig/network

2. Modify /etc/hosts

Find: localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

Add below that your IP address (a.b.c.d) and the new hostname:

a.b.c.d   hostname


Run this command: hostname

4. Persist the change using /etc/init.d/network restart




Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top