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.
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.
It’s the same thing on Kali Linux. Open a terminal and type:
You’ll get something like this, showing you the current hostname on this computer:
In my case, the current hostname is “infosecscout”.
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.
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:
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:
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.
Do you prefer to see this tutorial in video? You can watch this one that show you all the steps:
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: