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

Index in MySQL

Preface Let's get straight to the point. The ...

Docker builds python Flask+ nginx+uwsgi container

Install Nginx First pull the centos image docker ...

Analysis of the process of building a cluster environment with Apache and Tomcat

In fact, it is not difficult to build an Apache c...

Docker installs the official Redis image and enables password authentication

Reference: Docker official redis documentation 1....

Vue.js performance optimization N tips (worth collecting)

Table of contents Functionalcomponents Childcompo...

Introduction to the use of MySQL source command

Table of contents Thoughts triggered by an online...

Uniapp's experience in developing small programs

1. Create a new UI project First of all, our UI i...

Node.js returns different data according to different request paths.

Table of contents 1. Learn to return different da...

20 JavaScript tips to help you improve development efficiency

Table of contents 1. Declare and initialize array...

Steps of an excellent registration process

For a website, it is the most basic function. So l...

js to achieve simple calendar effect

This article shares the specific code of js to ac...

Detailed example of jQuery's chain programming style

The implementation principle of chain programming...

How to use js to communicate between two html windows

Scenario: When page A opens page B, after operati...