Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing a hostname permanently in Ubuntu

I want to create a shell script that can change the hostname of my Ubuntu permanently. Whenever I use the hostname New_hostname command, it returns to the original hostname after I restart the machine.

I found out that the only way I can change this permanently is by modifying the file in /etc/hostname and save it. Is there some way I can do this using a shell script only? I also have a password.

like image 297
user1548960 Avatar asked Jan 18 '14 10:01

user1548960


Video Answer


1 Answers

The hostnamectl combines setting the hostname via the hostname command and editing /etc/hostname. Unfortunately, editing /etc/hosts still has to be done separately.

hostnamectl set-hostname <new-hostname>
like image 50
Fizer Khan Avatar answered Oct 13 '22 17:10

Fizer Khan