Development

How to Change Hostname in Debian 10

Captain Salem 1 min read

How to Change Hostname in Debian 11

A hostname is a label or identifier assigned to a computer or device on a network. It is used to distinguish one machine from another in a networked environment.

Debian Change Hostname

To change the hostname in Debian 11, you can follow these steps:

Open a terminal. You can do this by clicking on the “Activities” button in the top-left corner, searching for “Terminal,” and selecting the terminal application.

In the terminal, you need to edit the /etc/hostname file. Use a text editor like nano or vim to open the file. For example, to use nano, run the following command:

sudo nano /etc/hostname

In the editor, you’ll see the current hostname. Replace it with the new hostname you want to set. For example, if you want to change the hostname to “myhostname”, your /etc/hostname file should contain only the following:

myhostname

Save the changes and exit the editor. In nano, you can do this by pressing Ctrl+O to write the file and then Ctrl+X to exit.

Next, you need to update the /etc/hosts file. Open it with the text editor using the following command:

sudo nano /etc/hosts

In the file, you’ll see a line starting with 127.0.1.1. Update the hostname part in that line to match the new hostname you set in the /etc/hostname file. For example:

127.0.1.1    myhostname

Save the changes and exit the editor.

To apply the new hostname, you need to restart your system. You can do this by running the following command:

sudo reboot

After the system restarts, it should have the new hostname you set. You can verify the changes by opening a terminal and running the following command:

hostname

It should display the new hostname you set. Example:

debian@Quantum:~$ hostname
GeekBits

Conclusion

In this tutorial, we learned how we can change the hostname of a Debian system by editing the etc/hostname file.

Share
Comments
More from Cloudenv

Cloudenv

Developer Tips, Tricks and Tutorials.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Cloudenv.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.