Each person has a unique identity, such as their name and birth date. Computers also have individual identities, specifically, their hostnames and internet protocol (IP) addresses. Each machine has a valid IP address, but referring to a system by its IP address is not practical.
Instead, you can configure a computer's hostname, which is the machine's human-friendly name. You can map the hostname to the IP address so that it's easy to connect to a machine using its name.
[ Download now: Advanced Linux commands cheat sheet. ]
Configure a static hostname
Display the system's hostname using:
$ hostname
You can also use the hostname
command to modify the system's name temporarily. Here's an example:
$ hostname demo.example.com
This change is only temporary. After a reboot, all changes will revert.
Configure a persistent hostname
To persistently change the hostname, use the hostnamectl
command, or directly modify the default configuration file /etc/hostname
.
[ Learn how to manage your Linux environment for success. ]
Here's an example of modifying the hostname permanently using the hostnamectl
command. This shows the change:
$ hostnamectl set-hostname server1.example.com
After executing this command, don't forget to verify the change using the hostname
command.
You can confirm this entry by displaying the /etc/hostname
file contents.
Wrap up
These examples show you how to configure the hostname for your machine. Note that during the configuration steps, your system will not automatically resolve the hostname with the IP address. This article covers only how to configure the hostname for a machine.
About the author
Shiwani Biradar is an Associate Technical support Engineer in Red Hat. She loves contributing to open source projects and communities. Shiwani never stops exploring new technologies. If you don't find her exploring technologies then you will find her exploring food. She is familiar with Linux, Cloud, and DevOps tools and enjoys technical writing, watching TV series, and spending time with family.
More like this
Browse by channel
Automation
The latest on IT automation for tech, teams, and environments
Artificial intelligence
Updates on the platforms that free customers to run AI workloads anywhere
Open hybrid cloud
Explore how we build a more flexible future with hybrid cloud
Security
The latest on how we reduce risks across environments and technologies
Edge computing
Updates on the platforms that simplify operations at the edge
Infrastructure
The latest on the world’s leading enterprise Linux platform
Applications
Inside our solutions to the toughest application challenges
Original shows
Entertaining stories from the makers and leaders in enterprise tech
Products
- Red Hat Enterprise Linux
- Red Hat OpenShift
- Red Hat Ansible Automation Platform
- Cloud services
- See all products
Tools
- Training and certification
- My account
- Customer support
- Developer resources
- Find a partner
- Red Hat Ecosystem Catalog
- Red Hat value calculator
- Documentation
Try, buy, & sell
Communicate
About Red Hat
We’re the world’s leading provider of enterprise open source solutions—including Linux, cloud, container, and Kubernetes. We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.
Select a language
Red Hat legal and privacy links
- About Red Hat
- Jobs
- Events
- Locations
- Contact Red Hat
- Red Hat Blog
- Diversity, equity, and inclusion
- Cool Stuff Store
- Red Hat Summit