In a networking environment, all computer systems, be it Windows PC, Linux server or Unix mainframe, has a hostname. A hostname is a label (also known as computer name) that is assigned to a device connected to a computer network and that is used to identify the device in various forms of electronic communication such as the World Wide Web servers, email transport agents or Usenet.
Hostname may be appended a domain name, which is a name in a Domain Name System (DNS), separated from the host name by a period (dot). In the latter form, the hostname is also called a domain name. If the domain name is completely specified including a top-level domain of the Internet, then the hostname is said to be a fully qualified domain name (FQDN). For example, hostname.domain.com.
It’s import to set a correct hostname and FQDN, especially for a newly set up system which almost certainly connected to Internet. For Linux, the new system host name is normally defaulted the hostname to localhost.localdomain, with no domain part of the FQDN (Fully Qualified Domain Name). This tutorial will guide on how to properly change the hostname and FQDN.
- Change the hostname of the machine with one of the following methods (replace hostname with actual computer name that you want to assign (without domain name, i.e. host name only):
Method 1: Run the following command:
hostnamectl set-hostname hostname
Method 2: Edit the /etc/hostname file, and replace the existing content with the new hostname.
- If you use method 2 above, run the following command to make the change effective:
systemctl restart systemd-hostnamed
- Edit /etc/hosts file, and enter a new line with the IP address, FQDN (Fully Qualified Domain Name) and hostname of the system. For example:
192.168.1.1 server.techjourney.net server