Host name is the identifier of a system in the network. Host name can be get with different ways in Linux. Host name is generally put in the /etc/hostname file.

Get Host name By Echoing Host name File

Host name information is stored in a file /etc/hostname . So we can simple print the host name to the terminal with echo command like below.

$ cat /etc/hostname

Get Host name With hostname Command

We can get host name with hostname command. This will only list host name and will not print domain related information.

$ hostname

Get Fully Qualified Host name

We can get fully qualified host name which provides full name with domain information.

$ hostname -f

Hostname File

Host name file /etc/hostname will only provide host name with fully qualified domain name. There will any no other data in this file.

Change Host name

As the hostname is stored in the /etc/hostname file we can change the hostname by editing this file. We will set the hostname as ubu1 with the following echo command. Keep in mind that in order to change /etc/hostname file we require root privileges which can be get with the sudo command.

$ sudo echo "ubu1" > /etc/hostname

Get Domain Name

Domain name information is about the systems network configuration.

$ dnsdomainname cen1.test

How To Get Host Name and Domain Name Of Linux? Infografic