How to Change Hostname in Ubuntu

  • Post category:Ubuntu

The hostname of your Ubuntu system is the name assigned to your device on a network. Whether you want to personalize your machine or update the name for network configurations, changing the hostname is a straightforward process. In this guide, we’ll show you how to change the hostname in Ubuntu using both the command line and the graphical interface.

Method 1: Change the Hostname Using the Command Line

For those who prefer the terminal, follow these steps to change the hostname.

Step 1: Open Terminal

Press Ctrl + Alt + T to open a terminal window.

Step 2: Set the New Hostname

Use the following command to set a new hostname:

sudo hostnamectl set-hostname new-hostname

Replace new-hostname with your desired hostname. For example:

sudo hostnamectl set-hostname my-new-host

Step 3: Verify the Change

To verify that the hostname has been changed, run:

hostnamectl

This command will display the current hostname along with other system information.

Step 4: (Optional) Edit the /etc/hosts File

To ensure your new hostname is mapped correctly, edit the /etc/hosts file:

sudo nano /etc/hosts

Look for the line with your old hostname (usually next to 127.0.1.1) and replace it with the new one. Press Ctrl + X, then Y, and Enter to save and exit.

Method 2: Change the Hostname Using the Graphical Interface

If you prefer not to use the terminal, you can change the hostname through Ubuntu’s graphical interface.

Step 1: Open Settings

Click on the system menu in the top-right corner and select Settings.

Step 2: Navigate to About

In the Settings window, go to the About section.

Step 3: Change Device Name

In the Device Name field, type in your new hostname.

Step 4: Apply Changes

The new hostname should take effect immediately. Some applications may require a reboot to recognize the change, but no restart is necessary for the system itself.

Conclusion

Changing the hostname in Ubuntu is simple whether you’re using the command line or graphical interface. By following these steps, you can easily update your system’s hostname to suit your needs. For more Linux and Ubuntu tutorials, visit CodeAllow.