The “hostname” Linux Command

The hostname command in Linux displays the system’s hostname, which is a unique name assigned to a computer or device on a network.

The syntax of hostname command is as follows:

hostname [OPTION]... [HOSTNAME]

Where OPTION can be

  • -f (display the FQDN (Fully Qualified Domain Name)),
  • -i (display the IP address(es) associated with the hostname),
  • -d (display the domain part of the FQDN),
  • -s (display the short hostname), or
  • -F FILE (use the hostname found in FILE instead of the default).

When we start a terminal, we will see the command prompt in a format as “username@hostname” , so we can check the username using “whoami” and hostname using same names command as below,

yt@dev:~$ whoami
yt

yt@dev:~$ hostname
dev

If HOSTNAME is specified, it will set the system’s hostname to the given value. You can check how this can be done at “How to Change Hostname for Ubuntu Machine ?”

Leave a Comment