转自: http://null-byte.wonderhowto.com/how-to/hacker-fundamentals-everymans-guide-network-packets-are-routed-across-web-0134491/

We already covered how your data travels the OSI model, layer by layer, and talks with other machines on your local network. But how does that data leave your network? How does it know where to go? What's going on here?

Much of the 'talking' on a local network are broadcasts. This computer is asking for the MAC address of another one, or asking for a local IP address, or any number of things. But doesn't that mean the Internet should be flooded with various broadcast noise all over the place? As it turns out, no. You see, the job of a router is not only to route traffic, but to stop broadcasts. To explain this concept fully, let's look into some examples.

No routers were hurt in the writing of this article.

A Tale of Two Packets: Internal

If you remember correctly, an IP address has two components, the network section and the host section. A subnet mask separates the IP address into those two segments (<network><host>). A subnet is expressed just like an IP address in a four octet form, the most common one being 255.255.255.0 where the '255' means those octets are describing the network and the '0' is describing the host.

Let's say you wanted to send data to another computer on your local network at home. Your internal IP address in this example is 172.10.1.20 and your destination IP address is 172.10.1.30. Also, let's assume your subnet mask is a standard 255.255.255.0.

The first thing that gets done is the computer looks at the address on the packet being sent. It then compares its address with the destination address. Notice the 172.10.1.x is the same on both, and the subnet mask has filled octets in the same locations as well ( 255.255.255.0). This tells the computer that the destination is on the same network it is on. Your computer knows it is host '20' and it needs to reach host '30' and it doesn't need to go through a router to get there.

Now your computer only needs to know the MAC address of host '30' to send this data on its way. If you recall the Media Access Control address is a physical layer function that addresses actual physical hardware on your computer. In a nutshell, it works like an IP address, only on your local network.

ARP!

To perform this feat, your computer sends out a broadcast message to everyone on the network called an ARP, or Address Resolution Protocol. It's like your PC yelling "HELLO! I am looking for the computer 172.10.1.30".

Now each device on the network receives that message and looks at its own IP address in turn. The router (172.10.1.1) sees it is not the one being looked for and drops the message. Other computers on the network do the same thing until the computer that has the IP of 172.10.1.30 gets it, checks its address, and sees they match. It then replies back to the sending computer of 172.10.1.20 saying "HEY! That's me and my MAC address is AA00:BC33:3211".

In the picture below, the MAC address is called an "Ethernet address", reflecting the fact that it's addressing for the physical layer. However, common lingo is "MAC address"

Now the sending computer has the internal IP and MAC address of the receiving computer and can send its data over. But what happens if the two addresses are not on the same network?

A Tale of Two Packets: External

Well, it's not as simple when we have to cross other networks, as there is a bit more going on behind the scenes, as you will see. Let's assume we are sending the same data as before and our source IP address is 172.10.1.20 and our destination IP address is 192.168.0.100. You should immediately notice by the subnet mask of 255.255.255.0 that these two addresses are on separate networks. See, we are getting there.

Just like in the first example, the sending computer looks at the destination address and compares it to its own. However, this time there is a problem—they don't match at all.

Now it knows that it can't just send out an ARP message like before, because remember what happened in the last example, when the routers address didn't match the address being asked? It simply dropped the packet. This is how routers stop broadcasts from traveling the entire Internet. In fact, without this design, the Internet would be flooded with so many broadcast messages from the millions of connected devices that it would crash and fail.

At this point, your computer knows an ARP just isn't going to cut it for the destination of 192.168.0.100, so it broadcasts another ARP. But this time is looks for what's called the default gateway. This is a node, or a router, that acts as an entry or exit point to another network.

Normally, when a computer cannot find a route for an IP address, it will send it along to the default gateway as a route of last resort. This is your modem/router at home. Your router will reply saying, "YO! I am the default gateway and my MAC address is xxxx:xxxx:xxxx!"

Your computer then adds the routers MAC address as the destination MAC address to the packet, and sends it over to the router for safe travels。

Route Me Baby!

The router takes a look at the packet and knows the source IP came from its own network. But the destination is separate altogether. Because the destination is not the same as the router's own internal IP address, it knows the packet is not for it, but needs to travel through it

The router then looks at its routing tables to find a way to get to the 192.168.0.xnetwork. It leaves the source and destination IP address information inside the packet, and changes the new source MAC address to its own address and the destination MAC address to the next node deducted from the routing table.

