How do i change the hostname of a running server?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi all,
To change the hostname of your server, you’ll need to follow 4 quick and easy steps. Let’s begin:
Enter your Droplet
Firstly, you’ll need to SSH to your Droplet with either root or a sudo user. You can do that using the command
Another way would be using the droplet’s console from your Control Panel with DigitalOcean.
Change the hostname using hostnamectl
The first step once you have entered the droplet would be to use the
hostnamectl
command. Let’s say we want to name our droplet ‘ExampleName’. To do so, we need to execute the command like soThe hostnamectl command does not produce output. On success, 0 is returned, a non-zero failure code otherwise.
Update the /etc/hosts file
Next on our list would be to update the hosts file located in the etc folder. You can use any editor you want from nano, vi, vim.
In there you’ll see something similar to
Change the line which says the following
to be
Save the file and exit.
Here I want to do a disclaimer, the line
127.0.1.1 PreviousNameHere
Will actually contain your previous hostname and notPreviousNameHere
.Edit the cloud.cfg file
It’s possible you have the
cloud-init
package installed. In such a case, you’ll need to update one last file -/etc/cloud/cloud.cfg
.First, check if the file exists
If the package is installed the output will look like the following:
If it isn’t installed
In the case it’s installed, you’ll need to edit it as well. Open the file,
Find the line
and change it to be
Save the file and exit.
That’s it, you are ready now!!
To make sure everything is working properly, execute the command
Regards, KFSys
http://lmgtfy.com/?q=change+hostname+linux
Do the following:
Step 1.
sudo nano /etc/hosts
Step 2. change
127.0.1.1 your-current-hostname
to127.0.1.1 your-new-hostname
. Then save the file.Step 3.
sudo nano /etc/hostsname
Step 4. change currently entered hostname in that file and enter your new hostname. Save the file after.