Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Shell Scripting
  • Kali Linux
  • Ubuntu
  • Red Hat
  • CentOS
  • Docker in Linux
  • Kubernetes in Linux
  • Linux interview question
  • Python
  • R
  • Java
  • C
  • C++
  • JavaScript
  • DSA
Open In App
Next Article:
hwclock command in Linux with examples
Next article icon

hostname command in Linux with examples

Last Updated : 19 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

hostname command in Linux is used to obtain the DNS (Domain Name System) name and set the system’s hostname or NIS (Network Information System) domain name. A hostname is a name given to a computer and attached to the network. Its main purpose is to uniquely identify over a network.

 Syntax of the `hostname` command in Linux

hostname -[option] [file]

Example: We obtain the system hostname by just typing the hostname without any attributes.  

hostname

hostname

Options           Description Syntax
-a

This option is used to get the alias name of the host system (if any). It will return an empty line if no alias name is set. This option enumerates all configured addresses on all network interfaces. 

hostname -a
-A

This option is used to get all FQDNs (Fully Qualified Domain Name) of the host system. It enumerates all configured addresses on all network interfaces. An output may display the same entries repetitively.

hostname -A
-b

Used to always set a hostname. Default name is used if none specified.

hostname -b
-d 

 This option is used to get the Domain if local domains are set. It will not return anything (not even a blank line) if no local domain is set.

hostname -d
-f 

This option is used to get the Fully Qualified Domain Name (FQDN). It contains short hostname and DNS domain name.

hostname -f
-F 

This option is used to set the hostname specified in a file. Can be performed by the superuser(root) only.

sudo hostname -F filename
-i

This option is used to get the IP (network) addresses. This option works only if the hostname is resolvable.

hostname -i
-I

This option is used to get all IP(network) addresses. The option doesn’t depend on resolvability of hostname.

hostname -I
-s

 This option is used to get the hostname in short. The short hostname is the section of hostname before the first period/dot(.). If the hostname has no period, the full hostname is displayed.

hostname -s
-V

Gives version number as output.

hostname -V

Outputs of Options available in `hostname` command

1) `-a` Option in `hostname` command in Linux

Display all aliases of the host.

Syntax:

hostname -a
hostname -a

hostname -a

2) `-A` Option in `hostname` command in Linux

 Syntax:

hostname -A
hostname -A

hostname -A

3) `-b` Option in `hostname` command in Linux

 Syntax:

hostname -b
hostname -b

hostname -b

4) `-d` Option in `hostname` command in Linux

 Display the domain name of the host if any.

Syntax:

hostname -d
hostname -d

hostname -d

5) `-f` Option in `hostname` command in Linux 

Display the fully qualified domain name (FQDN) of the host.

 Syntax:

hostname -f
hostname -f

hostname -f

6) `-F` Option in `hostname` command in Linux

 This option is used to set the hostname specified in a file. Can be performed by the superuser(root) only. 

Syntax:

sudo hostname -F filename

 

sudo hostname -F filename

sudo hostname -F filename

7) `-i` Option in `hostname` command in Linux

 Display the IP address of the host

Syntax:

hostname -i
hostname -i

hostname -i

8) `-I` Option in `hostname` command in Linux 

 This option is used to get all IP (network) addresses. The option doesn’t depend on resolvability of hostname.

hostname -I
hostname -I

hostname -I

9) `-s` Option in `hostname` command in Linux 

Display the short hostname of the host.

 Syntax:

hostname -s
hostname -s

hostname -s

10) `-V` Option in `hostname` command in Linux

Display the version information about the hostname 

 Syntax:

hostname -V
hostname -V

hostname -V

11) How to set hostname in Linux 

Set the hostname of the system temporarily.

Syntax:

sudo hostname NEW_HOSTNAME
sudo hostname geeksforgeeks

sudo hostname geeksforgeeks

Replace NEW_HOSTNAME with the new hostname you want to set. (Here we have changed it to “geeksforgeeks”)

Set the hostname of the system permanently.

To set the hostame of our system permanently we have to go inside “/etc/hostname” using text editor and change hostname to the hostname we want.

here we can change hostname permanently

here we can change hostname permanently.

Conclusion

This command `hostname` in Linux seems so simple but at the same time it is a very powerful command that allows users to view or set the hostname of the system. It is important for users to know the `hostname` command to manage their Linux system effectively. One can easily understand by this article, as we have discussed many options and also their output, options like `-a`, `-A`, `-b`, `-d`, `-f`, `-F`, `-i`, `-I`, `-s` and `-V`.



Next Article
hwclock command in Linux with examples
author
roshalmoraes
Improve
Article Tags :
  • Linux-Unix
  • linux-command
  • Linux-networking-commands

Similar Reads

  • gs command in Linux with Examples
    gs command invokes Ghostscript, which is an interpreter of Adobe Systems PostScript and Portable Document Format(PDF) languages. After executing Ghostscript it reads further input from the standard input stream until it encounters 'quit' command. Syntax: gs [ options ] [ files ] ... Options: Below a
    2 min read
  • gunzip Command in Linux with Examples
    The gunzip command in Linux is a popular tool for decompressing files compressed with gzip. It simplifies file unzipping, enhances file management, and optimizes disk space in Linux environments. In this blog post, we will explore how gunzip works, providing practical examples for you to try. Whethe
    5 min read
  • halt command in Linux with examples
    This command in Linux is used to instruct the hardware to stop all the CPU functions. Basically, it reboots or stops the system. If the system is in runlevel 0 or 6 or using the command with --force option, it results in rebooting of the system otherwise it results in shutdown. Syntax: halt [OPTION]
    2 min read
  • hash command in Linux with examples
    The `hash` is a command in Linux that helps in managing the hash table. It facilitates with mapping the names of executable files to their locations on disk. It helps in speeds uping the commands execution by remembering paths of frequently used commands. It uses the `hash` to view hashed commands (
    5 min read
  • hdparm command in Linux with Examples
    "hdparm" (i.e., hard disk parameter) is one of the command line programs for Linux that is used to handle disk devices and hard disks. With the help of this command, you can get statistics about the hard disk, alter writing intervals, acoustic management, and DMA settings. It can also set parameters
    4 min read
  • Head Command in Linux With Examples
    Need to quickly view the beginning of a file in Linux? The head command is your best option. This essential command-line tool enables users, developers, and system administrators to preview the start of log files, configuration files, CSV datasets, and other text documents in seconds. The head comma
    6 min read
  • help Command in Linux with examples
    If you’re new to the Linux operating system and struggling with command-line utilities, the help command is one of the first tools you should learn. As its name suggests, the 'help' command provides detailed information about built-in shell commands, making it an essential resource for beginners and
    5 min read
  • hexdump command in Linux with examples
    The 'hexdump' command in Linux is a versatile utility used to display file content or data from standard input in a human-readable format. It is invaluable for programmers and system administrators for debugging binary data, analyzing file structures, and verifying data integrity. Here we will get a
    6 min read
  • How to Display Command History in Linux | history Command
    The history command in Linux is essential for terminal users, enabling them to view, search, and manipulate previously executed commands. Now, mastering this Linux command allows for efficient commands of commands, automation of repetitive tasks, and troubleshooting without the need to retype length
    4 min read
  • host command in Linux with examples
    host command in Linux system is used for DNS (Domain Name System) lookup operations. In simple words, this command is used to find the IP address of a particular domain name or if you want to find out the domain name of a particular IP address the host command becomes handy. You can also find more s
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences