Skip to content

Commit 99b0f66

Browse files
committed
DNS解析
1 parent c7dd91b commit 99b0f66

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

note/URLConnection/urlconnection.md

+47-1
Original file line numberDiff line numberDiff line change
@@ -302,4 +302,50 @@ public synchronized void print(PrintStream p) {
302302

303303
# 响应解析
304304

305-
其实就是获得输入流逐行解析的过程,不再向下展开。
305+
其实就是获得输入流逐行解析的过程,不再向下展开。
306+
307+
# DNS解析
308+
309+
触发DNS解析的时机是HttpClient的New方法,默认的实现是Inet4AddressImpl的lookupAllHostAddr方法:
310+
311+
```java
312+
public native InetAddress[]
313+
lookupAllHostAddr(String hostname) throws UnknownHostException;
314+
```
315+
316+
native实现其实调用的是Linux的**getaddrinfo系统**调用,当然JDK在java层面也有对解析结果的缓存。
317+
318+
如何查看Linux的DNS服务器地址呢?
319+
320+
- 配置文件
321+
322+
```shell
323+
cat /etc/resolv.conf
324+
```
325+
326+
结果如下:
327+
328+
```html
329+
nameserver 10.0.0.2
330+
```
331+
332+
- nslookup:
333+
334+
```shell
335+
nslookup baidu.com
336+
```
337+
338+
结果:
339+
340+
```html
341+
Server: 10.0.0.2
342+
Address: 10.0.0.2#53
343+
344+
Non-authoritative answer:
345+
Name: baidu.com
346+
Address: 220.181.57.216
347+
Name: baidu.com
348+
Address: 123.125.115.110
349+
```
350+
351+
所以DNS便是10.0.0.2

0 commit comments

Comments
 (0)