How to Change Hostname in Linux
Introduction
Changing the hostname of your Linux server helps with identification and organization, especially in multi-server environments. This guide shows you how to change the hostname safely.
Step-by-step Guide
- Check the current hostname
- hostname
- Set the new hostname (temporary, until reboot)
- sudo hostnamectl set-hostname new-hostnamen
- (Replace
new-hostnamewith your desired hostname)
- (Replace
- sudo hostnamectl set-hostname new-hostnamen
- Edit the /etc/hosts file to update the hostname
- sudo nano /etc/hostsn
- Find the line with
127.0.1.1and replace the old hostname with the new one:
- Find the line with
- 127.0.1.1 new-hostname
- sudo nano /etc/hostsn
- (Optional) Edit /etc/hostname for older systems
- sudo nano /etc/hostnamen
- Replace the old hostname with the new one and save.
- sudo nano /etc/hostnamen
- Reboot the server to apply all changes
- sudo reboot
- Verify the new hostname after reboot
- hostname
Recommendations
- Use descriptive hostnames for easier server management.
- Update DNS records if your hostname is used in your network.
- Always double-check
/etc/hoststo avoid SSH or mail issues.
Call To Action
eed reliable Linux hosting for your projects? Check out our VPS plans! https://xernode.com/#pricing