How to change hostname on Linux

Answered
Jan 05, 2026 79 views 1 answers
21

I need to change my server hostname. What is the correct way to do this on modern Linux systems?

D
Asked by db_admin
Silver 415 rep

1 Answer

29

Change hostname

# View current hostname
hostname
hostnamectl

# Change hostname (systemd)
sudo hostnamectl set-hostname new-hostname

# Edit hosts file
sudo nano /etc/hosts
# Change: 127.0.1.1 old-hostname
# To: 127.0.1.1 new-hostname

Verify change

# Check hostname
hostname
hostnamectl status

# Reboot for full effect (optional)
sudo reboot
O
Answered by omar_linux 1 week, 2 days ago
Platinum 593 rep

Your Answer

You need to be logged in to answer questions.

Log In to Answer

Related Questions

Hot Questions

No hot questions available.