How to set Permanent or Static hostname for CentOs7 Minimal Server.

Introduction

A hostname is a unique name assigned to a server or computer that helps identify it on a network. In CentOS 7, you can temporarily change the hostname using the hostname command, but the change will be lost after a reboot. To ensure the hostname remains unchanged even after restarting the server, you must configure a permanent (static) hostname.

This guide explains how to set a permanent hostname on a CentOS 7 Minimal Server, whether it is installed on a physical machine, VPS, or virtual machine.

Prerequisites

Before proceeding, ensure you have:

  • A CentOS 7 Minimal Server installed
  • Root or sudo access to the server
  • A desired hostname (for example: abc.abc.com)

Change Hostname Temporarily

You can change the hostname temporarily using the following command:

hostname abc.abc.com

Verify the current hostname:

hostnamectl

Sample Output

Static hostname: localhost.localdomain
Transient hostname: abc.abc.com

The Transient hostname reflects the temporary change. However, after a server reboot, the hostname will revert to its previous value.

Set a Permanent Hostname in CentOS 7

To configure a hostname that persists across reboots, use the hostnamectl command:

hostnamectl set-hostname abc.abc.com

Verify the change:

hostnamectl

Sample Output

Static hostname: abc.abc.com
Icon name: computer-vm
Chassis: vm
Machine ID: 31ff204cc76641e99460750cef4d0e0e
Boot ID: 9992b7511b4942c29ea48a0aada0294c
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
Kernel: Linux 3.10.0-514.el7.x86_64
Architecture: x86-64

The hostname is now stored as the Static hostname and will remain unchanged after system reboots.

Verify Hostname Configuration

You can confirm the hostname at any time using:

hostnamectl status

or

hostname

Both commands should display the newly configured hostname.

Conclusion

Setting a permanent hostname in CentOS 7 is a simple but important system administration task. While the hostname command only changes the hostname temporarily, the hostnamectl set-hostname command ensures the hostname persists after reboots. Using a properly configured hostname improves server identification, network management, monitoring, and troubleshooting.

Frequently Asked Questions (FAQ)

1. What is the difference between a static hostname and a transient hostname?

A static hostname is permanently stored on the system and survives reboots. A transient hostname is temporary and may be assigned by DHCP or changed manually until the system restarts.

2. Do I need to reboot the server after changing the hostname?

No. The hostname change takes effect immediately when using:

hostnamectl set-hostname <hostname>

3. How can I check the current hostname on CentOS 7?

Use either of the following commands:

hostname

or

hostnamectl

Both commands display the current hostname configuration.

Talk to our experts

Looking for the right technology solution for your business? Our team of experts can help you with development, cloud, DevOps, design, and a wide range of other technology needs. Get in touch with our team here.

admin

Writes about Web & Architecture at Pheonix Solutions.

Leave a Reply

Scroll to Top