Setting hostname in CentOS 7 and RHEL7

less than 1 minute read

Setting the hostname in CentOS 6 used to done with:

$ hostname

This would only set the hostname until server restart though. To get the hostname to stick, the file: /etc/sysconfig/network would need to be edited. The line HOSTNAME= needs to be updated from (localhost.localdomain is the default value):



In CentOS 7 everything is done with the command line command hostnamectl.

For a temporary setting of the hostname

hostnamectl set-hostname

And to make it stick, use the flag --static:

hostnamectl set-hostname --static

Leave a Comment