How to change hostname on Ubuntu Operating System

How to change hostname on Ubuntu Operating System

Hostname is the identified name of a computer or server's operating system. It's used for computer communication with each other. Hostname works when you connect computers on the same network and router. Every system has its own hostname for its uses. It's called localhost.

Localhost is used for testing web applications, server access, and more over the ports. However, we cannot access localhost from another computer even if we're connected to the same network connection, or access it from another network. It works only for its own system: for localhost, use 127.0.0.1 for local access. Now follow these steps to change the hostname on Ubuntu operating system.

Ubuntu sets the default hostname when you install the operating system. If you're using a cloud server like DigitalOcean or others, you'll be asked or shown how to create a hostname. If you're currently using the default hostname and need to change it, follow this command to open the hostname changing option:

$ sudo nano /etc/hostname

Here you can see your current hostname. If you want to change your hostname, press Ctrl + X and then press Y to confirm your new hostname.

Now you can see your new hostname, but this device's new hostname is not ready to be accessed from another device. We need to make changes to the hosts file:

$ sudo nano /etc/hosts
set ip for new host public access

Now reboot your system by using the "sudo reboot" command to make it accessible from another device on the same network using the hostname.