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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • 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. What are Symbolic Links (Soft Links) and how to create them under Linux
  2. How to Compress and Extract Files and Directories in Linux Using gzip and bzip2
  3. cd: Change the current working directory
  4. lvmdiskscan Command Examples in Linux
  5. How To Masquerade Sender Address In Sendmail in CentOS/RHEL
  6. createrepo Command Examples in Linux
  7. CentOS / RHEL : How to change SNMP community string
  8. konsole Command Examples in Linux
  9. airpaste – Share messages and files on the same network using mDNS (Command Examples)
  10. apt Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • csslint: A linter for CSS code
  • csh: The shell (command interpreter) with C-like syntax (Command Examples)
  • csc: The Microsoft C# Compiler (Command Examples)
  • crystal: Tool for managing Crystal source code

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright