Chapter 15. Changing a hostname by using hostnamectl


You can use the hostnamectl utility to update the hostname. By default, this utility sets the following hostname types:

  • Static hostname: Stored in the /etc/hostname file. Typically, services use this name as the hostname.
  • Pretty hostname: A descriptive name, such as Proxy server in data center A.
  • Transient hostname: A fall-back value that is typically received from the network configuration.

Procedure

  1. Optional: Display the current hostname setting:

    # hostnamectl status --static
    old-hostname.example.com
  2. Set the new hostname:

    # hostnamectl set-hostname new-hostname.example.com

    This command sets the static, pretty, and transient hostname to the new value. To set only a specific type, pass the --static, --pretty, or --transient option to the command.

  3. The hostnamectl utility automatically restarts the systemd-hostnamed to activate the new name. For the changes to take effect, reboot the host:

    # reboot

    Alternatively, if you know which services use the hostname:

    1. Restart all services that only read the hostname when the service starts:

      # systemctl restart <service_name>
    2. Active shell users must re-login for the changes to take effect.

Verification

  • Display the hostname:

    # hostnamectl status --static
    new-hostname.example.com

Additional resources

  • hostnamectl(1)
  • systemd-hostnamed.service(8)
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.