How to Set or Change System Hostname in Linux?
Last Updated :
26 Mar, 2025
A hostname is a label assigned to a device connected to a computer network. It is used to identify the device in various forms of electronic communication such as logging in, sending emails, or in network traffic. This name can be anything from a simple single-word string to a more complex string of numbers and letters.
Example:
- In the URL www.geeksforgeeks.org, the hostname is www.
- Mail servers are often named after their function or protocol used and receive the corresponding hostname like mail, pop3, IMAP, etc.
Rules of Hostname
- The hostname will be a single word or phrase with no space.
- A Hostname consists of only a combination of letters, numbers, periods, or hyphens.
- The maximum length of the hostname will be 253 characters.
- DNS (Domain Name Space) may be appended to the hostname.
- The hostname cannot have an underscore.
How to Display Hostname in Linux?
Step 1) Firstly open your terminal on Linux.
Step 2) Command ''Hostname'' is used in order to display hostname in Linux operating system as shown below:
hostname- This command will display the current hostname of your system. This is the simplest way to find out what your system is recognized as in the network.
- Also, without typing the command hostname you can identify your Linux hostname.
- In the above image see jagroop@jagroop-SVE1513CYNB so after @ you can identify your hostname which is:
jagroop-SVE1513CYNB
How to Display Domain Name?
Command "Domainname" is used to return the domain name of the Linux System. If your Linux device domain name is set then you will get "none" message as output. Else you will get your Domain name. In my Linux system, I don't have any domain name so it will result in none as shown:

How to display hostname with more detailed information?
In order to display hostname with more detailed information we will use hostnametcl command:
hostnamectl

Or, In order to display hostname with more detailed information various types of commands are used, and these commands we will get by using command "hostname -h" which means that we want help regarding hostname. In the below output, all the commands applicable for hostname is shown as:

For example: I want to know the IP address of my hostname so, will choose the option -i which is implemented as:

How to Change or Set a hostname?
Step 1) Change the hostname using "hostnamectl"command using the syntax:
sudo hostnamectl set-hostname geeksforgeeks
When we run the above syntax, the system will ask password and execute it as shown:

Step 2) After step 1, restart your Linux system
Step 3) After restart, open the terminal
Step 4) Now type command "hostname", you will get your changed hostname output as:

Why Set or Change a Hostname?
- Network Identification: A unique hostname helps in identifying a machine on a network. In larger networks, ensuring each computer has a distinct hostname is crucial for effective management and communication.
- Simplify Remote Management: For system administrators managing multiple servers, distinct hostnames simplify the process of maintaining these systems.
- Branding or Reorganization: Sometimes, in a corporate setting, hostnames are set to reflect the company's branding or reorganized to adhere to new IT policies.
Also Check:
Conclusion
Changing or setting the hostname in Linux may seem like a small task, but it plays a big role in how your system is identified across networks. Whether you're dealing with personal computers, business servers, or operating in cloud environments, a well-defined and distinct hostname simplifies system administration, enhances remote access, and makes network organization better.
With easy Linux commands such as hostname, hostnamectl, and domainname, you can look up, modify, or change your system name in a matter of steps—no expert skills required. These modifications assist with everything from network debugging to remote login and even enhance server tracing in corporate sectors.
Similar Reads
Non-linear Components
In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co
11 min read
Class Diagram | Unified Modeling Language (UML)
A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact
12 min read
Spring Boot Tutorial
Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance
10 min read
Backpropagation in Neural Network
Backpropagation is also known as "Backward Propagation of Errors" and it is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network. In this article we will explore what
10 min read
AVL Tree Data Structure
An AVL tree defined as a self-balancing Binary Search Tree (BST) where the difference between heights of left and right subtrees for any node cannot be more than one. The absolute difference between the heights of the left subtree and the right subtree for any node is known as the balance factor of
4 min read
What is Vacuum Circuit Breaker?
A vacuum circuit breaker is a type of breaker that utilizes a vacuum as the medium to extinguish electrical arcs. Within this circuit breaker, there is a vacuum interrupter that houses the stationary and mobile contacts in a permanently sealed enclosure. When the contacts are separated in a high vac
13 min read
Polymorphism in Java
Polymorphism in Java is one of the core concepts in object-oriented programming (OOP) that allows objects to behave differently based on their specific class type. The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity ca
7 min read
3-Phase Inverter
An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power
13 min read
Linux Commands Cheat Sheet
Linux, often associated with being a complex operating system primarily used by developers, may not necessarily fit that description entirely. While it can initially appear challenging for beginners, once you immerse yourself in the Linux world, you may find it difficult to return to your previous W
13 min read
Decorators in Python
In Python, decorators are a powerful and flexible way to modify or extend the behavior of functions or methods, without changing their actual code. A decorator is essentially a function that takes another function as an argument and returns a new function with enhanced functionality. Decorators are
10 min read