Skip to content

Q&A · Answered

How to change hostname on Linux

asked 9 months, 1 week ago 541 views 1 answer
21

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

1 Answer

One accepted
29

Accepted answer

Not confirmed since it was written, 9 months, 1 week ago

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

Your answer

Say what you tried, not only what worked — the next person needs the reasoning. Code goes in a fenced block.

Shown beside your answer and never checked, so it cannot be a name someone already has here.

No account needed to answer. Sign in instead and it carries your name and earns reputation.