2023-07-27 09:30:00
The hostname or host name is the name of the machine with which it is identified on a network. It can be anything from a single string of words to a complex name. Each host name has a corresponding numeric address that also identifies the machine on the network.
On the Internet, we can think of the main URL of a website as its host name.
Check Linux hostname
You can check the current hostname of a Linux machine with the command ‘hostname‘.
$ hostname
Check Linux hostname
He ‘linux shell tips‘ is the hostname of my machine and it will be identified on my local network by this name. You can also check the corresponding numeric address with the command ‘ host ‘.
$ host linuxshelltips
Check the IP address of the hostname
Set hostname in Linux
If your machine hasn’t been assigned a hostname yet, or if you want to change the hostname, this is how you do it.
$ sudo hostname abhispc
set hostname
open the file ‘/etc/hostname’ in Vim or any editor of your choice.
$ sudo vim /etc/hostname
replace the chain hostname existing with the new hostname and then keep y out from the file.
Replace hostname
Finally, open the file ‘/etc/hosts’ and replace the host name previous with the new hostname.
$ sudo vim /etc/hosts
Replace the hostname with the new hostname
Now keep y out from the file.
Now check with the command ‘hostname’ if it has been changed
$ hostname
Verify hostname changes
Set hostname in Linux using ‘Hostnamectl’
And hostnamectl is a command line tool to modify the host name. Only the newer Linux distributions, for example. Ubuntu 16.04 y RHEL 7 and later, which are based on SystemDyou can make use of this tool.
First, to see the details about the hostincluding the hostnamerun the following command.
$ hostnamectl
Set hostname using Hostnamectl
Then, to change or set the host namerun
$ hostnamectl set-hostname abhispc
change hostname
Conclusion
We saw a simple way to modify or set the host name on linux. For more information on the command ‘hostname‘, be sure to read the page of the manual for the same use of the command ‘man hostname’.
Thanks for reading, and let us know your thoughts and questions in the comments below!
#set #change #hostname #hostname #Linux