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
How to Change or Set System Locales in Linux?
Locale is basically a set of environmental variables that defines the user's language, region, and any special variant preferences that the user wants to see in their Linux interface. System libraries and locale-aware applications on the system use these environmental variables. Locale settings usua
7 min read
How to Change Kali Linux hostname?
Changing the hostname in Kali Linux involves modifying system configuration files to update the label assigned to your device on a network. The hostname serves as a unique identifier for the device, simplifying communication by using a readable name instead of an IP address. Adjusting the hostname c
5 min read
How to change the default SSH port in Linux
SSH (Secure Shell) is a network protocol used to securely connect to the remote server where the data between the server and client is transferred in an encrypted format. In the world of Linux system administration and security, one essential practice is changing the default SSH port. This article w
7 min read
How to Set Hostname Permanently in Linux
Setting a hostname is a fundamental step in configuring a Linux system. The hostname acts as an identifier for your machine on a network, making it easier to manage and communicate with other devices. In this article, we'll explore the importance of having a well-defined hostname and the process of
7 min read
How To Change Default Shell In Linux
In most Linux systems, the default shell is bash but we can change that to any other shell-like zsh, fish, sh, and any other. In this article, we are going to show how to change that default shell to any other shell in Linux systems. To change the user's shell, first, let's find the current shell. T
4 min read
How to Change Hostname on RHEL 9 (Red Hat Enterprise Linux 9)
Changing the hostname on RHEL 9 (Red Hat Enterprise Linux 9) is a fundamental task that can be accomplished with a few simple steps. In this detailed guide, we will walk you through each aspect of the process, ensuring that even beginners can understand and execute the procedure successfully. Table
4 min read
How to Change Apache HTTP Port in Linux?
The Apache HTTP server is one of the internet's most popular web servers today, thanks to its versatility, consistency, and a plethora of features, some of which are actually not available on other web servers, such as Nginx's competitor. Some of Apache's most significant features include the abilit
2 min read
How to Move File in Linux | mv Command
The `mv` command in Linux is like a superhero tool that can do a bunch of cool stuff with your files and folders. Think of it as a digital moving truck that helps you shift things around in your computer. Whether you want to tidy up your folders, give your files new names, or send them to different
7 min read
How to Change Default MySQL/MariaDB Port in Linux?
The default port that the MySQL database server runs under Linux is 3306/TCP. Use the commands below to change the default MySQL/MariaDB Database port in Linux. vi /etc/mysql/mariadb.conf.d/50-server.cnf Search for the line MYSQL, find port under this line, and replace port values accordingly. [mysq
1 min read
How to Change the username or userID in Kali Linux?
Kali Linux, a popular Linux distribution for penetration testing and ethical hacking, allows users to create a username during installation, automatically assigning a unique User ID (UID) to each user for identification. However, there are situations where you might need to change the username or us
4 min read