文章目录
一、DNS系统
1、概念
- DNS域名系统(Domain Name system缩写DNS, Domain Name被译为域名)是因特网的一项核心服务, 它作为可以将域名和IP地址相互映射的一个分布式数据库;是应用层协议,是域名也是服务
- DNS使用的协议及端口号是TCP和UDP的53端口号
- TCP是用来做区域传送,多用于主从同步
在一个区中主DNS服务器从自己术机的数据文件中读取该区的DNS数据信息,而辅助DNS服务器则从区的主DNS服务器中读取该区的DNS数据信息 - UDP是用来做DNS解析的
FQON全称Fully Qualified Domain Name
即全城名:同时带有主机名和域名的名称
FQDN=Hostnane + DomainName
如: ww. baidu. com.
注意:最前面的一定是主机,最后一个点表示根域,通常是省略不写的,但实际上www. abc . com=www. abc. com.
2、作用
- 正向解析:根据域名查找对应的IP地址
- 反向解析:根据IP地址查找对应的城名(域名的反向解析不是很常用,只在一些特殊场合才会用到,比如可用于反垃圾邮件的验证。)
今天我们主要以实验的方式详细讲解正向解析的过程
3、域名系统是树形的域名树
首先DNS系统的分布式数据结构是树形,分为根域、顶级域、二层域、三层域或子域、主机名五个部分;具体看图1
例:www.sina.com.cn
从上往下,一层管理一层
- 根域:位于域名空间最顶层,一般用一个".“表示根域
- 顶级城:一般代表种类型的组织机构或国家地区, 比如com. cn. net, uk等
- 二级域::用来标明顶级域内的一个特定的组织。国家顶级域下面的二级域名由国家网络部门统一管理,比如baidu. taobao等
- 子域:二级域下所创建的各级域统称为子域,各个组织或用户可以自由申请注册自己的域名sina.com.cn
- 主机位:位于域名空间最下层,就是一台具体的计算机,比如www,mail等
每一级的城名长度限制是63个字符,域名总长度则不能超过253个字符
拓展小知识:
- 顶级域:
.com:盈利的组织,一般是盈利的企业申请
.net:网络公司
.org:民间团体组织;非盈利的
.edu:教育性,比如大学的网址
.cn:中国的
.uk:美国的
.gov:政府
.mil:军事
.hk:中国香港
… - 主机名:
mail:邮件
news:新闻
ftp:上传下载的类
4、工作原理
这里还是给大家画一个图,方便大家的理解
dns服务器经过了两个过程:
递归查询:客户端-域名服务器-ip;可以直接告诉准确结果的
迭代查询:从域名服务器-根域-二级域-服务器-三级域;无法直接告知,需要一层层查
具体解析过程如下:
- 看本机的缓存记录
- 查询hosts文件
- 查询dns域名服务器,交给dns域名服务器处理
- 域名服务器查看缓存:查询缓存表有直接返回结果,没有则进行下一步
- 域名服务器发送请求给根域:根域通过查看域名服务器请求的地址,告知顶级服务器可能会知道结果,让其去找顶级服务器
- 顶级域服务器:顶级域服务器返回三级域服务器可能会知道结果,让其去找三级域服务器
- 三级域服务器:三级域服务器返回二级域服务器可能会知道结果,让其去找二级域服务器
- 二级域服务器:二级域服务器查询主机位内的缓存表,发现是我的主机,把查询到的IP地址返回给本地域名服务器
- 本地域名服务器将结果记录到缓存,然后把域名和ip的对应关系返回给客户端
//1-3的过程称为递归查询;4-9的过程称为迭代查询