This process continues over and over with each router that picks up the packets looking at the addresses, seeing it's not for their network and passing it along until it reaches the final destination of 192.168.0.100.

That router will strip of the source and destination MAC addresses that allowed the packets to travel, and replace the source with its own. It then ARPs to find the MAC address of the server being looked for and uses the reply to add the final MAC address of that machine, then sends it along.

转载于:https://www.cnblogs.com/morningdew/p/6034834.html

The Everyman's Guide to How Network Packets Are Routed Across the Web相关推荐

  1. How To Set Up a TCP/IP Peer-to-Peer Network Connection

    飞鸽传书How To Set Up a TCP/IP Peer-to-Peer Network Connection View products that this article applies t ...

  2. Useful “ifconfig” Commands to Configure Network Interface in Linux

    https://www.tecmint.com/ifconfig-command-examples/ ifconfig in short "interface configuration&q ...

  3. Network Stack Specialization for Performance

    最近在研究DPDK,这是sigcomm 2014的论文,纪录在此备忘 Ps:  文中关键词的概念: segment : 对应于tcp的PDU(协议传输单元),这里应该指tcp层的包,如果一个包太大tc ...

  4. 使用 Web 高速缓存减少网络流量 / Reducing network traffic with Web caching

    使用 Web 高速缓存减少网络流量 / Reducing network traffic with Web caching English Version Reducing network traff ...

  5. 【论文翻译】中英对照翻译--(Attentive Generative Adversarial Network for Raindrop Removal from A Single Image)

    [开始时间]2018.10.08 [完成时间]2018.10.09 [论文翻译]Attentive GAN论文中英对照翻译--(Attentive Generative Adversarial Net ...

  6. 图(Graph),也称网络(Network)

    图(Graph) 图(graph),也称网络(Network). 图这种数据结构是很具有代表性的,现代社会人们构建了大量的网络系统, 如计算机网络.物联网.通信网络.交通网络.电力网络.商业和金融网络 ...

  7. PRTG Network Monitor

    介绍 PRTG Network Monitor(PRTG网络监视器)是一款可以监视网络计算机,路由器,交换机,防火墙,数据库服务器等内容的电脑网络监控器.PRTG Network Monitor提供受 ...

  8. 数据库连接字符串大全

    提供的本连接地址(http://www.connectionstrings.com/) SQL Server  ODBC  Standard Security: "Driver={SQL S ...

  9. 面试系统设计_系统设计面试问题–您应该知道的概念

    面试系统设计 You may have heard the terms "Architecture" or "System Design." These com ...

最新文章

  1. [VBScript] 自动删除2小时以前生成的文件
  2. 这样出ORACLE的面试题
  3. 未来趋势分析:Linux有可能成为java OS
  4. python(40):利用utf-8编码判断中文英文字符
  5. 热点的ap频段哪个快_小米9手机热点无法使用:建议2.4G+5G 信号同时输出,提高兼容性...
  6. 【数据结构与算法】之深入解析“贪心算法“的原理解析和算法实现
  7. 基于xlua和mvvm的unity框架
  8. Prime Number Aizu - 0009(素数筛)
  9. 统计源期刊目录_统计源期刊是什么意思
  10. SSM(Spring+Spring MVC+Mybatis)整合 1:整体概述、目录内容及实验环境介绍
  11. Spring使用JDBC访问MySQL数据库
  12. 小程序的支付Demo和登录Demo
  13. 新版本eclipse Neon 4.6.1,登录git报401 没有权限
  14. sonarQube代码管理工具
  15. STC8G1K08A之PWM占空比调整
  16. C++并发编程之线程异步std::packaged_task知识点总结
  17. oracle字符串截取substr和字符串查找instr
  18. AIRSIM 中文使用手册-2021/4/6
  19. Always young
  20. 大学生体测成绩计算工具【npm包】

热门文章

  1. Selenium介绍
  2. 给你这张图,你能搜索到来历吗
  3. 基于java的数据结构学习——数组实现的栈以及简单应用C++实现
  4. Python数据可视化2018:数据可视化库为什么这么多?
  5. 【前端工程师手册】JavaScript作用域拾遗
  6. es5.0 安装head插件
  7. 【Foreign】采蘑菇 [点分治]
  8. 面向对象编程从骨子里就有问题——看看名人大家是如何吐槽面向对象的
  9. MySQL学习笔记(二)—— MySQL的安装
  10. 修练8年C++面向对象程序设计之体会