• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

hostnamectl Command Examples in Linux

by admin

In most cases, systemctl is used to control services, but there are some additional systemd commands that you can use. For example, hostnamectl enables you to view the system’s network hostname and other information about the system’s hardware and the Linux kernel it is running. You can also use this command to change the system’s hostname.

Syntax

The syntax of the hostnamectl command is:

# hostnamectl [options] [subcommand] [arguments]

For example, to set the hostname to server01:

# hostnamectl set-hostname server01

hostname types
We can configure 3 hostname types is CentOS/RHEL 7 :

Hostname Type Description
Static Assigned by the system admin
Dynamic Assigned by DHCP or mDNS server at runtime
Pretty Assigned by the system admin. Its can be used as Description like “Oracle DB server”

Out of these 3, only static hostname is mandatory. Other 2 are optional.

hostnamectl Command Examples

1. Get the hostname of the computer:

# hostnamectl

2. Set the hostname of the computer:

# hostnamectl set-hostname "hostname"

3. Set a pretty hostname for the computer:

# hostnamectl set-hostname --static "hostname.example.com" && sudo hostnamectl set-hostname --pretty "hostname"

4. Reset hostname to its default value:

# hostnamectl set-hostname --pretty ""

Conclusion

The hostname command is used to view the hostname or to temporarily modify the hostname at runtime. And the hostnamectl command is used to permanently modify the hostname from command line.

Filed Under: Linux

Some more articles you might also be interested in …

  1. How To Delete Disk Partition using Parted Command
  2. “git stash” Command Examples
  3. How to enable CUPS Debugging on CentOS/RHEL
  4. pinky Command Examples in Linux
  5. Rpm: Error While Loading Shared Libraries: Libz.so.1: Cannot Open Shared Object File: No Such File
  6. How to configure postifx smtp relay in CentOS/RHEL 5 and 6
  7. vgcreate: command not found
  8. hdparm Command Examples in Linux
  9. startx Command Examples in Linux
  10. apt-add-repository Command Examples

You May Also Like

Primary Sidebar

Recent Posts

  • gml2gv Command Examples
  • glow Command Examples
  • glib-compile-resources Command Examples
  • glances Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright