Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

272
Views
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.

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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>
over 4 years ago · Santiago Trujillo Report

0

Type

echo "myNewHostName" > /etc/hostname

in any shell with root access near you..

You may also want to take a look at the file /etc/hosts, cf. http://pricklytech.wordpress.com/2013/04/24/ubuntu-change-hostname-permanently-using-the-command-line/.

over 4 years ago · Santiago Trujillo Report

0

In Ubuntu 18.04 LTS

Hostname changing via SSH is reverted after reboot in Ubuntu 18.04. Make permanent change as following way.

1. Edit /etc/cloud/cloud.cfg

sudo nano /etc/cloud/cloud.cfg

Set preserve_hostname to true

preserve_hostname: true

2. Run hostnamectl

hostnamectl set-hostname new-host-name

3. Reboot

sudo reboot
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!