• 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

hostname Command Examples in Linux

by admin

This command can get or set the hostname or the NIS domain name. You can also get the DNS domain or the FQDN (fully qualified domain name). Unless you are using bind or NIS for host lookups you can change the FQDN (Fully Qualified Domain Name) and the DNS domain name (which is part of the FQDN) in the /etc/hosts file.

Usage:

hostname [-b] {hostname|-F file}         set host name (from file)
hostname [-a|-A|-d|-f|-i|-I|-s|-y]       display formatted name
hostname                                 display host name

{yp,nis,}domainname {nisdomain|-F file}  set NIS domain name (from file)
{yp,nis,}domainname                      display NIS domain name

dnsdomainname                            display dns domain name

hostname -V|--version|-h|--help          print info and exit

Example:

# hostname
abc-redhat-host

Set the desired hostname of the system using hostname command.

# hostname xyz.example.com

To keep the hostname persistent across reboots, edit the file /etc/hostname.

# vi /etc/hostname
xyz.example.com

The hostname can be viewed in the /etc/hostname file as well.

# cat /etc/hostname

hostname Command Examples

1. To print the hostname of the system:

# hostname 

2. To display the alias host name of the system:

# hostname -a
# hostname --alias 

3. To display the name of DNS domain:

# hostname -d
# hostname --domain 

4. To read the hostname from the file:

# hostname -F hostfile.txt
# hostname --file hostfile.txt

5. To display the FQDN (Fully Qualified Domain Name):

# hostname -f
# hostname --fqdn
# hostname --long 

6. To display the IP address of the host:

# hostname -i
# hostname --ip-address 

7. To display the short hostname:

# hostname -s
# hostname --short 

8. To get the version of the hostname command:

# hostname -V
# hostname --version 

9. To have the verbose output:

# hostname --verbose 

10. To display the NIS domain name:

# hostname -y
# hostname --yp
# hostname --nis 

11. To get the help for hostname command:

# hostname --help 

Filed Under: Linux

Some more articles you might also be interested in …

  1. How to Change the default kernel (boot from old kernel) in CentOS/RHEL 8
  2. CentOS / RHEL : Installing and Configuring ASMLib
  3. Examples of using dmsetup command in Linux
  4. CentOS / RHEL 6 : How to setup yum repository using locally mounted DVD
  5. jobs Command Options In Linux
  6. How to find Which Process Is Killing mysqld With SIGKILL or SIGTERM on Linux
  7. How to configure iSCSI Initiator (client) in CentOS / RHEL 6
  8. Slow SSH login due to unreachable rsyslog server
  9. How to Partition DM-Multipath Pseudo Devices in CentOS/RHEL
  10. CentOS / RHEL : How to add a null route in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • vgextend Command Examples in Linux
  • setpci command – configure PCI device
  • db_load command – generate db database
  • bsdtar command – Read and write tape archive files

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright