1

How to configure a hostname on a Linux system

 1 year ago
source link: https://www.redhat.com/sysadmin/configure-hostname-linux
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to configure a hostname on a Linux system

Make it easier to access your Linux computer by giving it a human-friendly name that's simpler to use than an IP address.

Posted: August 17, 2022 | %t min read | by Shiwani Biradar (Red Hat, Sudoer)

Image
Laptop with sticky note, phone, notepad, and coffee

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
Image
hostname configuration commands

(Shiwani Biradar, CC BY-SA 4.0)

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
Image
hostnamectl commands

(Shiwani Biradar, CC BY-SA 4.0)

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.

Check out these related articles on Enable Sysadmin

Image
Combination lock on keyboard
Use the chage command to force users to change their passwords to comply with your password-aging policies.
Posted: July 5, 2022
Image
Man working on computer with headphones
Here’s how to configure Linux superuser access so that it's available to those who need it—yet well out of the way of people who don't need it.
Posted: June 30, 2022
Image
Person typing in a text editor on a laptop
Make your system boot the way you want it to by editing your Grand Unified Bootloader (GRUB) file.
Posted: June 24, 2022
Author: Alan Smithee

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK