Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to modify hostname by linux

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces how to modify the host name of linux, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

Method: 1, open the "/ etc/hostname" file, delete the old hostname, replace it with the new hostname, and save the file; 2, use the "sudo hostnamectl set-hostname" command; 3, use the "sudo hostname" command.

The operating environment of this tutorial: linux5.9.8 system, Dell G3 computer.

View the current hostname

First we use the hostname command to see the current hostname.

Hostname

You can also use the hostnamctl command

Hostnamectl

Method 1: modify the configuration file

The hostname is saved in the / etc/hostname file, so we can open the file and edit the hostname manually.

Sudo nano / etc/hosts

Delete the old hostname, replace it with the new hostname, and save the file. Pay attention to upper and lower case.

If you don't update the / etc/hosts file, some programs, such as sudo, don't know how to parse the new hostname.

If you are changing the hostname of the Linux server, the new hostname should resolve to the public IP of the Linux server. If you change the hostname of the PC, the new hostname should resolve to 127.0.0.1, or 127.0.1.1.

127.0.1.1 is the IP that the Debian Linux distribution parses the local host. When the Debian system is installed, if the computer's IP is dynamic, the Debian installer creates an entry of 127.0.1.1 in the / etc/hosts file. The 127.0.1.1 address uses the loopback network card. In fact, 127.0.0.0Mab 8 (127.0.0.0 ~ 127.255.255.255) uses the loopback network card.

Method 2:hostnamectl command

The command syntax is:

Sudo hostnamectl set-hostname

This command removes the hostname from the / etc/hostname file and replaces it with the new hostname. As with the first method, we also need to update the / etc/hosts file. The essence of both methods is the same.

Method 3:hostname command to make temporary changes

If you only need to change the hostname temporarily, you can use the hostname command.

Sudo hostname

This command does not change the static hostname (static hostname) in the / etc/hostname file, it only changes the temporary hostname (transient hostname). So when you restart the computer, you go back to the old hostname.

The static hostname is saved in the / etc/hostname file.

Thank you for reading this article carefully. I hope the article "how to modify the host name of linux" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report