Linux Command - hostname

hostname - show or set the system’s host name or domain name

Options

Option Description
-d display the name of the DNS domain
-f display FQDN(Fully Qualified Domain Name)
-i display IP address(es) of the host. This works only if the host name can be resolved. Avoid using this option.
-I display all network addresses of the host. loopback interface and IPv6 link-local addresses are omitted. Do not make any assumptions about the order of the output.

Example

Show host name

1
hostname

Show domain name

1
hostname -d

Show FQDN

1
hostname -f

show all ip address

1
hostname -I

Sample output

1
192.168.1.208

To show the ip address, you can use ifconfig command. By default, it display the information for all network interfaces.

You can also show the ip address using the ip addr show command.

Change current hostname

Hostname can be changed using hostnamectl command in Ubuntu.

To change hostname to server0

1
sudo hostnamectl set-hostname server0

To view current hostname

1
hostnamectl

Reference