Get the App
SLTechnology News&Howtos  ›  Development  › 

How to view and modify hostname under Linux

Shulou Source: shulou.com Published: 2022-06-01 22:46:36 10月30日 Update

Editor to share with you how to view and modify hostname under Linux, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Hostname is the hostname used to identify a machine in the system. After logging in to the linux system, [root@izm5e9z5o9dc8yjs3vh6mhz], where @ is followed by the host name, you can determine the landing system by the host name.

Query hostname:

Uname-n

Hostname

[root@oldboy ~] # uname-noldboy [root@oldboy ~] # hostnameoldboy

The hostname of the Linux operating system is a kernel variable, and you can view the native hostname through the hostname command. You can also view it directly by cat / proc/sys/kernel/hostname.

[root@oldboy ~] # hostnameoldboy [root@oldboy ~] # cat / proc/sys/kernel/hostnameoldboy

The above two outputs have the same result.

Modify the hostname of the runtime Linux system, that is, there is no need to restart the system

The hostname command can set the hostname of the system, which takes effect immediately after running, but the changes will be lost after the system is rebooted. If you want to permanently change the hostname of the system, you need to modify the relevant settings file.

Set the hostname:

Temporary effect:

The default is to display the hostname set the hostname: hostname hostname

Hostname displays and sets hostname

Permanent effect:

Vim / etc/sysconfig/network; modifies hostname to the expected value; save and exit.

/ etc/sysconfig/network

Vim / etc/hosts; modifies or adds hostname, the IP address corresponding to the hostname. Save and exit.

/ etc/hosts

The service network restart; network restarts.

The above is all the contents of the article "how to View and modify hostname under Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Host system article content name command permanent login run same operating system not much variable can pass address most file is in more expected value Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Apple NVidia Linux Shulou Tech Info