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

Docker installs Elasticsearch7.6 cluster and sets password

Starting from Elasticsearch 6.8, free users are a...

mysql-8.0.17-winx64 deployment method

1. Download mysql-8.0.17-winx64 from the official...

Echart Bar double column chart style most complete detailed explanation

Table of contents Preface Installation and Config...

The viewport in the meta tag controls the device screen css

Copy code The code is as follows: <meta name=&...

VMware Workstation 14 Pro installation Ubuntu 16.04 tutorial

This article records the specific method of insta...

Win10 install Linux ubuntu-18.04 dual system (installation guide)

I installed a Linux Ubuntu system on my computer....

Detailed explanation of how to cleanly uninstall Docker

First, the server environment information: Reason...

Why can't my tomcat start?

Table of contents Phenomenon: Port usage: Spellin...

Solution for Docker Swarm external verification load balancing not taking effect

Problem Description I created three virtual machi...

WeChat applet date and time component (year, month, day, hour, and minute)

This article example shares the specific code of ...

HTML exceeds the text line interception implementation principle and code

The HTML code for intercepting text beyond multipl...

In-depth understanding of MySQL long transactions

Preface: This article mainly introduces the conte...