Detailed explanation of hosts file configuration on Linux server

Detailed explanation of hosts file configuration on Linux server

Linux server hosts file configuration

The hosts file is a file in the Linux system that is responsible for the fast resolution of IP addresses and domain names. It is saved in the "/etc" directory in ASCII format and the file name is "hosts".

The hosts file contains the mapping between IP addresses and host names, as well as aliases for host names. In the absence of a domain name server, all network programs on the system resolve the IP address corresponding to a host name by querying this file, otherwise the DNS service program is required to resolve it. Usually you can add commonly used domain names and IP address mappings to the hosts file for quick and convenient access.

Below we introduce the method and steps to modify the hosts configuration file:

Required tools: vim/vi

1. Install vim editor

sudo apt install vim -y # debian

sudo yum install vim -y # readhat

2. Use an editor to modify the hosts file

1. sudo vim /etc/hosts

2. Press the i key to enter edit mode

The format of the hosts file is as follows:

IP address Host name/Domain name

Part 1: Network IP address;

Part 2: Host name or domain name;

Part 3: Hostname alias;

For example:

127.0.0.1 localhost.localdomain localhost

192.168.1.100 linmu100.com linmu100

192.168.1.120 ftpserver ftp120

3. Save after modification

Content Extension

Configure hosts file

This file can configure the host IP and the corresponding host name. Its role cannot be ignored for server-type Linux systems. On a local area network or the Internet, each host has an IP address, which distinguishes each host and enables communication based on the IP. But IP addresses are not easy to remember, so domain names came into being. In a local area network, each machine has a host name, which is used to distinguish hosts and facilitate mutual access.

The relevant configuration file for Linux host names is /etc/hosts; this file tells the host which domain names correspond to which IPs, and which host names correspond to which IPs:

For example, there is a definition in the file

192.168.1.100 linumu100 test100

Assuming that 192.168.1.100 is a website server, entering http://linumu100 or http://test100 in the web page will open the web page of 192.168.1.100.

Usually this file first records the local IP and host name:

127.0.0.1 localhost.localdomain localhost

This means that when we are debugging a web project, we clearly enter localhost in the address bar of the browser, and it will know that we are debugging locally because it is mapped to 127.0.0.1 (that is, the local machine).

The above are all the knowledge points introduced this time. Thank you for your learning and support for 123WORDPRESS.COM.

You may also be interested in:
  • Detailed introduction to modifying etc/hosts file in Linux
  • Detailed explanation and configuration of hosts file under Linux system
  • script_tool_for_linux.bash: One-click deployment script for hosts in Linux environment

<<:  Steps to initialize the password after the first successful installation of MySQL

>>:  Introduction to general_log log knowledge points in MySQL

Recommend

A complete example of implementing a timed crawler with Nodejs

Table of contents Cause of the incident Use Node ...

CSS3 uses animation attributes to achieve cool effects (recommended)

animation-name animation name, can have multiple ...

Which loop is the fastest in JavaScript?

Knowing which for loop or iterator is right for o...

Blog Design Web Design Debut

The first web page I designed is as follows: I ha...

Use CSS to set the width of INPUT in TD

Recently, when I was using C# to make a Web progra...

VMware15 installation of Deepin detailed tutorial (picture and text)

Preface When using the Deepin user interface, it ...

js to achieve waterfall flow layout (infinite loading)

This article example shares the specific code of ...

Description of the default transaction isolation level of mysql and oracle

1. Transaction characteristics (ACID) (1) Atomici...

How to configure the Runner container in Docker

1. Create a runner container mk@mk-pc:~/Desktop$ ...

Detailed explanation of MySQL from getting started to giving up - installation

What you will learn 1. Software installation and ...

Two problems encountered when deploying rabbitmq with Docker

1. Background The following two problems are enco...

JS implements a stopwatch timer

This article example shares the specific code of ...

Comparison of two implementation methods of Vue drop-down list

Two implementations of Vue drop-down list The fir...

JavaScript imitates Jingdong carousel effect

This article shares the specific code for JavaScr...