How to permanently change the host name in Linux

How to permanently change the host name in Linux

If you want to change your host name, you can follow the steps below.

Using hostname

Using hostname command can only temporarily change our host name. When we restart, the host name will return to the original one.

# hostname newhostname

Enter hostname linux to change the host name to linux, and use uname -n command to view it.

這里寫圖片描述

At this time, our host name has changed, why is it still Peithon on the left? Try reopening a terminal, or if you are using Xshell, reopen the session again.

Modify the configuration file

If you want to permanently change your hostname, you need to follow the steps below

Modify the file /etc/sysconfig/network

這里寫圖片描述

Among them, mylinux is the host name to be set, then save and exit, restart the system and you will read the configuration file and set the host name to the new hostname.

If you do not want to restart the system at this point, you can use hostname mylinux to make a temporary change. In this way, even if you restart the system, the host name set in the configuration file read is the same as your hostname setting, which is equivalent to unchanged.

This completes the host name setting.

Hosts File

Generally, you do not need to modify the hosts file to change the host name. The /etc/hosts file provides a domain name resolution function, similar to DNS. Before the Linux system sends a domain name resolution request to the DNS server, it will query the /etc/hosts file. If there is a corresponding record in it, the record in the hosts will be used.

So if you want to change the host name, just modify the /etc/sysconfig/network file. However, if you want to use distributed, you need to bind the host name and IP together, then you need to modify the hosts file.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Detailed explanation of Linux host name modification command
  • How to change the host name in Linux
  • How to modify the network card name and host name in Linux
  • Detailed introduction to linux host name configuration

<<:  Implementation of Vue3 style CSS variable injection

>>:  Detailed tutorial on installing MySQL offline on CentOS7

Recommend

Vue uses Baidu Maps to realize city positioning

This article shares the specific code of Vue usin...

Linux uses iftop to monitor network card traffic in real time

Linux uses iftop to monitor the traffic of the ne...

MySQL complete collapse query regular matching detailed explanation

Overview In the previous chapter, we learned abou...

React+ts realizes secondary linkage effect

This article shares the specific code of React+ts...

Solution to ES memory overflow when starting docker

Add the jvm.options file to the elasticsearch con...

Detailed explanation of the usage of Object.assign() in ES6

Table of contents 2. Purpose 2.1 Adding propertie...

Realizing the effect of carousel based on jQuery

This article shares the specific code of jQuery t...

Installation and use tutorial of Elasticsearch tool cerebro

Cerebro is an evolution of the Elasticsearch Kopf...

Detailed explanation of MySQL Truncate usage

Table of contents MySQL Truncate usage 1. Truncat...

Detailed explanation of MySQL information_schema database

1. Overview The information_schema database is th...

Analysis of MySQL query sorting and query aggregation function usage

This article uses examples to illustrate the use ...

Usage instructions for the docker create command

The docker create command can create a container ...

Examples of vertical grid and progressive line spacing

New Questions Come and go in a hurry. It has been...