9to6linux.com
Covering latest Linux News, Tutorials, Reviews and more

How to change the Hostname (computer name) in Linux

Do you want to change the hostname or the computer name of your Linux distribution? We will guide you how to do this here. - Article by 9to6linux (Editor) on
How to change the Hostname (computer name) in Linux
Latest Tech News

How to change Hostname (computer name) in Linux

Do you want to change the hostname or the computer name of your Linux distribution? We will guide you how to do this here.

This happens many times that you purchased a new desktop computer or a laptop, and the system comes with a pre-installed Linux operating system in it. The OEM manufacturer, the assembler, or the seller installed the operating system in it with some random Hostname during the setup.

It is always hard to remember the preconfigured name. Hence, you like to change it with a better, readable, and rememberable name. In this quick post, we will learn how to check the current hostname (computer name) and change it in Linux.

How to check the current hostname (computer name) in Linux?

Follow the steps mentioned below to check the hostname or computer name in Linux:

  1. Open your Terminal window.
  2. Enter the following command in the terminal screen and press Enter:
    $ hostname
  3. This will output you the name of your computer.

How to change the current hostname (computer name) in Linux?

Follow the steps mentioned below to change the hostname or computer name in Linux:

  1. Open your Terminal window.
  2. Type the following command to edit /etc/hostname using the nano editor:
    $ sudo nano /etc/hostname
  3. How to change Hostname (computer name) in Linux

  4. Replace the old name with the new one.
  5. Now type the following command to edit the /etc/hosts file using the nano editor:
    $ sudo nano /etc/hosts
  6. How to change Hostname (computer name) in Linux

  7. Replace all the occurrences of the old name with the new one.
  8. Reboot the computer for the changes to take effect.