Linux

How To Change Hostname on Ubuntu & Other Linux Platforms

Are u looking to change the current hostname in ur linux desktop then u landed the right plave so in this post we are here to share some amazing post that can help change hostname in linux.

keep Reading !

In this quick tutorial, I’ll show you how to change hostnames on Ubuntu, Debian, and other Linux distributions.

How to change hostname in Linux redhat6

You can use the following systemd command to change the hostname on major Linux distributions:

hostnamectl set-hostname new_host_name

Read the rest of the article to learn more about the hostname and how to change it.

Before looking at different ways to change a hostname, you must first know what a hostname is!

What is a hostname in Linux?

A hostname is a “host” i.e. the name assigned to a computer on a network. Hostname is basically the name of your computer. It is used to identify your computer on the network

You can view the hostname in the terminal using the hostname command.

Checking current hostname

As you can see in the screenshot above, the username is anointed while the hostname istfoss-notes.

When you install Ubuntu, it asks you to setup a name for your computer/pc. This is the “hostname” for your system.

READ  20+ Best Linux Distributions For Programmers

If at any point you feel that your computer does not have a fancy or relative name, you can easily change the hostname in Linux.

Note that you should not use the same hostname on two different computers on the same network, as this can cause problems. This hostname is the unique identifier of the computer on the network.

There are two ways to setup hostname in Ubuntu:

  • Change hostname in command line
  • Change hostname using GUI way

We will see both ways of changing the hostname in this tutorial.

Change the hostname in Ubuntu and other Linux using the command line

If you want to change the hostname in Ubuntu or any other Debian-based Linux distribution, you can use specific Linux methods to do this, which is using the command line.

Now, Linux has several commands to change hostnames. I will show you two such methods here.

Method 1: Change the hostname using the system tool

If your Linux system uses SystemD, you can use the tools given by SystemD to change the hostname. To check your present or current hostname of ur pc and  other information, use can type this command:

hostnamectl

Its output should be something like this:

  • Static Hostname: itsfoss
  • Icon Name: Computer-Laptop
  • Chassis: Laptop
  • Machine ID: 1b9ab93094fa4978beba80fd3c48a18c
  • Boot ID: 68a0f4c77b9d4ca3aaa2c99ce051a7f8
  • Operating System: Ubuntu 18.04.2 LTS
  • Kernel: Linux 4.15.0-46-Generic
  • Architecture: x86-64

To change hostname, you can use this option with the hostnamectl command:

hostnamectl set-hostname <new_hostname>

Of course, replace <new_hostname> with your new host name in the above command.

READ  Best Top 10 GNOME Tweaks Tool IDeas-How to Customize Your Linux Desktop With GNOME Tweaks Tool

Method 2: replace hostname with hostname command

Open a linux terminal and use type this  command below to change the hostname. Replace <new_hostname> with the new hostname you want to use:

sudo hostname <new_hostname>

Now if you use the command hostname, you will see that your hostname has been changed.

But the changes you have just made are not permanent. If you reboot your system, the old hostname will return.

To change your hostname permanently, you must also edit your / etc / hostname and / etc / hosts files, in which Ubuntu, Mint and other Debian-based distributions store hostnames.

Since you are in the terminal, you have to use a command line based text editor to edit these files such as Vi or Vim. Ubuntu has Nano Editor installed by default so that you can use it.

I am going to use Nano here. You will see only one line here and it will contain the hostname of your system. Change it to your desired hostname and save the file.

sudo nano / etc / hostname

You must also edit the / etc / host file similarly and replace all events in your old hostname with the new hostname.

Sudo nano / etc / host

This is important otherwise you will start seeing the error “unable to resolve sudo: host”.

You are done!

Although I have used Ubuntu here, you can use these methods to change hostnames in Debian or most other distributions.

Change hostname in Ubuntu using GUI

Ubuntu, an early friendly Linux distribution, often provides a graphical way of doing things.

To change the hostname in any other Linux distribution using Ubuntu 18.04 or the GNOME desktop, simply go to System Settings and click Details.

READ  How to Install steam in ubuntu

Go to System Settings-> Details

Here, you will see the name ‘device name’ field which is editable. This ‘device name’ is the hostname of your system. Change what you want. The changes you make here are permanent.

Here, you will see the name ‘device name’ field which is editable. This ‘device name’ is the hostname of your system. Change what you want. The changes you make here are permanent.

Ubuntu 18.04 Changing Hostname in GNOME

This is a very similar process in any other desktop environment. If you are using Ubuntu 16.04 Unity, you can expand the next section to see screenshots.

Bonus Tip: Mandatory Rules for Hostnames

Some rules are specified for the hostname:

  • Hostnames can only contain letters, numbers and hyphen characters, and period characters
  • Hostname will be begin and end with a letter or number
  • hostname must be between 2 and 63 characters
  • If your proposed hostname does not follow the rules, you might see an error like this:
  • Hostname: The specified hostname is invalid

Eventually…

I hope this article helped you change the hostname on Ubuntu and other Linux distributions. Feel free to give your feedback.

About the author

Muhammed Asif

Muhammed Asif is a Blogger Who has passionate to do Experiment of Android and Tech Gadgets.I Also Completed My Btech Graduation in CSE I love to share to fruitful info on my blog.

Leave a Comment