Hostname and Fully Qualified Domain name in Linux

What is hostname?

Hostname in linux refers to the name of your computer.

If you have no idea about domain name, then read this article (What is domain name?).

What is fully qualified domain name (FQDN)?

Fully Qualified domain name is the unique name through which a computer is identified on the internet. The reason why it is identifiable on such a huge network (internet) is because of its uniqueness. Uniqueness in a way that it contains hostname of a computer and domain name. Remember that the hostname of the computer is unique in its own network where computer is physically present and domain name is unique all over the internet.

So, through domain name you can reach to the specific network and from that network you can reach to that specific computer through hostname. Let's see how it is practically implemented in linux.

Say you have 3 computers on your network and you want to uniquely identify each of them on the internet. Your domain name is

  1. This computer is a web server to handle websites, its hostname is www.
  2. This computer is an ftp server to handle file transfers, its hostname is ftp.
  3. This computer is an email server to send/receive emails, its hostname is mail.

Let's see, what will be the FQDNs of each computer. Remember FQDN is the combination of hostname and domain name. i.e. hostname.domain_name

  1. The FQDN of the web server will be
  2. The FQDN of the ftp server will be
  3. The FQDN of the email server will be

So, you have seen the concepts regarding hostname and fully qualified domain name (FQDN). Let's see now how it is done in Linux.

Hostname and Fully Qualified Domain name (FQDN) implementation in Linux

Following is the command to find the current hostname assigned to the system.

If you want to know the fully qualified domain name (FQDN), then use the following switch with hostname.
hostname --fqdn

As we know, there is RPM based Linux distributions (Red Hat, CentOS, Fedora etc) and Debian based Linux distributions (Debian, Ubuntu etc). They both have minor differences in implementing hostname.

RPM based Linux distributions say that the hostname should be fully qualified domain name (FQDN).

There are two things whether you want to change/set the hostname temporarily or permanently.

Change/Set the hostname temporarily

By temporarily, I mean to change the hostname as long as the computer is not rebooted. After rebooting the system, hostname will revert back to old one (which was permanently set). You can run the following command to change the hostname temporarily.

hostname new_temporary_hostname

Change/Set the hostname permanently

You can run the following command to change the hostname permanently. New linux distributions that comes with SystemD have the following command to change the hostname.

hostnamectl set-hostname new_permanent_hostname
Debian based and some of the RPM based Linux distributions have hostname in the file located in /etc/hostname. You can change hostname in this file.

For init based linux distributions, the hostname can be changed by modifying /etc/sysconfig/network by setting hostname to the new hostname of your choice.