DNS Access Unavailable: Troubleshooting Guid

1. Overview of DNS Access Unavailable Issues

In the context of troubleshooting DNS Access Unavailable issues, my job involves simulating various real-life failures, including network packet loss, latency, and resource saturation. Recently, while reviewing the “DNS Access Unavailable” feature, I discovered unexpected behaviors that prompted a deeper examination of its implementation. This guide will explore how I set up the function to modify the /etc/hosts file and the complications that can arise, leading to potential misconfigurations that prevent the intended outcome.

For example, if you want to implement www.baidu.coma situation where access is unavailable, you can do this:

As a result, when you access it through a browser or terminal using curl www.baidu.com, an error will be reported.

DNS Access Unavailable
Domain name access is unavailable

The problem I encountered is that in some cases, even if I made the above settings, the result was still accessing Baidu’s server instead of the one I set 127.0.0.1.

pingThe following will discuss go-httptwo failure scenarios, the failure phenomenon capture and the causes.

2. Understanding DNS Access Unavailable Functionality

2.1、Reproducing DNS Access Unavailable Scenarios

Our goal is to www.baidu.commap it locally local 127.0.0.1.

Before modifying /etc/hoststhe file, we first runping www.baidu.com

Without interrupting the above ping command , domain name access is unavailable ( /etc/hostsfile modification 127.0.0.1 www.baidu.com #chaosblade).

After modifying /etc/hoststhe file, ping www.baidu.comthe result found has not changed from 110.242.68.4.

But at this time, open another terminal and run it ping www.baidu.com, and find that it is in line with expectations!

Is pingthere a cache in the implementation?

2.2 Analyzing Ping Results When DNS Access Is Unavailable

In fact, it depends on pingthe implementation principle of the command

ping implement ​github.com/iputils/iputils/blob/master/ping/ping.c#L656

How ping works

After interpreting the source code, pingthe implementation is as follows: before entering the continuous sending of icmpdata packets, the domain name specified by the user will only be resolved once. Therefore, in pingthe process, even if hoststhe file is modified, the running pingprocess is not aware of it.

3. HTTP Request Failures: DNS Access Unavailable

3.1 Problem Recurrence

Later I discovered that a similar situation occurred when gomaking a request.httpping

For example, in the following example, a request for the 50secondary www.baidu.comhomepage is made http get, and the interval between each request is 3s. During the program running, modify /etc/hoststhe file to see if the request can be made and the response can be received normally.

Packet capture display 1: Details

http request

Packet capture display 2: Statistics

http statistics

It was found that the library did not point tohosts the file because it was changed .gohttpwww.baidu.comIP127.0.0.1

3.2 Troubleshooting

Through packet capture analysis, 50this httprequest uses long connection technology, because the source port is 58443, of course, this also conforms HTTP 1.1 persistent connectionto the characteristics.

You may have questions. Looking at the request header, there is no setting HTTPindicating a long connection .persistent connection

Indeed, no, but this is only because HTTP/1.1persistent connections are enabled by default.

3.3. Other ways to reproduce

The above gocode needs to be run and the packet needs to be captured to confirm that httpthe request is a long connection. Therefore, even if the file is modified /etc/hosts, no new dnsquery is performed, resulting in the use dnsof the first query ipinstead of the setting 127.0.0.1.

Is there a way to know that dnsthe query was only performed once without capturing the packet? Of course.

We can use the standard libraryhttptrace

The output is as follows:

If you look at the above log information carefully, you will find the following facts:

1. Only one query was performed for 50each request , which was the root cause of the failure to modify the file as expected.httpdns/etc/hosts

2. Only httpwhen the connection is sent for the first time, a new underlying connection is created, and all subsequent requests reuse the previous underlying connection.

How do you know?

The fields GotConnyou see indicate a new connection and indicate reuse of the underlying connection.Reusedfalsetrue

Summary

When the operating system receives dnsa query request, it first checks whether the domain name to be queried /etc/hostshas a corresponding configuration in the file, otherwise it calls dnsthe service to perform a recursive query.

After modifying /etc/hoststhe file, we expect it to take effect immediately, and it does.

However, there are still some special cases where even if the file is modified, the changes in the file cannot reach these scenarios, such as the pingand described above http.

I think we can call it a caching problem.

Ahahaha, this is one of the two biggest problems in the world of computers:

  • name
  • cache
Click to rate this post!
[Total: 0 Average: 0]