How to Change the Hostname on Linux

On Linux, you can change the hostname by using the hostnamectl command.

How to Set the Hostname on Linux

sudo hostnamectl set-hostname <new-hostname>
Code language: Bash (bash)

For example:

sudo hostnamectl set-hostname server1
Code language: JavaScript (javascript)

At this point, you will need to logout and back in to see the changes have taken effect.

Tags:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments