1 / 24

DNS Introduction

DNS Introduction. 主讲:孟宁 电话:0512-68839302 E-mail:mengning@ustc.edu.cn 主页:http://staff.ustc.edu.cn/~mengning 地址:苏州工业园区独墅湖高等教育区仁爱路166号明德楼A302室. 2010年12月. DNS 的基本概念. 域名系统( DNS )是一种用于 TCP/IP 应用程序的分布式数据库,它 提供主机名字和I P地址之间的转换 及有关电子邮件的选路信息。 DNS 提供了允许服务器和客户程序相互通信的协议。. DNS 的基本原理.

sadah
Download Presentation

DNS Introduction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. DNS Introduction 主讲:孟宁 电话:0512-68839302 E-mail:mengning@ustc.edu.cn 主页:http://staff.ustc.edu.cn/~mengning 地址:苏州工业园区独墅湖高等教育区仁爱路166号明德楼A302室 2010年12月

  2. DNS的基本概念 • 域名系统(DNS)是一种用于TCP/IP应用程序的分布式数据库,它提供主机名字和I P地址之间的转换及有关电子邮件的选路信息。 • DNS提供了允许服务器和客户程序相互通信的协议。

  3. DNS的基本原理 • 从应用的角度上看,对D N S的访问是通过一个地址解析器( resolver)来完成的。 • 在Unix主机中,该解析器主要是通过两个库函数gethostbyname 和gethostbyaddr来访问的,它们在编译应用程序时与应用程序连接在一起。前者接收主机名字返回I P地址,而后者接收I P地址来寻找主机名字。 • 解析器通过一个或多个名字服务器来完成这种相互转换。

  4. DNS的基本原理 • 在一个应用程序请求T C P打开一个连接或使用U D P发送一个数据报之前。心须将一个主机名转换为一个I P地址。 • 操作系统内核中的T C P / I P协议族对于D N S一点都不知道。

  5. 顶级域名被分为三个部分 • 1) a r p a是一个用作地址到名字转换的特殊域。 • 2) 7个3字符长的普通域。有些书也将这些域称为组织域。 • 3) 所有2字符长的域均是基于I S O 3 1 6 6中定义的国家代码,这些域被称为国家域,或地理域。

  6. 7个3字符长的普通域

  7. DNS查询和响应的一般格式

  8. DNS查询和响应的一般格式

  9. 如何存储域名gemini.tuc.noao.edu

  10. Example sw2@sw2-desktop:~/mylesson/np$host www.ustc.edu.cn www.ustc.edu.cn has address 202.38.64.9 sw2@sw2-desktop:~/mylesson/np$host 202.38.64.9 Host 9.64.38.202.in-addr.arpa. not found: 3(NXDOMAIN) sw2@sw2-desktop:~/mylesson/np$host www.ustcsz.edu.cn www.ustcsz.edu.cn has address 219.219.223.20 sw2@sw2-desktop:~/mylesson/np$host 219.219.223.20 20.223.219.219.in-addr.arpa domain name pointer www.ustcsz.edu.cn. sw2@sw2-desktop:~/mylesson/np$host www.ietf.org www.ietf.org has address 64.170.98.32 www.ietf.org has IPv6 address 2001:1890:1112:1::20 www.ietf.org mail is handled by 0 mail.ietf.org. sw2@sw2-desktop:~/mylesson/np$host 64.170.98.32 32.98.170.64.in-addr.arpa domain name pointer mail.ietf.org.

  11. 主机名字转换成I P地址(A记录查询) sw2@sw2-desktop:~/mylesson/np$ host www.ustcsz.edu.cn www.ustcsz.edu.cn has address 219.219.223.20 IP 192.168.90.229.58717 > 219.219.223.10.53: 7284+ A? www.ustcsz.edu.cn. (35) IP 219.219.223.10.53 > 192.168.90.229.58717: 7284* 1/2/2 A 219.219.223.20 (119) IP 192.168.90.229.37888 > 219.219.223.10.53: 49757+ AAAA? www.ustcsz.edu.cn. (35) IP 219.219.223.10.53 > 192.168.90.229.37888: 49757* 0/1/0 (81) IP 192.168.90.229.60351 > 219.219.223.10.53: 7156+ MX? www.ustcsz.edu.cn. (35) IP 219.219.223.10.53 > 192.168.90.229.60351: 7156* 0/1/0 (81)

  12. 主机名字转换成I P地址(A记录查询) sw2@sw2-desktop:~/mylesson/np$ host www.ietf.org www.ietf.org has address 64.170.98.32 www.ietf.org has IPv6 address 2001:1890:1112:1::20 www.ietf.org mail is handled by 0 mail.ietf.org. IP 192.168.90.229.36480 > 219.219.223.10.53: 11445+ A? www.ietf.org. (30) IP 219.219.223.10.53 > 192.168.90.229.36480: 11445 1/6/2 A 64.170.98.32 (239) IP 192.168.90.229.44438 > 219.219.223.10.53: 1423+ AAAA? www.ietf.org. (30) IP 219.219.223.10.53 > 192.168.90.229.44438: 1423 1/6/2 AAAA[|domain] IP 192.168.90.229.56146 > 219.219.223.10.53: 7633+ MX? www.ietf.org. (30) IP 219.219.223.10.53 > 192.168.90.229.56146: 7633 1/6/4 MX mail.ietf.org. 0 (288)

  13. I P地址转换成主机名字(PTR指针查询) sw2@sw2-desktop:~/mylesson/np$ host 219.219.223.20 20.223.219.219.in-addr.arpa domain name pointer www.ustcsz.edu.cn. IP 192.168.90.229.42966 > 219.219.223.10.53: 31376+ PTR? 20.223.219.219.in-addr.arpa. (45) IP 219.219.223.10.53 > 192.168.90.229.42966: 31376* 1/2/2 (144)

  14. I P地址转换成主机名字(PTR指针查询) sw2@sw2-desktop:~/mylesson/np$ host 64.170.98.32 32.98.170.64.in-addr.arpa domain name pointer mail.ietf.org. IP 192.168.90.229.56835 > 219.219.223.10.53: 53263+ PTR? 32.98.170.64.in-addr.arpa. (43) IP 219.219.223.10.53 > 192.168.90.229.56835: 53263 1/4/0 (150)

  15. gethostbyname的用法 • 使用这个东西,首先要包含2个头文件: • #include <netdb.h> • #include <sys/socket.h> • struct hostent *gethostbyname(const char *name);这个函数的传入值是域名或者主机名,例如"www.ustcsz.edu.cn"等。传出值,是一个hostent的结构。如果函数调用失败,将返回NULL。

  16. hostent的结构 struct hostent { char *h_name; /*主机的规范名*/ char **h_aliases;/*主机的别名*/ /*主机ip地址的类型,到底是ipv4(AF_INET),还是ipv6(AF_INET6)*/ int h_addrtype; int h_length;/*主机ip地址的长度*/ char **h_addr_list;/*主机的ip地址,是以网络字节序存储的*/ };

  17. #include <netdb.h> • #include <sys/socket.h> • int main(int argc, char **argv) • { • char *ptr,**pptr; • struct hostent *hptr; • char str[32]; • /* 取得命令后第一个参数,即要解析的域名或主机名 */ • ptr = argv[1]; • /* 调用gethostbyname()。调用结果都存在hptr中 */ • if( (hptr = gethostbyname(ptr) ) == NULL ) • { • printf("gethostbyname error for host:%s\n", ptr); • return 0; /* 如果调用gethostbyname发生错误,返回1 */ • } • /* 将主机的规范名打出来 */ • printf("official hostname:%s\n",hptr->h_name); • /* 主机可能有多个别名,将所有别名分别打出来 */ • for(pptr = hptr->h_aliases; *pptr != NULL; pptr++) • printf(" alias:%s\n",*pptr);

  18. /* 根据地址类型,将地址打出来 */ • switch(hptr->h_addrtype) • { • case AF_INET: • case AF_INET6: • pptr=hptr->h_addr_list; • /* 将刚才得到的所有地址都打出来。其中调用了inet_ntop()函数 */ • for(;*pptr!=NULL;pptr++) • printf(" address:%s\n", inet_ntop(hptr->h_addrtype, *pptr, str, sizeof(str))); • break; • default: • printf("unknown address type\n"); • break; • } • return 0; • }

  19. DNS体系的内部实现 • DNS用UDP还是用TCP? • 查询请求超过512字节 • 辅助名字服务器与主名字服务器之间的区域传送 • DNS服务器做了什么? • 递归查询 • DNS根服务器

  20. host.example.microsoft.com

  21. host.example.microsoft.com • 首先,首选服务器分析全名并确定对于顶级域com具有绝对控制权的服务器的位置。随后,对com DNS 服务器使用迭代查询,以获取microsoft.com服务器的参考信息。然后参考性应答从microsoft.com服务器传送到example.microsoft.com的 DNS 服务器。最后,与服务器 example.microsoft.com 联系上。因为该服务器包括作为其配置区域一部分的查询名称,所以,它向启动递归的源服务器作出权威性的应答。当源服务器接收到表明已获得对请求查询的权威性应答的响应时,它将此应答转发给发出请求的客户机,这样,递归查询过程就完成了。

  22. Example:ustcsz.edu.cn

  23. 谢谢大家!

More Related