Skip to main content

Changing Kali Linux Hostname

  1. Change hostname permanently and make it sticky – with reboot
  2. Change hostname permanently and make it sticky  – without rebooting
  3. Change hostname randomly in each boot time.

Change hostname permanently – with reboot

As always, I’ve divided the options into multiple dot points.

Step 1: edit hostname file

Open hostname file from /etc directory and modify the name in there.
leafpad /etc/hostname
How to change hostname in Kali Linux - 1- blackMORE Ops
Let’s say we change the name from kali to aiur
How to change hostname in Kali Linux - 2- blackMORE Ops
Save the file.

Step 2: edit hosts file

Open hosts file from /etc directory and modify the name in there.
leafpad /etc/hosts
How to change hostname in Kali Linux - 3 - blackMORE Ops
Change kali to aiur.
How to change hostname in Kali Linux - 4 - blackMORE Ops
Save the file.

Step 3: reboot

Now reboot to reflect your changes
reboot
And you should see the new hostname coming up in terminal (i.e. root@aiur)

How to change hostname in Kali Linux - 6 - blackMORE Ops

Change hostname permanently – without reboot

Don’t want to reboot?  Here’s how

Follow step 1 and 2 from above

i.e.
  1. Update /etc/hostname
  2. Update /etc/hosts, so local address (es) resolves with the new system name.

Reload configuration files

Type in following 3 commands one at a time.
service hostname.sh start
service networking force-reload
service network-manager force-reload
How to change hostname in Kali Linux - 7 - blackMORE Ops
Now force-reload networking service.
How to change hostname in Kali Linux - 8 - blackMORE Ops
This will temporarily disconnect your system from the network (ssh usually resists short disconnection)
This might definitively disconnect your system from the network because networking might not restore connections; please reboot, which is not lazy, but ensures that your setup is really correct

How to change hostname in Kali Linux - 9 - blackMORE Ops
So we need to reload network-manager service as well.
How to change hostname in Kali Linux - 10 - blackMORE Ops
This should reconnect networking again.
How to change hostname in Kali Linux - 11 - blackMORE Ops
Depending on what other services you’re running, i.e. avahi, metasploit, postgresql, cups, openSSH server, ssmtp etc. you might have to restart them all.
Now you must close your existing terminals to have the new hostname coming up at the top. See following screenshot with highlighting.
First screenshot is after re-loading all the required services. Note that it’s still showing root@kali in the top. uname -a or hostname shows correct info though.
How to change hostname in Kali Linux - 12 - blackMORE Ops
If I close this terminal and open a new one, root@kali becomes root@aiur which is what we want.
How to change hostname in Kali Linux - 13 - blackMORE Ops

Change hostname randomly in each boot time

Following procedure will allow you to change your hostname randomly in each boot. That hostname will stick until you reboot again.

Create a bash script

Create a script which will automate the procedure
In this terminal create a file.
touch newhostname
leafpad newhostname
How to change hostname in Kali Linux - 14 - blackMORE Ops
Now, add the following lines to your newly created file:
#!/bin/bash
cp -n /etc/hosts{,.old}
idomainname=$(domainname -i)
fdomainname=$(domainname -f)
newhn=$(cat /dev/urandom | tr -dc 'A-Z' | head -c8)
echo $newhn > /etc/hostname
mv /etc/hosts /etc/hosts.old
echo "127.0.0.1 localhost" > /etc/hosts
echo "$idomainname  $fdomainname    $newhn" >> /etc/hosts
echo "# The following lines are desirable for IPv6 capable hosts" >> /etc/hosts
echo "::1     localhost ip6-localhost ip6-loopback" >> /etc/hosts
echo "ff02::1 ip6-allnodes" >> /etc/hosts
echo "ff02::2 ip6-allrouters" >> /etc/hosts
service hostname.sh stop
sleep 1
service hostname.sh start
service networking stop
sleep 1
service networking start
service network-manager stop
sleep 1
service network-manager start
xhost +$newhn
exit
Save it and exit leafpad.
Note: I’ve used only CAPS here for new hostname, 'A-Z'. You can also choose a mixure of uppercase and lowercase ('A-Za-z') or numbers etc.
Also I’ve chosen 8 characters long hostname head -c8, you can change it to any length you like.

Move script to /usr/bin/ folder

We need to move this file to /usr/bin.
mv newhostname /usr/bin/newhostname

Make it executable

Use the following command to make newhostname file executable.
chmod +x /usr/bin/newhostname
How to change hostname in Kali Linux - 16 - blackMORE Ops

Make it run at Startup:

Now that we have the script in right place and it’s executable, we need to add it your Startup applications. This will allow your system to run it every time you reboot your machine and generate a new hostname for you.
Follow the steps below:
  1. Click on “Applications” –> “System Tools” –> “Preferences” –> “Startup Applications”
  2. Click “Add”
  3. Fill in:
    1. Name: Random Host Name
    2. Command: /usr/bin/newhostname
    3. Comment: Start Kali with a random hostname each boot
  4. Click Save
  5. Close Windows
