基于 OSI 模型的数据包如何通过 Internet 从一台计算机传输到另一台计算机 [英] How does a packet travel from one computer to another over the Internet based on OSI model

查看:70
本文介绍了基于 OSI 模型的数据包如何通过 Internet 从一台计算机传输到另一台计算机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我熟悉基本的 OSI 模型,但我总是感到困惑,数据包如何通过 Internet 从一台机器传输到另一台机器,以及哪些 OSI 层会出现在画面中?例如,对于以下拓扑:

I am familiar with the basic OSI model but I always get confused how does a packet travel from one machine to another over the Internet and what OSI layers do come into picture? For example, for the following topology:

机器A<----->交换机<---->路由器<---->路由器<---->路由器<---->交换机<---->机器B

Machine A<----->Switch<---->Router<---->Router<---->Router<---->Switch<---->Machine B

其中显示多个路由器代表 Internet,当机器 A 向机器 B 发送数据包(例如通过 FTP 的简单ls"命令)时,OSI 层会发生什么.

where the multiple routers are shown to represent the Internet, what happens at the OSI layer level, when Machine A send a packet (say a simple "ls" command over FTP) to Machine B.

以上只是一个建议的例子,但如果有人可以用任何其他网络拓扑来解释,那也很好.我只是在寻找一个非常基本的解释,说明数据包如何在每个节点(机器、交换机、路由器等)转换到不同的 OSI 层.

The above is just a suggested example, but if any one can explain with any other network topology, that is fine too. All I am looking a very basic explanation of how the packet gets transformed to different OSI layers at each nodes (Machine, Switch, Router, etc.).

推荐答案

路由器使用 IP 层(第 3 层),而交换机使用数据链路层(第 2 层).第 1 层是通过线路的物理 1 和 0,第 2 层是数据链路层,它是以太网和点对点协议 (PPP) 等协议,它在相邻节点之间传送有关来自和并允许错误检测和重传.第 3 层是 IP 层,它携带有关数据包来自和到达的整个网络中的位置的信息,而不仅仅是当前的跃点.

Routers use the IP layer (layer 3) and switches use the data-link layer (layer 2). Layer 1 is the physical 1s and 0s that go over a wire, Layer 2 is the data-link layer, which is protocols like Ethernet and Point-To-Point Protocol (PPP), which carries information between adjacent nodes about MAC address from and to and allows for error detection and retransmission. Layer 3 is the IP layer, which carries information about where in the whole network the packet is from and to, not just the current hop.

传输过程如下:

机器 A 想要向机器 B 发送一个数据包.机器 A 知道机器 B 的 IP 地址,因此它将它放在第 3 层数据包中.然而,机器 A 需要将下一跳的 MAC 地址放在第 2 层数据包中.如果它不知道,那么它会发送一个叫做 ARP 请求的东西(地址解析协议,在这里阅读:http://www.tildefrugal.net/tech/arp.php ) 到网络,带有目标 IP.这里会发生几件事之一:

Machine A wants to send a packet to Machine B. Machine A knows Machine B's IP address, so it places that in the layer 3 packet. Machine A needs to place the MAC Address of the next hop in the layer 2 packet, however. If it does not know, then it will send something called an ARP request (Address Resolution Protocol, read here: http://www.tildefrugal.net/tech/arp.php ) to the network, with the destination IP. One of a few things will happen here:

  1. IP 是本地的.拥有该 IP 的机器将使用其 MAC 地址回复发件人.
  2. IP 是非本地 IP.网关路由器将检测到这一点并发送其 MAC 地址.
  3. IP 是非本地的,并且机器 A 的默认网关和子网掩码已设置.使用此信息,机器 A 可以确定 IP 地址的非本地性并将其发送到路由器的 MAC 地址(如果尚不知道,则为 ARPing).

(如果机器 A 更早发现了这一点,它将在 ARP 缓存中,而机器 A 只会使用它.)现在发送了 MAC 地址,可以传输数据包(执行实际传输的物理层 1线上的数据).下一站将是开关.交换机知道作为第 2 层目的地列出的 MAC 地址在哪个出站端口上,因为它跟踪它看到的数据包来自的每个 MAC 地址以及它来自哪个端口 - 如果它不知道,那么它会每隔单一端口,保证它会到达.

(If Machine A found this out earlier, it will be in the ARP cache and Machine A will just use that.) Now that the MAC address is sent, the packet can be transferred (the physical layer 1 performing the actual transfer of data on the wire). The next stop will be the switch. The switch knows which outbound port the MAC address listed as the layer 2 destination is on, because it tracks every MAC address it's seen a packet come from and which port it came on - if it does not know, then it will flood it out every single port, guaranteeing it'll arrive.

因此,数据包到达路由器.IP 模型很酷的一点是它将网络/世界中的每个 IP 地址划分为一个层次结构 - 根据定义,子网不能部分重叠子网,它们要么完全包含它们,要么完全包含它们.因此,只要子网遵循这个层次结构,路由器就可以明确地确定 40 亿个可能的 IP 地址中的每一个在网络上的位置,只需查看 IP 在其表中将属于哪个子网即可!然后将数据包从该端口发送出去.

As such, the packet arrives at the router. The cool thing about the IP model is that it divides every single IP address in the network/world into a hierarchy - Subnets by definition cannot overlap subnets partially, they either wholly contain them or are wholly contained by them. So as long as subnets follow this hierarchy, the router can unambiguously determine where each of the 4 billion possible IP addresses are on the network just by looking at what subnet the IP will fall under in its table! The packet is then sent out that port.

当数据包通过互连的 ISP 的路由器、骨干基础设施等时,它到达机器 B 的路由器,在那里发生相反的过程 - 路由器 B 看到它的目的地是机器 B 并将其发送入站.(同样,如果不知道,路由器 B 将不得不使用类似 ARP 的过程来查找机器 B 的 MAC 地址.)其余的应该是微不足道的.

As the packet travels through interconnected ISPs' routers, backbone infrastructure and so on, it arrives at Machine B's router, where the opposite process happens - router B sees that its destined for Machine B and sends it inbound. (Similarly, Router B will have to use a process like ARP to find Machine B's MAC address if not known.) The rest should be trivial from here.

好的参考:

https://web.archive.org/web/20120129120350/http://www.tildefrugal.net/tech/arp.php

http://en.wikipedia.org/wiki/Data_link_layer

http://en.wikipedia.org/wiki/Network_switch

http://en.wikipedia.org/wiki/Network_layer

http://en.wikipedia.org/wiki/Routing

http://en.wikipedia.org/wiki/Router_(计算)

http://en.wikipedia.org/wiki/Address_Resolution_Protocol

这篇关于基于 OSI 模型的数据包如何通过 Internet 从一台计算机传输到另一台计算机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