How To Change Hostname on Linux via Command-Line Interface (CLI)

DigitalOcean Referral Badge
Start your VPS now with FREE $100 credit.

Hostname (also called nodename in archaically) is a label on a computer or server networking which is assigned to a device connected to a computer network.

Hostnames are commonly used to identify devices in various forms of electronic communication, e.g World Wide Web. Hostname can be a simple name consisting of a single word or phrase, or even structured.

Each hostname usually has at least one numeric network address associated with it to route packets for performance reasons, etc.

Internet hostnames can also appended the name of a Domain Name System (DNS) domain, which is separated from the host-specific label by a period (“dot”). Hostname is also called a domain name In the latter form.

We can call hostname as a fully-qualified domain name (FQDN) if the domain name is fully specified, including a top-level Internet domain.

Hostnames with DNS domains are usually stored in the Domain Name System along with its IP addresses, where the host represent for the mapping purpose the hostname to an address, or the reverse process.

Well, today we will guide on how to change hostname on Linux distribution system via command-line interface (CLI) on SSH terminal. Make sure to set the hostname with a fully-qualified domain name or FQDN.

READ:  How To Install Cockpit Web Console on Rocky Linux 8.5 (Green Obsidian)

It works on almost all Linux machine, including Debian/Ubuntu and RHEL-based distros like CentOS, Rocky Linux and AlmaLinux.

1. Let’s Set Hostname with a fully-qualified domain name (FQDN)

Simply run the following command the set a hostname with fully-qualified domain name (FQDN).

$ hostnamectl set-hostname server.domain.com

For example:

$ hostnamectl set-hostname srv.fcgid.com

2. Verify Hostname

Verify your a new hostname using the following command.

$ hostnamectl
-----------------------------------------------------
Static hostname: srv.fcgid.com
Icon name: computer-vm
Chassis: vm
Machine ID: 8293ea6584d64fcc8c0a2b87779cb5e8
Boot ID: 11fdd08d104a4a369fa1d5651366aae7
Virtualization: kvm
Operating System: CentOS Stream 8
CPE OS Name: cpe:/o:centos:centos:8
Kernel: Linux 4.18.0-383.el8.x86_64
Architecture: x86-64
-----------------------------------------------------

Conclusion

Changing the hostname on a Linux-based distro is very, very easy. Although we change the hostname only through the command-line interface (CLI) via the SSH console. This can be applied to all Linux-based distro systems.

Leave a Comment