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 Ubuntu in Linux

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

In this issue, the editor will bring you about how to modify the host name of Ubuntu 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.

Ubuntu modifies hostname referenc

In CentOS7, there are three defined hostnames:

1. Static (Static hostname)

The "static" hostname, also known as the kernel hostname, is the hostname that the system initializes automatically from / etc/hostname at startup.

two。 Transient Tansient hostname

A "transient" hostname is a hostname temporarily assigned while the system is running, for example, through a DHCP or mDNS server.

3. Flexible (Pretty hostname)

The "flexible" host name is also known as the "alias" host name.

"flexible" hostnames allow the use of free-form hostnames (including special / white space characters) to display to end users, such as xh01@f5.

Both "static" hostnames and "transient" hostnames follow the same character restrictions as Internet domain names.

In CentOS 7, there is a command-line tool called hostnamectl that allows you to view or modify configurations related to hostnames.

View the hostname:

Hostnamectl takes a look at the current hostname and looks at all three hostnames

Hostnamectl status or, check all three hostnames

View only static, transient, or flexible hostnames, using the-- static,--transient or-- pretty options, respectively

Or, what you see is a Tansient hostname hostname.

/ / or check the hostname configuration file and see the static (Static hostname) cat / etc/hostname

View information about the current Linux operating system (kernel version number, hardware architecture, host name, operating system type, etc.):

Uname-a / / what you see is transient (Tansient hostname)

Cat / etc/redhat-release / / View the operating system environment

Modify hostname: method 1: temporarily valid

Hostname hostname / / A hostname that can only be temporarily modified. When the machine is rebooted, the hostname changes back.

Hostname sowhat method 2: permanently effective

/ / permanently modify the host name, which can be maintained after restart.

Hostnamectl set-hostname sowhat / / permanently modify the host name, which can be maintained after restart. / / Delete hostnamehostnamectl set-hostname "" hostnamectl set-hostname ""-- statichostnamectl set-hostname "--pretty

Modify all three hostnames: static, transient, and flexible:

[root@localhost] # hostnamectl set-hostname sowhat [root@localhost ~] # hostnamectl-- pretty [root@localhost ~] # hostnamectl-- staticxh00 [root@localhost ~] # hostnamectl-- transientxh00

As shown above, when you modify a static / transient hostname, any special or white space characters are removed, and any uppercase letters in the supplied parameters are automatically converted to lowercase.

Once the static hostname is modified, / etc/hostname will be updated automatically. However, / etc/hosts will not be updated to save your changes, so be sure to manually update / etc/hosts every time you change the hostname, and then restart CentOS 7. Otherwise, the system will be slow to restart.

Manual update / etc/hosts

Vim / etc/hosts

# 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4127.0.0.1 sowhat#::1 localhost localhost.localdomain localhost6 localhost6.localdomain6::1 sowhat

Restart CentOS 7

Reboot-f

After restart

[root@qqmm ~] # hostnamesowhat [root@qqmm ~] # hostnamectlsowhat

If you only want to change a specific hostname (static, transient, or flexible), you can use the-- static,--transient or-- pretty options. For example, to permanently change the hostname, you can modify the static hostname:

[root@localhost ~] # hostnamectl-- after static set-hostname sowhat restarts CentOS 7 [root@localhost ~] # hostnamectl-- staticsowhat [root@localhost ~] # hostnamectl-- transientsowhat [root@localhost ~] # hostnamectl-- pretty [root@localhost ~] # hostnamesowhat

In fact, you don't have to restart the machine to activate permanent hostname changes. The above command immediately modifies the kernel hostname, logs out and logs back in to observe the new static hostname at the command line prompt

Reference article: https://www.jianshu.com/p/39d7000dfa47

Method 3: take effect permanently

Modify the configuration file / etc/hostname to modify the hostname. Replace the name in the file content hostname name with the hostname you want to restart.

Vim / etc/hostname

Hostname sowhat

Method 4: permanently take effect through nmtui modification, then restart hostnamed

Nmcli general hostname sowhatsystemctl restart systemd-hostnamed

You can also change the hostname by entering the graphical interface through nmtui. Move the cursor through the up and down keys of the keyboard to the set system Hostname menu and press enter.

At this point, the "set hostname" tab appears on the screen, enter the hostname to be set, move the cursor to "OK" through the keyboard key, and enter to confirm the modification of the hostname.

This is how the Ubuntu in the Linux shared by the editor modifies the host name. 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: 276

*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

Internet Technology

Wechat

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

12
Report