Table of Contents
This tip is about the how to Set or Change Hostname in Linux. So read this free guide, How to Set or Change Hostname in Linux step by step. If you have query related to same article you may contact us.
How to Set or Change Hostname in Linux – Guide
The hostname of a Linux system is meaningful because it is used to recognize the device on a network. The hostname is also displayed at other visible points, for example in the endpoint summary. This provides a constant token of the system you are working with. It’s a real savings when you’re dealing with multiple systems over SSH and the order-line terminals start to blend into your psyche.
Of course, IP addresses are used when devices need to communicate with each other, but they can change frequently. Hostnames give us a way to know which device we are interacting with in the organization or genuinely, without remembering too many numbers that depend on future developments. Consequently, it is significant that your system has a hostname that helps you quickly distinguish it. For example, “backup server” is substantially more useful than “server2”.
How to Set or change the hostname on Linux
Check the Linux hostname
You can check the current hostname of a Linux machine with the command ‘hostname’.
$ hostname
‘linuxshelltips’ is the hostname of my machine and will be identified on my local network with this name. You can also check the corresponding numeric address with the ‘host’ command.
$ linuxshelltips host
Set hostname on Linux
If your machine has not yet been assigned a hostname, or if you want to change the hostname, here’s how.
$ sudo hostname abhispc
Open the ‘/etc/hostname’ file in Vim or any editor of your choice.
$ sudo vim / etc / hostname
Replace the existing hostname string with the new hostname, then save and exit the file.
Finally, open the file ‘/etc/hosts’ and replace the old hostname with the new hostname.
$ sudo vim / etc / hosts
Now save and exit the file. Now check with the ‘hostname’ command if it has changed.
$ hostname
Set hostname on Linux using ‘Hostnamectl’
A hostnamectl is a command-line tool for modifying the hostname. Only newer Linux distributions, for example Ubuntu 16.04 and RHEL 7 and later, which are based on SystemD, can make use of this tool. First, to see the details about the host, including the host name, run the following command.
$hostname
So, to change or set the hostname, run
$ hostnamectl set-hostname abhispc
Final note
I hope you like the guide How to Set or Change Hostname in Linux. In case if you have any query regards this article you may ask us. Also, please share your love by sharing this article with your friends.