Skip to main content
RunBook Academy

LinuxLI · Linux Fleet ArchitectureNaming inventory

Naming and inventory - knowing your fleet

Foundation⏱ ~10 minhostnamectlbash

What you'll learn

  • Design a hostname convention
  • Use host IDs and machine IDs
  • Maintain an inventory database
  • Integrate with configuration management

Prerequisites

Verified against Ubuntu 24.04 LTS · Debian 12 (Bookworm) · RHEL 9.x · Rocky Linux 9.x · AlmaLinux 9.x · Linux kernel 6.1 LTS / 6.6 LTS · systemd 255+ · OpenSSH 8.7p1 (RHEL 9) / 9.6p1 (Ubuntu 24.04) · nftables 1.0.x · chrony 4.x · Pacemaker 2.1.x · Corosync 3.1.x · 2026-08-09

Not yet marked complete on this device.

A fleet of 100 hosts without a naming convention is a mess. A fleet with hostname conventions, machine IDs, and an inventory is manageable. This lesson covers the basics.

Hostname conventions

A good hostname convention is:

  • Predictable: you can guess the hostname from the role and location.
  • Unique: no two hosts have the same name.
  • Stable: the name does not change when the role does.
  • Sortable: hosts in the same group sort together.

Common conventions:

<role>-<num>-<location>.<domain>
db-01-prod.example.com
web-03-prod.example.com
cache-02-staging.example.com
  • role: db, web, cache, app, etc.
  • num: zero-padded instance number.
  • location: prod, staging, dev, region, etc.
  • domain: the FQDN.

Avoid:

  • Random names (db-jade-walrus).
  • Names that change with state (db-5-active, db-5-failed).
  • Names longer than 15 characters (legacy limit).

Set the hostname

# Static (preserved across reboots)
hostnamectl set-hostname db-01-prod.example.com

# Pretty (for display)
hostnamectl set-hostname --pretty "DB 01 Prod"

# Transient (not preserved)
hostnamectl set-hostname --transient db-01-prod.example.com

Verify:

hostnamectl
hostname -f

Machine ID

Every Linux host has a unique machine ID (in /etc/machine-id):

cat /etc/machine-id
# 5d1b3a1c2e8f4a6b9d0c1d2e3f4a5b6c

The machine ID is:

  • Unique per host.
  • Stable across reboots.
  • Used by systemd, SSSD, and other tools to identify the host.

Inventory systems use the machine ID as the primary key.

Inventory database

Maintain a database of all hosts. Common fields:

CREATE TABLE hosts (
    id INTEGER PRIMARY KEY,
    machine_id TEXT UNIQUE,
    hostname TEXT,
    fqdn TEXT,
    role TEXT,         -- db, web, app
    environment TEXT,  -- prod, staging, dev
    region TEXT,       -- us-east-1, eu-west-1
    ip TEXT,
    os_version TEXT,
    kernel TEXT,
    installed_at TIMESTAMP,
    decommissioned_at TIMESTAMP,
    notes TEXT
);

Sources of inventory data:

  • Configuration management (Ansible facts).
  • Cloud provider API (AWS, Azure, GCP).
  • CMDB (ServiceNow, etc.).
  • Manual updates.

Integrations

  • Ansible: inventory plugin from cloud or CMDB.
  • Salt: grains (host facts) collected automatically.
  • Puppet: external nodes classifier from CMDB.
  • Monitoring: Prometheus target discovery from cloud.

For a small fleet, a spreadsheet works. For a large fleet, use an automated inventory system.

Knowledge check

Knowledge check · 3 questions

  1. Q1. What is a good hostname convention for production?

  2. Q2. The /etc/machine-id is unique per host.

  3. Q3. Which of the following are valid inventory sources? Select all that apply.

Passing score: 75%. Answers are checked in this browser.