How to change hostname in Kali Linux - 17 - blackMORE Ops

How to change hostname in Kali Linux - 18 - blackMORE Ops
How to change hostname in Kali Linux - 19 - blackMORE Ops

Reboot

Finally reboot your machine to load the script at start-up.
reboot
How to change hostname in Kali Linux - 5 - blackMORE Ops
Enjoy your new hostnames. Here’s mine

How to change hostname in Kali Linux - 20 - blackMORE Ops

Credits and sources:

Similar procedures were posted in different places:
  1. Telecomix Wiki
  2. Ubuntu Forums by rocksockdoc
  3. Kali forums by testingresults, ,
  4. Notesbit by Jiltin

Copied for future reference from https://www.blackmoreops.com/2013/12/12/change-hostname-kali-linux/.

Popular posts from this blog

Importing Exploit-DB Exploits into Metasploit in Kali Linux for Offline Access

You're going to need three terminals open for this. Terminal 1 for starting metasploit Terminal 2 for importing the exploit to local Metasploit repository Terminal 3 for searchsploit which we will use to search for the exploit instead of opening your browser and looking in exploitdb. Let's be done with it! 1. First, open the first terminal to run metasploit with the following commands: > service postgresql start > msfconsole  2. Go to Terminal 3 and run the following command to update its database: > searchsploit -u 3. Open Terminal 2, then go to the metasploit modules directory by: > cd .msf4/modules 4. Then create a directory inside the msf4 modules folder: > mkdir exploits 5. Now, back to the Terminal 3. We will to search for an exploit we want to import. Let's first try to look for the explore ms15-100 by typing: > searchsploit msf15-100 After pressing Enter, you should be able to see the search result. It will be a t...

Different ways Product Managers can add value

Product Management is NOT about adding new features to your product! It's about adding VALUE! 𝗛𝗲𝗿𝗲 𝗮𝗿𝗲 𝟴 𝗱𝗶𝗳𝗳𝗲𝗿𝗲𝗻𝘁 𝘄𝗮𝘆𝘀 𝘆𝗼𝘂 𝗰𝗮𝗻 𝗮𝗱𝗱 𝘃𝗮𝗹𝘂𝗲 𝘁𝗼 𝘆𝗼𝘂𝗿 𝗽𝗿𝗼𝗱𝘂𝗰𝘁: 𝘝𝘢𝘭𝘶𝘦 𝘢𝘴 𝘋𝘪𝘳𝘦𝘤𝘵 𝘮𝘦𝘵𝘳𝘪𝘤𝘴’ 𝘨𝘳𝘰𝘸𝘵𝘩  -  This most basic, business-driven aspect of the “value” concept. It will often drive your product goals, and it’s easy (and mandatory!) to measure. New features will mostly fall under this category! 𝘝𝘢𝘭𝘶𝘦 𝘢𝘴 𝘱𝘳𝘦𝘷𝘦𝘯𝘵𝘪𝘯𝘨 𝘢 𝘱𝘳𝘰𝘣𝘢𝘣𝘭𝘦 𝘧𝘶𝘵𝘶𝘳𝘦 𝘥𝘳𝘰𝘱 𝘪𝘯 𝘮𝘦𝘵𝘳𝘪𝘤𝘴 -  Any product is like a house; if not maintained and fixed, it will eventually collapse. This aspect translated into quality that the client/user often doesn’t get to appreciate until it’s too late. To achieve this kind of value, you will have your development team fixing bugs, making products scalable, and introducing/replacing old technologies in favour of newer ones. 𝘝𝘢𝘭𝘶𝘦 𝘢𝘴 𝘵𝘩𝘦 𝘢𝘣𝘪𝘭𝘪𝘵𝘺 𝘵𝘰 𝘵𝘳𝘢?...

List of Websites that can be very useful to anyone

1. screenr.com – record movies of your desktop and send them straight to YouTube. 2. ctrlq.org/screenshots – for capturing screenshots of web pages on mobile and desktops. 3. goo.gl – shorten long URLs and convert URLs into QR codes. 4. unfurlr.com – find the original URL that's hiding behind a short URL. 5. qClock – find the local time of a city using a Google Map. 6. copypastecharacter.com – copy special characters that aren't on your keyboard. 7. postpost.com – a better search engine for twitter. 8. lovelycharts.com – create flowcharts, network diagrams, sitemaps, etc. 9. iconfinder.com – the best place to find icons of all sizes. 10. office.com – download templates, clipart and images for your Office documents. 11. followupthen.com – the easiest way to setup email reminders. 12. jotti.org – scan any suspicious file or email attachment for viruses. 13. wolframalpha.com – gets answers directly without searching - see...