Network programming (6) IP protocol related technologies

1. DNS

Since IP addresses are not easy to remember, the TCP/IP world has had something called a host identifier from the very beginning . This identification method refers to assigning a unique host name to each computer, and the host name can be used directly during network communication without entering a long list of IP addresses. And at this time, the system must automatically convert the hostname to a specific IP address . To accomplish this, hosts often use a database file called hosts .

image.png

DNS system : A system that can effectively manage the correspondence between hostnames and IP addresses.

In this system, the management organization of the host can change and set the data. That is, it maintains a database that represents the correspondence between hostnames and IP addresses within an organization.

domain name

A domain name is a hierarchical name used to identify host names and organization names.

When using a domain name, you can append the organization's domain name to each host name. Organizations that have a domain name can set up their own sub-network. At this time, the sub-domain name should be between the host name and the domain name.

Example: The domain name of Kurashiki University of Arts and Sciences is as follows:

kusa.ac.jp

When there are hosts such as pepper, piyo, and kinoko, their complete host names with domain names will be in the following form:

pepper.kusa.ac.jp
piyo.kusa.ac.jp
kinoko.kusa.ac.jp

The domain name hierarchy is shown in the following figure:

image.png

As shown in the figure above, it is a tree structure, the vertex is the root (root), and the next layer of the vertex is called the first-level domain name (TLD: Top Level Domain). Under the jp domain name, there can also be many types of domain names. .

domain name server

The domain name server refers to the host and corresponding software that manage the domain name. It can manage the relevant information of the domain in which it is located. The layer it manages is called ZONE.

The DNS set at the root is called the root domain name server. It plays a vital role in DNS's function of retrieving data. The IP addresses of the tier-1 domain name servers below the root are registered in the root domain name server. Similarly, the IP addresses of the next-level domain name servers are registered in the next-level domain name servers of the root domain name server.

parser

进行DNS查询的主机和软件叫做DNS解析器。用户所使用的工作站或个人电脑都属于解析器。一个解析器至少要注册一个以上域名服务器的IP地址。通常,它至少包括组织内部的域名服务器的IP地址。

DNS查询

image.png

二、ARP

只要确定了IP地址,就可以向这个目标地址发送IP数据报。然而,在底层数据链路层,进行实际通信时却有必要了解每个IP地址所对应的MAC地址。

ARP(Address Resolution Protocol) 是一种解决地址问题的协议。以目标IP地址为线索,用来定位下一个应该接收数据分包的网络设备对应的MAC地址。如果目标主机不在同一个链路上时,可以通过ARP查找下一跳路由器的MAC地址。

不过ARP只适用于IPv4,不能用于IPv6。IPv6中可以用ICMPv6替代ARP发送邻居探索消息。

原理

主机A为了获得主机B的MAC地址,起初要通过广播发送一个ARP请求包。这个包中包含了想要了解其MAC地址的主机IP地址。由于广播的包可以被同一个链路上所有的主机或路由器接收,因此ARP的请求包也就会被这同一个链路上所有的主机和路由器进行解析。如果ARP请求包中的目标IP地址与自己的IP地址一致,那么这个节点就将自己的MAC地址塞入ARP响应包返回给主机A。

缺点:如果每发送一个IP数据报都要进行一次ARP请求以此确定MAC地址,那将会造成不必要的网络流量。

解决方案 :通常的做法是把获取到的MAC地址缓存一段时间。

IP地址和MAC地址是否缺一不可?

答案是肯定的。

在以太网上发送IP包时,“下次要经由哪个路由器发送数据报”这一信息非常重要。而这里的“下一个路由器”就是相应的MAC地址。没有MAC地址,则需要进行对MAC地址广播,会造成数据包重复发送。

IP可以通过路由控制快速的筛选,如果没有IP,则需要在全世界查找MAC地址。

RARP

RARP(Reverse Address Resolution Protocol)是将ARP反过来,从MAC地址定位IP地址的一种协议。例如将打印机服务器等小型嵌入式设备接入到网络时就经常会用得到。

对于使用嵌入式设备时,会遇到没有任何输入接口或无法通过DHCP动态获取IP地址的情况。在类似情况下,就可以使用RARP。

代理ARP

通常ARP包会被路由器隔离,但是采用代理ARP(Proxy ARP)的路由器可以将ARP请求转发给邻近的网段。由此,两个以上网段的节点之间可以像在同一个网段中一样进行通信。

在目前的TCP/IP网络当中,一般情况下用路由器连接多个网络时,会在每个网段上定义各自的子网,从而进行路由控制。然而,对于那些不支持设定子网掩码的老设备来说,不使用代理ARP,有时就无法更好地使用网络。

三、ICMP

架构IP网络时需要特别注意两点:确认网络是否正常工作,以及遇到异常时进行问题诊断。

ICMP正是提供这类功能的一种协议。

ICMP的主要功能包括,确认IP包是否成功送达目标地址,通知在发送过程当中IP包被废弃的具体原因,改善网络设置等。

ICMP的消息大致可以分为两类:一类是通知出错原因的错误消息,另一类是用于诊断的查询消息。

image.png

image.png

四、DHCP

为了实现自动设置IP地址、统一管理IP地址分配,就产生了DHCP(Dynamic Host Configuration Protocol)协议。有了DHCP,计算机只要连接到网络,就可以进行TCP/IP通信。也就是说,DHCP让即插即用变得可能。而DHCP不仅在IPv4中,在IPv6中也可以使用。

五、NAT

NAT (Network Address Translator) is a technology used to use private addresses in the local network and switch to global IP addresses when connecting to the Internet. In addition to converting IP addresses, NAPT (Network Address PortsTranslator) technology that can convert TCP and UDP port numbers has also emerged, so that a global IP address can be used to communicate with multiple hosts (usually people mentioned NAT, most of which are Refers to NAPT. NAPT is also called IP Masquerading or MultiNAT.).

NAT (NAPT) is actually a technology developed for IPv4 which is facing address exhaustion. However, in order to improve network security in IPv6, NAT is also used, and NAT-PT is often used in the mutual communication between IPv4 and IPv6.

6. IP tunnel

Networks A and B use IPv6. If network C in the middle position supports IPv4, direct communication between network A and network B will not be possible. In order to allow normal communication between them, the function of IP tunnel must be used at this time.

In the IP tunnel, the IPv6 packets sent from the network A can be combined into one data, and then an IPv4 header can be added to it and then forwarded to the network C.

Typically, the IP header is followed by the TCP or UDP header. However, there are more and more situations in current applications, such as "the IP header is followed by the IP header" or "the IP header is followed by the IPv6 header". This communication method in which the network layer header is added after the network layer header is called "IP tunneling".


The content of the article is excerpted from: Illustrated TCP/IP (Fifth Edition)

Guess you like

Origin juejin.im/post/7112617594644873230