Hostname

LINUXLPIC1-101

2/21/2026

In Linux (specifically on systemd systems like CentOS 7), the hostname isn't just a single string in a file anymore. There are actually three distinct types of hostnames managed by the hostnamectl utility.

The Three Types of Hostnames

Type Purpose Persistence

Static The traditional hostname stored in /etc/hostname. Permanent (survives reboot).

Transient Assigned by the network (like DHCP) or the kernel. Temporary (lost after reboot).

Pretty A free-form, high-level name for humans (e.g., "Miguel's Lab VM").Permanent, but only for UI/Desktop use.

The hostnamectl Command

To see your current status:

$ hostnamectl status

To change the hostname permanently (Static):

$ sudo hostnamectl set-hostname my-new-server

Note: This command automatically updates /etc/hostname for you, so you don't have to worry about manual file editing.

Setting a "Pretty" Hostname

The "Pretty" hostname allows for spaces and special characters that aren't allowed in standard DNS names.

$ sudo hostnamectl set-hostname "CentOS 7 - LPIC Study Lab" --pretty

Now, if you run hostnamectl status, you will see both the technical "Static" name and the human-friendly "Pretty" name.

The /etc/hosts Connection (LPIC-1 Warning)

A common mistake students make is changing the hostname but forgetting to update the /etc/hosts file.

If your hostname is my-new-server, but /etc/hosts still looks like this:

127.0.0.1 localhost old-name

...many services (like sudo) will start acting very slow because they are trying to "resolve" your own name and failing.

Pro Tip: Every time you change your hostname, immediately open /etc/hosts and make sure your new name is listed next to 127.0.0.1. The rule for the /etc/hosts file is: IP → FQDN → Short Name → Aliases

Example: 127.0.0.1 my-new-server.example.com my-new-server localhost

Verify it worked

$ getent hosts 127.0.0.1

or just ping your own machine with your new name:

$ ping my-new-server

Why do we need a "Transient" hostname?

Imagine you bring your laptop to a coffee shop. Your "Static" name is my-laptop, but the coffee shop's DHCP server might want to identify you as guest-122.

  • Your Static name remains my-laptop.

  • Your Transient name becomes guest-122.

  • Once you leave the coffee shop, the transient name disappears.

If you want to see exactly what the "active" name is (the one the Kernel is currently using), you can use these traditional commands:

  1. The hostname command: Simply typing hostname returns the current active name (usually the transient one if it exists, otherwise the static one).

  2. cat /proc/sys/kernel/hostname

A common LPIC-1 "Troubleshooting" scenario

The exam might ask what happens if you set a hostname using the old command: sudo hostname my-temporary-name

  • Result: This sets the Transient hostname only.

  • Reboot: After you restart the VM, that name will disappear, and the system will go back to whatever is in /etc/hostname (the Static name).

Note: to check the transient name, you need to use the old command hostname. Ping or getent host won't work for the transient name.

Summary Checklist
  • Static: /etc/hostname (standard DNS rules).

  • Pretty: High-level description (allows spaces).

  • Command: hostnamectl set-hostname [name].

  • Sync: Don't forget to update /etc/hosts!