change hostname kali linux

How To Easily Change Hostname On Kali Linux

Setting up the hostname Linux is an important step, and it’s especially essential on Kali Linux, which is often used for hacking and pen-testing purposes. Keeping the default name “kali” is probably not the smartest idea if you want to stay sneaky.

On Kali Linux, the hostname can be customized by editing the hostname and hosts files. A reboot is then required to apply the change.

Let’s see how to check your current hostname first, and then how to do this step-by-step.

Master Linux Commands
Your essential Linux handbook
Want to level up your Linux skills? Here is the perfect solution to become efficient on Linux. 20% off today!

Download now

How to find the current hostname on Kali Linux?

On most Linux distributions, the hostname is indicated just after the username when you open a terminal. The “hostname” command can also be use to get the same result.

Master Ethical Hacking Skills!
Join the Complete Ethical Hacking Course Bundle and step into the world of cybersecurity.
Learn to think like a hacker and protect systems with this comprehensive course.

It’s the same thing on Kali Linux. Open a terminal and type:
hostname

You’ll get something like this, showing you the current hostname on this computer:

In my case, the current hostname is “infosecscout”.

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!

Check the next section if you want to change it.

How to change the hostname on Kali Linux?

Here are the required steps to change the hostname on Kali Linux:

  • Set the new hostname in the /etc/hostname file.
  • Edit the /etc/hosts file to do the same change.
  • Reboot the system to apply the modification.

Let’s see how to do this.

Edit the hostname file

Kali Linux keeps the hostname for the computer in the /etc/hostname file.

You can use Nano or any other text editor to change the value.
sudo nano /etc/hostname

Administrator privileges are required, so don’t forget to use “sudo” if you are not root.
There is only one line in this file, just change the value to choose a new hostname.
For example, I’ll change mine to “infosec-kali”:

It’s recommended to keep the host name pretty short, as not all operating systems and network hardware are handling long names the same way (and it’s 63 characters max anyway).
Valid characters are letters (a-z), digits (0-9) and hyphen (-).

Once the file edited, save the changes and exit (CTRL+O and CTRL+X with Nano).

Edit the hosts file

There is another file to change, the /etc/hosts file, where the system keeps an association between hostnames and IP address (a bit like a tiny DNS for the current computer).

If you don’t change this file, you’ll get various error when using the network or local resources. So, just take a few seconds to do the same thing here:

  • Open the file with nano:
    sudo nano /etc/hosts
  • Find the old hostname in this file.
    It should be near the localhost IP address (127.0.1.1)
  • Remove the old hostname, and replace it with the new one.
  • Save and exit.
Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!

On this screenshot, you can see my hosts file after editing it.

Restart your computer

A reboot is required to apply the changes. You can do it via the graphic interface, or use this command to do it directly from the terminal:
sudo reboot

Once done, you can open a terminal again and check that the new name is used with the same command as given at the beginning of this post:
hostname

Hide your IP address and location with a free VPN:
Try it for free now, with advanced security features.
2900+ servers in 65 countries. It's free. Forever.

In my case, the hostname is now “infosec-kali”, as expected.

That’s it, you now know how to change your hostname on Kali Linux.

Video

Do you prefer to see this tutorial in video? You can watch this one that show you all the steps:

Going further

Doing the research and tests for this article, I also came across a great post on the official forum explaining how to change the hostname to something random at each boot.

I think it’s particularly smart if you are doing some kind of pen-testing. Check the previous link to see how to do it. It’s a basic script, but it can save you a lot of time.

And if you want more tutorials like this, check my other resources for Kali Linux on this website:

Whenever you’re ready for more security, here are things you should think about:

- Break free from Gmail: You should be able to choose what happens to your data. With Proton, only you can read your emails. Get private email.

- Protect yourself online: Use a high-speed Swiss VPN that safeguards your privacy. Open-source, no activity logs. Get Proton VPN risk-free.

- Master Linux commands: A sure method to learn (and remember) Linux commands. Useful ones only, one at a time, with clear explanations. Download the e-book.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *