Changing the hostname of your Ubuntu server installation is a pretty simple affair.
To view the current hostname of your system, simply enter hostname.
Now to affect a termporary change of hostname, you could simply use:
sudo hostname mynewhostname
However, be careful here as this is really just a temporary hostname change and won’t be saved when the system restarts. The reason for this is because the hostname is usually set on system startup when the system loads the detail from a file, generally located at “/etc/hostname”.
So in order to permanently change your system’s hostname, you need to edit the correct host-related files like so:
sudo nano /etc/hosts
Set your new desired hostname next to the entry for 127.0.1.1 (leaving the 127.0.0.1 localhost entry as is). Next, run:
sudo nano /etc/hostname
Simply enter your desired hostname on a single line and save.
Once you have made your changes and saved both of the files, you should be good to go – as you can test out for yourself by simply rebooting your machine with a good old sudo reboot and then checking with hostname!
Nifty.
You might also enjoy:
-
The following bash script is written to automate the process of backing up all your various MySQL databases running on either a local or remote MySQL server ...
-
If you're using Ubuntu or perhaps another flavour of Linux, there come a time when you need to either reboot (restart) or shutdown a machine via a terminal ...
-
As a web developer I need to juggle a number of projects on my development machine all at once. The simple way to get around accessing these various sites i ...
-
SCP is a powerful utility that allows us to securely copy files between remote machines. What makes it even more powerful is the ability to add it to script ...
-
Installing a new software package via a command line terminal in Ubuntu Karmic Koala (and basically all the other versions preceding it) is deceptively easy ...