Skip to content

Commit aa38c78

Browse files
hello dns
1 parent 693160e commit aa38c78

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
layout: post
3+
title: DNS 基础
4+
date: 2019-03-23
5+
author: JY
6+
header-img: img/cat0_dns.jpeg
7+
catalog: true
8+
tags:
9+
- DNS
10+
- 计算机网络
11+
---
12+
13+
# DNS简介
14+
tcp/ip协议是基于ip来寻找目标host的。但是其实在我们的日常使用中通常用到的都地址(比如www.baidu.com)。这时候比如我们想要ping www.baidu.com的时候当前主机会先使用dns协议向当前操作系统上面配置的dns server发起一个请求,最终查询到ip地址之后再使用tcp/ip发送icmp的报文。
15+
16+
17+
#### 关于地址
18+
工作的时候我用到最多的当然是http协议。比如在看到这个url [https://xxxx/path0/path1]()的时候不知道大家管xxxx叫什么的。有的人叫它hostname,有的叫domain。到了cloud部门之后也有人叫它cname,FQDN的。虽然都能听懂,但是偶尔心中会有疑惑,这些名字真的都是代表同一个意思吗?在这里就直接贴google上的答案了
19+
20+
>A fully qualified domain name (FQDN) contains both a host name and a domain name. For a landing page, the fully qualified domain name usually represents the full URL or a major portion of the top-level address.
21+
22+
>In looking at a fully qualified domain name, the host name typically comes before the domain name. The host name represents the network or system used to deliver a user to a certain address or location. The domain name represents the site or project that the user is accessing.
23+
24+
>One example is the use of various networks to access educational websites. Typically, the domain name will consist of the identifier for a specific school’s web domain, along with the top-level .edu suffix. For example, the domain name for America University would be americauniversity.edu. The host name would consist of either "www" where the global internet is the host, or some proprietary network name that represents the host – for example, if the school uses a custom internal network called "myAUnet" then "myAUnet" would be the host name.
25+
26+
>In connecting to a host, using the fully qualified domain name shows where the user wants to go. A DNS server can resolve the host name to an IP address. Although there is some syntactical tolerance built into the use of a fully qualified domain name, generally, a user can have errors or problems if the domain name is not clearly and completely entered.
27+
28+
29+
简单来说FQDN=hostname + domain。由此可见一个FQDN是分为多个段的,这样设计的好处就是我们可以通过hierarchy的方式来解析授权域名。具体见下面。
30+
31+
#### 地址是如何被解析的
32+
如果把所有的public dns服务器看成一棵树的话。那顶级dns(TLD)就是处在树的顶端的节点。所有的地址都可以先通过它来解析。在这里我直接用dig命令来展示地址是如何被解析的
33+
![digTraceBaidu](img/dnsTraceBaidu.png)
34+
先看前面13条NS记录
35+
它展示了所有root dns server的名字。NS记录的作用是记录domain(第一列)应该由哪一个nameserver来负责解释。找到了名字之后只需要找对应的A记录就可以知道应该去哪一个ip是负责解释当前domain的了。顺便一提,这13台dns的地址是固定的,配置在本地的os里面。找到了root dns server之后我们就要从root dns server中知道.com这个一级域名是那些服务器来解析的,大家可以看到15条NS记录表名了这些namserver是root dns server授权给他们让他们来负责解析所有.com的域名的。本机会同时向所有的nameserver发送dns报文(基于udp协议),然后会采纳最先返回的dns信息。剩下的事情就是以此类推最终找到www.baidu.com,h.gtld-servers.net这台name server上面有一条CNAME记录了www.baidu.com指向了www.a.shifen.com这个FQDN,也就是说www.baidu.com是www.a.shifen.com的别名,具体的ip地址就可以在A记录上面被看到。
36+
37+
38+
#### 那所有请求岂不是都要通过root dns server吗
39+
当然不是,每一台机器都会配置dns server。这台server可以配置多个[zone](https://en.wikipedia.org/wiki/DNS_zone)。通常情况下,dns请求会先发送到网络运营商的name server解析,解析不出来的时候才会去root dns server逐层查询。name server上的dns记录通常是以文件的形式存在服务器上的,这也就以为着服务器管理员可以随意修改上面的记录。这样运营商或者企业想要屏蔽一些网站的时候就可以使用改dns数据的方式啦,嘿嘿。
40+
41+
#### dns server type
42+
一台dns server可以解析多个zone。他们在解析不同zone的时候扮演了不同的角色。随手在百度上面找了一篇文章,我觉得已经解释得比较清楚了这里就不做赘述 [http://dns-learning.twnic.net.tw/bind/intro5.html](http://dns-learning.twnic.net.tw/bind/intro5.html)
43+
44+
#### 动手搭一台dns server
45+
使用了virtual box上面创建的ubuntu 16.04的vm。用的是网桥模式,vm的地址是192.168.1.11
46+
安装
47+
```
48+
sudo apt-get bind9
49+
cd /etc/bind
50+
```
51+
在name.conf配置zone信息
52+
```
53+
zone "jiyuan.com" IN {
54+
type master;
55+
file "/etc/bind/master/jiyuan.com";
56+
};
57+
```
58+
创建文件jiyuan.com
59+
```
60+
;
61+
; BIND data file for local loopback interface
62+
;
63+
$TTL 604800
64+
@ IN SOA jiyuan.com. jiyuan.jiyuan.com. (
65+
2 ; Serial
66+
604800 ; Refresh
67+
86400 ; Retry
68+
2419200 ; Expire
69+
604800 ) ; Negative Cache TTL
70+
;
71+
@ IN NS jiyuan.com.
72+
@ IN A 192.168.22.24
73+
@ IN AAAA ::1
74+
75+
www IN A 192.168.22.25
76+
```
77+
重启dns服务
78+
```
79+
service bind9 restart
80+
```
81+
在宿主机上面验证一下
82+
```
83+
dig jiyuan.com @192.168.1.11
84+
```
85+
这时输出的ip地址应该是192.168.22.24。

0 commit comments

Comments
 (0)