Operations 4 min read

How to Quickly Change the Hostname in CentOS: Step‑by‑Step Guide

This tutorial shows how to replace the default long CentOS hostname by editing /etc/hostname and /etc/hosts, verifying the changes, and rebooting the system so the new name takes effect.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
How to Quickly Change the Hostname in CentOS: Step‑by‑Step Guide

Some CentOS users find the default long hostname (localhost.localdomain) inconvenient and want to change it.

The hostname is stored in /etc/hostname. Open the file with vi /etc/hostname and replace the existing name with the desired one (e.g., slave2). Save and exit using :wq!. Verify the change with cat /etc/hostname.

Alternatively, edit /etc/hosts to map the machine’s IP to the new hostname. Add a line containing the IP address and the chosen hostname, then confirm with cat /etc/hosts.

After updating the files, restart the system with shutdown -r now so the new hostname takes effect.

Upon reboot, the hostname will reflect the new name.

For consistency, it is recommended to modify both /etc/hostname and /etc/hosts to avoid future confusion.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxtutorialCentOShostname
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.