Situatie
Setting a hostname is a fundamental step in configuring a Linux system. The hostname acts as an identifier for your machine on a network, making it easier to manage and communicate with other devices.
Solutie
Pasi de urmat
Temporarily:
Step 1: Check the Current Hostname
First, you need to check the current hostname of the device by using the hostname command in terminal
hostname
Set the Hostname Temporarily
sudo hostnamectl set-hostname <name>
Verify Hostname Changes
You can verify the change in hostname by using the hostname or hostnamectl command in the terminal, which will display the temporary hostname we created.
hostname hostnamectl
Permanently:
Step 1: Check the Current Hostname
First, you need to check the current hostname of the device by using the hostname command in terminal
hostname
Ensure you know the current hostname before making any changes. This command displays the current hostname of your Linux machine. We can see that the hostname of our machine is Kali.
Step 2: Check File Directories
You need to check the contents of these two file directories “/etc/hostname and /etc/hosts” and you will erase some content in these files and rewrite it in the next step.
cat /etc/hostname cat /etc/hosts
Step 3: Edit /etc/hostname using Vi Editor
Use the sudo vi /etc/hostname command to enter into the vi editor and change the contents in the /etc/hostname file after entering into the vi editor follow these steps:
- Enter insert mode by pressing i.
- Delete the existing hostname and enter the new one.
- Save the changes by pressing Esc, then:wq!.
sudo vi /etc/hostname
Leave A Comment?