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

Vue front-end development auxiliary function state management detailed example

Table of contents mapState mapGetters mapMutation...

VUE + OPENLAYERS achieves real-time positioning function

Table of contents Preface 1. Define label style 2...

Ubuntu 20.04 sets a static IP address (including different versions)

Because Ubuntu 20.04 manages the network through ...

Vue3 slot usage summary

Table of contents 1. Introduction to v-slot 2. An...

Mysql some complex sql statements (query and delete duplicate rows)

1. Find duplicate rows SELECT * FROM blog_user_re...

JavaScript realizes the effect of mobile modal box

This article example shares the specific code of ...

JavaScript implements asynchronous submission of form data

This article example shares the specific code of ...

Detailed steps to install MySQL 5.7 via YUM on CentOS7

1. Go to the location where you want to store the...

A simple method to regularly delete expired data records in MySQL

1. After connecting and logging in to MySQL, firs...

border-radius method to add rounded borders to elements

border-radius:10px; /* All corners are rounded wi...

CentOS method to modify the default ssh port number example

The default ssh port number of Linux servers is g...

Detailed tutorial on installing Nginx 1.16.0 under Linux

Because I have been tinkering with Linux recently...

Detailed explanation of the use of Vue Smooth DnD, a draggable component of Vue

Table of contents Introduction and Demo API: Cont...

CSS multi-level menu implementation code

This is a pretty cool feature that makes web page...