How to Set & Change Hostname & FQDN (Fully Qualified Domain Name) in RHEL & CentOS 7

»»»How to Set & Change Hostname & FQDN (Fully Qualified Domain Name) in RHEL & CentOS 7

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.

Tip
To check current hostname, use the following command:

hostname

To check the current FQDN, use the following command:

hostname -f

FQDN may be shorter (only hostname is shown) if there is not DNS (Internet) domain name configured.

Or you can use the following command to show all static, transcient and pretty hostname:

hostnamectl status

  1. 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.

  2. If you use method 2 above, run the following command to make the change effective:
    systemctl restart systemd-hostnamed
  3. 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
    Note
    FQDN cannot be changed by using hostname. The recommended method of setting the FQDN is to make the hostname be an alias for the fully qualified name using /etc/hosts, DNS, or NIS. As the hosts entry in /etc/nsswitch.conf used for resolving host names in RHEL 7 and CentOS 7 always uses and parses “files” (i.e. /etc/hosts first, so it’s recommended to change the FQDN tin /etc/hosts, which also specifies its primary IP address.

    However, if you have added an entry for the system in the DNS server for local LAN which can accurately resolve and return the FQDN for the system when queried, you can skip this step.

By |2017-03-25T04:00:52+00:00March 25th, 2017|Categories: Linux|Tags: , , , , |0 Comments

About the Author:

LK is a technology writer for Tech Journey with background of system and network administrator. He has be documenting his experiences in digital and technology world for over 15 years.Connect with LK through Tech Journey on Facebook, Twitter or Google+.

STAY IN TOUCH

close-link