In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about how to modify the host name in Linux. The article is rich in content and analyzes and narrates it from a professional point of view. I hope you can get something after reading this article.
The hostnamectl command allows you to set three types of hostnames in Linux, details of which are as follows:
Static: this is the static hostname added by the system administrator.
Instantaneous / dynamic: this is given by the DHCP or DNS server at run time.
Readable form: it can be given by the system administrator. This is a free-form host name that represents the server in an easy-to-read form.
All of these can be set in the following four ways.
Hostnamectl command: controls the hostname of the system.
Nmcli command: is a command line tool that controls NetworkManager.
Nmtui command: is a text user interface that controls NetworkManager.
/ etc/hostname file: this file contains the static hostname of the system.
Method 1: use hostnamectl in Linux to change the hostname
Hostnamectl can be used to query and change the hostname of the system, as well as related settings. Just run hostnamectl to view the hostname of the system.
$hostnamectl
Or use the following command:
$hostnamectl status Static hostname: daygeek-Y700 Icon name: computer-laptop Chassis: laptop Machine ID: 31bdeb7b83230a2025d43547368d75bc Boot ID: 267f264c448f000ea5aed47263c6de7f Operating System: Manjaro Linux Kernel: Linux 4.19.20-1-MANJARO Architecture: x86-64
If you want to change the host name, you can use the following command format:
Syntax format:
$hostnamectl set-hostname [YOUR NEW HOSTNAME]
Use the following command to change the hostname using hostnamectl. In this example, I will change the host name from daygeek-Y700 to magi-laptop.
$hostnamectl set-hostname magi-laptop
You can use the following command to view the updated hostname.
$hostnamectl Static hostname: magi-laptop Icon name: computer-laptop Chassis: laptop Machine ID: 31bdeb7b83230a2025d43547368d75bc Boot ID: 267f264c448f000ea5aed47263c6de7f Operating System: Manjaro Linux Kernel: Linux 4.19.20-1-MANJARO Architecture: x86-64 method 2: use the nmcli command in Linux to change the hostname
Nmcli is a command-line tool designed to control NetworkManager and report the status of the network.
Nmcli is used to create, display, edit, delete, activate and log out network connections, as well as to control and display the status of network devices. In addition, it allows us to change the host name.
Use the following command to view the current hostname using nmcli.
$nmcli general hostnamedaygeek-Y700
Syntax format:
$nmcli general hostname [YOUR NEW HOSTNAME]
Use the following command to change the hostname with the help of the nmcli command. In this example, I will change the host name from daygeek-Y700 to magi-laptop.
$nmcli general hostname magi-laptop
It can take effect without rebooting the device, but for security purposes, you only need to restart the systemd-hostnamed service for the changes to take effect.
$sudo systemctl restart systemd-hostnamed
Run the same nmcli command again to check the changed hostname.
$nmcli general hostnamemagi-laptop method 3: use nmtui in Linux to change the hostname
Nmtui is a TUI application based on the curses library, which is used to interact with NetworkManager. When nmtui is started, if the previous command line argument to nmtui is not specified, it will remind the user to choose to perform an activity.
Run the following command in the terminal to open the text user interface.
$nmtui
Use the down arrow button to select the "Set system hostname" option, and then press enter.
The screenshot below shows the original hostname.
All we need to do is delete the original hostname, enter the new hostname, and then select "OK" and click enter to confirm it.
Then it will show you the updated hostname on the screen, select "OK" again and click enter to confirm that the change is complete.
Select the "Quit" button to leave the nmtui terminal interface.
It can take effect without restarting the device, but for security purposes, you need to restart the systemd-hostnamed service for the changes to take effect.
$sudo systemctl restart systemd-hostnamed
You can run the following command to see the updated hostname.
$hostnamectl Static hostname: daygeek-Y700 Icon name: computer-laptop Chassis: laptop Machine ID: 31bdeb7b83230a2025d43547368d75bc Boot ID: 267f264c448f000ea5aed47263c6de7f Operating System: Manjaro Linux Kernel: Linux 4.19.20-1-MANJARO Architecture: x86-64 method 4: use / etc/hostname in Linux to change the hostname
In addition to the above method, we can also modify the hostname by modifying the / etc/hostname file. But this method requires a server restart to take effect.
Use the following command to check the / etc/hostname file to see the current hostname:
$cat / etc/hostnamedaygeek-Y700
To change the hostname, just overwrite the file, because the file contains only the hostname.
$sudo echo "magi-daygeek" > / etc/hostname $cat / etc/hostnamemagi-daygeek
Then restart the system using the following command:
$sudo init 6
Check the contents of the / etc/hostname file to verify that the hostname has been changed.
$cat / etc/hostnamemagi-daygeek above is how to modify the host name in the Linux shared by the editor. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.