{"id":11355,"date":"2021-12-11T04:14:26","date_gmt":"2021-12-11T09:14:26","guid":{"rendered":"http:\/\/local.brightwhiz\/?p=11355"},"modified":"2021-12-11T04:14:27","modified_gmt":"2021-12-11T09:14:27","slug":"permanently-change-hostname-in-ubuntu","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/permanently-change-hostname-in-ubuntu\/","title":{"rendered":"How to Find and Permanently Change Hostname in Ubuntu Terminal"},"content":{"rendered":"\n
You do not need to do much to permanently change hostname in Ubuntu. To find out what your hostname is with the Ubuntu terminal. In Desktop environments you need to go to the Applications menu and click on Accessories \/ Terminal.<\/p>\n\n\n\n
When the terminal window opens you will be able to visually spot the hostname in two places. The first will be on the Title bar of the window while the other will be directly before the command-line prompt. In both cases, your hostname displays after your username in the format If you want to unnecessarily drill down further, Ubuntu<\/a> like any other Linux<\/a> distro provides a command to print out the hostname. Simply type:<\/p>\n\n\n\n $ hostname<\/p>\n\n\n\n You can also display the current hostname with additional information by simply entering the following command:<\/p>\n\n\n\n You can change the hostname using If you are using Ubuntu Desktop and its derivatives you can simply go to Settings (the gear icon) or About this Computer. If you had to open Settings, scroll down to where it says Details and click on that.<\/p>\n\n\n\n Doing this should launch the About screen. Go to the editable text box labeled Device name. Type in the new hostname you would like into that field and press Enter to change it.<\/p>\n\n\n\n With the Terminal window open, type in the following command and enter:<\/p>\n\n\n\n This command will change the hostname temporarily or until your restart your computer.<\/p>\n\n\n\n To make the change permanent you will need to edit the hostname file. Open the hostname file using this command:<\/p>\n\n\n\n The file should contain nothing other than the hostname in the first line.<\/p>\n\n\n\n One more step. You also need to change the hostname in one other place, the hosts file. Run the following command to open the hosts file:<\/p>\n\n\n\n With part of the output looking something like this after editing:<\/p>\n\n\n\n The Go to the line with the old hostname and change it to the new one without altering any other part of the file then save and close the file. Once you change it in both of these locations, you can safely restart your computer and the new hostname will remain permanent.<\/p>\n\n\n\n If your changes revert to the old hostname it could be because of cloud-init.<\/p>\n\n\n\n If you have the cloud-init package, a service used to initiate cloud services installed, you can also edit the and then type ls to display the files in that location. If the file is there enter the command to edit the file:<\/p>\n\n\n\n Find and set the parameter “preserve_hostname” from “false” to “true” then save.<\/p>\n\n\n\n That’s it, you should now be able to permanently change hostname on your Ubuntu or any Linux system.<\/p>\n","protected":false},"excerpt":{"rendered":" You do not need to do much to permanently change hostname in Ubuntu. To find out what your hostname is with the Ubuntu terminal. In Desktop environments you need to…<\/p>\n","protected":false},"author":1,"featured_media":11357,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,23,16],"tags":[183,193,354,424,433,544,573,591,598],"yoast_head":"\nusername@hostname<\/code>.<\/p>\n\n\n\n
$ hostnamectl<\/code><\/pre>\n\n\n\n
hostnamectl<\/code> by running the following command:<\/p>\n\n\n\n
$ sudo hostnamectl set-hostname NewHostname<\/code><\/pre>\n\n\n\n
How to Permanently Change Hostname and Hosts Files<\/h2>\n\n\n\n
Edit Hostname Using the Command-line<\/h2>\n\n\n\n
$ sudo hostname new-name<\/code><\/pre>\n\n\n\n
$ sudo nano \/etc\/hostname<\/code><\/pre>\n\n\n\n
$ sudo nano \/etc\/hosts<\/code><\/pre>\n\n\n\n
127.0.0.1 localhost\n127.0.1.1 NewHostname<\/code><\/pre>\n\n\n\n
\/etc\/hosts<\/code> resolve an IP address into a hostname.<\/p>\n\n\n\n
About cloud-init<\/h2>\n\n\n\n
\/etc\/cloud\/cloud.cfg<\/code> file. Your system may or may not have the
\/etc\/cloud\/cloud.cfg<\/code> file. You can always confirm by entering:<\/p>\n\n\n\n
$ cd \/etc\/cloud<\/code><\/pre>\n\n\n\n
$ sudo nano \/etc\/cloud\/cloud.cfg<\/code><\/pre>\n\n\n\n