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.
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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
