Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed explanation on the configuration of hosts files on linux server

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Linux server hosts file configuration

Hosts file is a file responsible for rapid resolution of IP address and domain name in Linux system. It is saved in "/ etc" directory in ASCII format, and the file name is "hosts".

The hosts file contains the mapping between IP addresses and hostnames, as well as aliases for hostnames. 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 the file, otherwise they need to use DNS service programs to solve the problem. Usually, the commonly used domain name and IP address mapping can be added to the hosts file to achieve fast and convenient access.

Let's introduce the methods and steps to modify the hosts configuration file:

Required tools: vim/vi

1. Install the vim editor

Sudo apt install vim-y # debiansudo yum install vim-y # readhat

2. Modify the hosts file using the editor

1. Sudo vim / etc/hosts

two。 Press the I key to enter edit mode

The format of the hosts file is as follows:

IP address hostname / domain name

Part I: network IP address

Part II: hostname or domain name

Part III: host name alias

For example:

127.0.0.1 localhost.localdomain localhost192.168.1.100 linmu100.com linmu100192.168.1.120 ftpserver ftp120

3. Save after the modification is completed.

Content expansion

Configure the hosts file

This file can configure the host ip and the corresponding hostname, and its role for server-type linux systems can not be ignored. On a local area network or INTERNET, each host has an IP address, which distinguishes each host and can communicate according to the ip. But the IP address is not easy to remember, so there is a domain name. In a local area network, each machine has a hostname, which is used to distinguish between hosts and facilitate mutual access.

The configuration file for Linux hostnames is / etc/hosts;. This file tells the host which domain names correspond to those ip and which hostnames correspond to which ip:

For example, there is such a definition in the file.

192.168.1.100 linumu100 test100

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

Typically, this file first records the ip and hostname of the machine:

127.0.0.1 localhost.localdomain localhost

This is when we were debugging the web project, we clearly entered localhost in the browser's address bar, he will know that we are local debugging, because he mapped to 127.0.0.1 (that is, native).

These are all the knowledge points of this introduction. Thank you for your study and support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report