A brief analysis of Linux resolv.conf

A brief analysis of Linux resolv.conf

1. Introduction

resolv.conf is the configuration file of the Domain Name System Resolver (DNS Resolver) of various operating systems. Whenever a program needs to access other hosts on the Internet through a domain name, it needs to use the Resolver library function to convert the domain name into the corresponding IP before it can access it.

Note that the Domain Name System Resolver (DNS Resolver) is not an executable program, but a series of library functions in C language that are used to parse resolv.conf to obtain the IP corresponding to the domain name. For an explanation of Resolver, you can use man 3 resolver to view the help manual.

2. Configuration details

The configuration of resolv.conf mainly includes the following items:
(1) nameserver xxxx. Used to configure the DNS server. You can use multiple nameservers to specify multiple DNS servers.
(2) Search domain1 domain2 baidu.com. This option can be used to specify multiple domain names, separated by spaces or tabs. Its function is that when the accessed domain name cannot be resolved by DNS, the resolver will add the parameters specified by search to the domain name and re-request DNS until it is correctly resolved or the list of domain names specified by search is exhausted. for example:

#ping news
PING news.baidu.com (74.125.128.101) 56(84) bytes of data.
64 bytes from hg-in-f101.1e100.net (74.125.128.101): icmp_req=1 ttl=47 time=78.9 ms
64 bytes from hg-in-f101.1e100.net (74.125.128.101): icmp_req=2 ttl=47 time=63.6 ms

(3) domain mydomain.com. Used to define the local domain name. If search is not set, search defaults to the value of domain.
(4) sortlist IP/netmask IP. Allows to sort the domain results in a specific order. Its parameters are an IP or a mask-IP pair, the mask is optional, separated by a slash. for example:

sortlist 130.155.160.0/255.255.240.0 130.155.0.0

(5) options. Built-in variables used to configure the resolver, not commonly found in resolv.conf. The syntax format is as follows:

options [option] ...

The value of option is as follows:

ndots:[n]: Sets the minimum number of dots that a domain name must contain when calling res_query() to resolve the domain name
timeout:[n]: Set the timeout for waiting for the DNS server to return, in seconds. The default value is RES_TIMEOUT=5, see <resolv.h>
attempts:[n]: Sets the number of times the resolver initiates domain name resolution requests to the DNS server. The default value is RES_DFLRETRY=2, see <resolv.h>
rotate: Set RES_ROTATE in _res.options to access nameserver in round-robin mode to achieve load balancing
no-check-names: Set RES_NOCHECKNAME in _res.options to disable checking of incoming hostnames and email addresses for invalid characters, such as underscores (_), non-ASCII characters, or control characters.

3. Notes

(1) search and domain cannot coexist. If they exist at the same time, the one that appears last will prevail.
(2) A line starting with a semicolon (;) or a pound sign (#) is a comment line;
(3) Each configuration item must be on a separate line and start with a keyword, with spaces separating configuration values.

4. Examples

Below is the content of resolv.conf.

nameserver 202.102.192.68
nameserver 202.102.192.69
search qq.com baidu.com
options no-check-names
options attempts:1
options timeout:1

The above is a brief analysis of the details of Linux resolv.conf. For more information about Linux resolv.conf, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • Detailed explanation of the solution to resolv.conf being reset after CentOS restart
  • Solve the problem that modifying the DNS address directly in the /etc/resolv.conf file in Cent0S 6.7 does not take effect after restart

<<:  Native JS to implement image carousel JS to implement small advertising plug-in

>>:  MySQL data duplicate checking and deduplication implementation statements

Recommend

OpenLayers realizes the method of aggregate display of point feature layers

Table of contents 1. Introduction 2. Aggregation ...

Record the steps of using mqtt server to realize instant communication in vue

MQTT Protocol MQTT (Message Queuing Telemetry Tra...

How to get the height of MySQL innodb B+tree

Preface The reason why MySQL's innodb engine ...

CenterOS7 installation and configuration environment jdk1.8 tutorial

1. Uninstall the JDK that comes with centeros fir...

Basic operations of mysql learning notes table

Create Table create table table name create table...

MySQL Interview Questions: How to Set Up Hash Indexes

In addition to B-Tree indexes, MySQL also provide...

A simple LED digital clock implementation method in CSS3

This should be something that many people have do...

CSS sets Overflow to hide the scroll bar while allowing scrolling

CSS sets Overflow to hide the scroll bar while al...

Basic installation tutorial of mysql decompression package

Since I have changed to a new computer, all the e...

Tips on setting HTML table borders

For many people who are new to HTML, table <ta...

Example analysis of the page splitting principle of MySQL clustered index

This article uses an example to illustrate the pa...

How to create a virtual environment using virtualenv under Windows (two ways)

Operating system: windowns10_x64 Python version: ...

How to install Element UI and use vector graphics in vue3.0

Here we only focus on the installation and use of...

Complete steps to install boost library under linux

Preface The Boost library is a portable, source-c...