Learn the IP routing process step-by-step

Source: Internet
Author: User
Tags unpack
The TCP/IP protocol cluster is the most widely used protocol stack in the Internet, and when it comes to the TCP/IP protocol stack, it is not a problem to talk about the router, because IP routed events occur almost every moment in the network traffic we use .... When you are a novice in the Web world, you may think that the IP routing between devices requires only the IP address of a single device, if you really think it is wrong. Each device requires a lot of additional information to complete the encapsulation of the data in addition to the required IP address when making IP routing. I'll step through the cases provided by the following network scenario to analyze what communication events the device will take in IP routing.




In this scenario, there are two networks, which are connected by a router with two Ethernet interfaces (F0/0,F0/1). The two ports on the router are the same as the RJ-45 models on your own computer, all built into the router. Now let's see what happens when host a at network a wants to communicate with Host B on network B.

Host a opens a command prompt (method: Start-run--cmd), and after the command prompt (>) enters ping 1.1.1.5 when the "ping" command is executed by the computer, the TCP/IP stack invokes the "ICMP" protocol encapsulation of the Internet layer of the Protocol stack Ping 1.1.1.5 "this request.
The ICMP protocol is encapsulated as follows:

ICMP header (Host a) Ping 1.1.1.5
Host A, to send a request encapsulated by this ICMP protocol to target Host B (Host B), the request must be "transported" using the IP protocol. In this way, the IP protocol acts as a postman, sending the ICMP packet to the IP address of the sender (host a) and the recipient (Host B), and then "POST" the packet based on the destination address (Host B's address).

The IP protocol package is as follows:
IP header ICMP header (Host a) Ping 1.1.1.5

Packets encapsulated by IP protocol only complete the encapsulation on the TCP/IP protocol cluster network layer, and the next step is to encapsulate the data link layer. Before the information in the data link layer is encapsulated, host a also needs to start the IP routing process to determine whether the target Host B is on the local network or the remote network. If Host B is on the local network, it means that Host B and host A are in the same logical subnet, which is the same IP network segment. If Host B is on a remote network, the Host B is not in the same network segment as host A, for example, host A is on network A and Host B is on network B. Obviously, in this case the network scenario, host A will determine that Host B is located in the remote network. So the question is, how does host a make a judgment?
First, host A will use its own IP address and subnet mask as "and operations." The so-called and operation is whether binary "0" and "1" phase or binary "0" and "0" phase, the result is "0", and only the binary "1" and "1" and the result is "1". In this example, the IP address of host A is 192.168.0.5, converting this IP address to binary is: 11000000 10101000 00000000 00000101
Host A has a subnet mask of 255.255.255.0, converting the mask to binary is: 11111111 11111111 11111111 00000000 The result of the "and operation" of the IP address and subnet mask in host a binary form is: 11000000 10101000 00000000 00000000
To make it easier to see the result of converting this "and operation" into a dotted decimal number is: 192.168.0.0
This allows host A to complete the first step of IP routing judgment through "and operations". The next step is to take the IP address of the target host (Host B) and the subnet mask of the sender (host a) as "and operations", for example, the IP address of Host B is 1.1.1.5, converting this IP address to binary is: 00000001 00000001 00000001 00000101
The subnet mask for host A is 255.255.255.0 to convert the mask to binary: 11111111 11111111 11111111 00000000 The result of the "and operation" of the two sets of binary numbers is: 00000001 00000001 00000001 00000000 Converting the result of this "and operation" into a dotted decimal number is: 1.1.1.0 so we get two sets of "and operations" results, namely: 192.168.0.0 and 1.1.1.0
For host A, after such a "and operation", if the two "and operation" result is the same, then the target Host B and itself within the same network, that is, target Host B in the local network. Conversely, for host A, after such a "and operation", if the two "and operation" result is different, then the target Host B and itself is not within the same network, that is, target Host B in the remote network. In this case, it is clear that target Host B is on the remote network for the sender (host a)-that is, in Network B.
Host A through the above and the target Host B slightly complex "and operation", completed the first step of the route judgment--to determine the target Host B in the remote network. Next, host a needs to "think" about how to reach the network where Host B resides. Host a first queries its own routing table to see if it can find a route entry to the destination network (Network B) in its own routing table. To make it easier for everyone to understand, I will display the route table output of host A as follows:


C:\>route Print
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.0.1 192.168.0.5 10
127.0.0.0 255.0.0.0 127.0.0.1 127.0.0.1 1
192.168.0.0 255.255.255.0 192.168.0.5 192.168.0.5 10
192.168.0.5 255.255.255.255 127.0.0.1 127.0.0.1 10
192.168.0.255 255.255.255.255 192.168.0.5 192.168.0.5 10
224.0.0.0 240.0.0.0 192.168.0.5 192.168.0.5 10
255.255.255.255 255.255.255.255 192.168.0.5 192.168.0.5 1

Default gateway:192.168.0.1

From the output display of the host a routing table, we did not find a specific route that matched the network that the target Host B was on, which means that host a did not reach the route of the 1.1.1.0 network. However, we notice that the last line of the routing table is output: Default gateway: The output from the last line of the 192.168.0.1 routing table indicates that host a cannot find a specific route to reach the target network. Packets destined for the destination network are sent to the default/default gateway (192.168.0.1), which is then forwarded to the target network by this default/default gateway.
Well, now that host a knows that the default gateway (192.168.0.1) is its own next-hop address, host a begins to execute the encapsulation. The package information is as follows:

Destination Mac:
Mac for Next hop device
SOURCE Mac:
MAC address of Host a
Source IP:
192.168.0.5
Destination IP:
1.1.1.5
ICMP header (Host a)
Ping 1.1.1.5

In the above addressed information, the only thing that host a does not know is "next-Hop device MAC address", where the "Next hop device MAC address" refers to host A's default gateway 192.168.0.1 the F0/0 interface MAC address. It is easy to create a confusion here, the destination IP address of host A is Host B, then why the destination MAC address of the link layer of the host a package is the MAC address of the router f0/0. The reason is that when people design the data link layer, they mainly consider how to solve the communication between two devices on a line.
From this network scenario, we see that both host A and Host B do not belong to two adjacent devices (one router in between) from their physical location. Since Host B is not directly adjacent to host a device, the destination MAC address of host A in the Data Link layer package is certainly not host B. Host A through the IP routing process to determine and query the routing table know that in order to reach Host B you must send the packet to router A's f0/0 interface (F0/0 interface is also host A to reach Host B must be directly adjacent to the interface), so f0/ The 0 MAC address becomes the destination MAC address that host a encapsulates in the data link layer. In this case, if host A is going to send data to server A instead of to Host B, then host A's destination MAC address encapsulated in the data link layer is the MAC address of server A, because Server A and host A are devices that are directly adjacent to each other. So, for host A, does it know the MAC address of the router f0/0 interface? Host A is not aware of. So the next thing that host a needs to do is how to find the MAC address of the f0/0 interface to complete the encapsulation of the data link layer into frames. First, host a looks at its own ARP cache table, each host/computer has this ARP cache table, which records all the direct neighboring devices or hosts that have been communicating with themselves (MAC address), the ARP cache table after a period of time will be automatically deleted, such as Windows dynamic ARP Cache entries will be deleted in less than 10 minutes. If host a communicates with the router before, host A will naturally find the hardware MAC address of the router f0/0 in the ARP cache table, but if this is the first communication between host A and the router, host a sends the ARP Broadcast request packet to network A. The ARP Request package contains the following key information:


Sender IP Address (192.168.0.5) Sender MAC Address (host a MAC address)
Destination IP address (192.168.0.1) Destination MAC address (000000000000)

The three information encapsulated in the ARP Request packet above is known and only the "Destination MAC address" information is unknown (full "0" padding). When the ARP Request packet is sent to network A, the device on network a receives the ARP packet and views the specific encapsulation information within the ARP packet. Because the destination IP address encapsulated in the ARP packet is 192.168.0.1, only an interface or device with 192.168.0.1 that IP can answer the ARP query request, and the responder encapsulates its hardware MAC address into this ARP reply packet. The key information encapsulated by this ARP reply packet (in this case, the ARP response from the router f0/0 interface) is as follows:


Sender IP Address (192.168.0.1) Sender MAC Address (f0/0 interface MAC address)
Destination IP address (192.168.0.5) Destination MAC address (host A's MAC address)

Host a resolves the MAC address of the router f0/0 interface through the ARP protocol to complete the encapsulation of the data link layer. Through host a This parsing process you can see that host a in the first time with the default gateway communication is indeed a hassle, in order to find the default gateway f0/0 interface MAC address also "delay" some time, this is why we ping the network on the first host/ Device, you will typically see the first packet with "Request timed out!" (The request timed out.) ) in the situation. Finally, when host a completes the MAC address resolution, the frame is sent to network A, the specific package of the frame is as follows:


Destination Mac:
Router f0/0 interface
SOURCE Mac:
MAC address of Host a
Source IP:
192.168.0.5
Destination IP:
1.1.1.5
ICMP header (Host a) Ping 1.1.1.5

Because the destination MAC address of the frame is the MAC address of f0/0, only the f0/0 interface of the router receives and processes the data frame. The router encapsulates the frame and looks at the encapsulation information of the network layer, and the router sees that the destination address for the packet's network layer encapsulation is 1.1.1.5. The router in order to forward this packet to 1.1.1.5, using the previously mentioned "and operation" method to calculate, according to the calculation results to determine the destination address 1.1.1.5 for the router itself in the local network or remote network. The "and operations" process of the router is summarized as follows:

The IP address on the f0/0 interface of the router 192.168.0.1 the subnet mask of the f0/0 interface with the "Result 1", and the subnet mask 1.1.1.5 for the destination address f0/0 and the router 255.255.255.0 interface. "Get" Result 2 ";" Result 1 "is not the same as" Result 2 ", proving that the destination address 1.1.1.5 is not in the network a where the router's f0/0 interface resides.
The router's other interface F0/1 IP address 1.1.1.1 with F0/1 interface subnet mask 255.255.255.0 as "with Operation" to get "result 3"; Destination address 1.1.1.5 and F0/1 interface
The subnet mask 255.255.255.0 as "with Operation" to obtain "Result 4", "Result 3" and "Result 4" is the same, proving that the destination address 1.1.1.5 is located in the router's F0/1 interface on the network B. This also means that Router B simply sends the packet sent to 1.1.1.5 from the F0/1 interface to OK. We call this route of the router a direct route.

After the router has reached the above conclusions, the encapsulation is executed immediately, and the specific information of the package is as follows:
Destination Mac:
MAC Address of Host B
SOURCE Mac:
Router F0/1 interface
Source IP Address
192.168.0.5
Destination IP Address
1.1.1.5
ICMP header (Host a) Ping 1.1.1.5

The destination MAC address in the specific information that is encapsulated by the router above is the MAC address of Host B. If the router does not find the hardware MAC address of Host B in the ARP cache table, the router still queries Host B's MAC address by sending an ARP request like the host a query router f0/0 interface hardware MAC address. The process of querying the router for Host B hardware MAC addresses is not repeated here.
So Host B received the data frame, Host B to unpack the frame to see the IP address of the network layer encapsulation, know that the destination of the packet is itself, Host B continues to unpack and look at the information inside the ICMP header to conclude: this is a request for self-feedback of the packet, you need to own this " The packet has reached Host B "information back to host a. Therefore, Host B needs to pass through such as encapsulation in order to deliver the feedback smoothly to host A:
Destination Mac:
Router F0/1 interface
SOURCE Mac:
MAC Address of Host B
Source IP:
1.1.1.5
Destination IP:
192.168.0.5
ICMP header Answer to (Host a) Ping 1.1.1.5

The destination MAC address that Host B encapsulates when sending a reply packet is the MAC address of the router's F0/1 interface, which is also the conclusion that Host B is judged by route and with operations, and for Host B the Router F0/1 interface is its next hop.
The router F0/1 interface receives the packet sent by Host B in order to forward it to host a again for encapsulation, the specific package information is as follows:
Destination Mac:
MAC address of Host a
SOURCE Mac:
Router f0/0 interface
Source IP:
1.1.1.5
Destination IP:
192.168.0.5
ICMP header Answer to (Host a) Ping 1.1.1.5

In the encapsulation process from host A to router to Host B, we can see that the information that the network layer encapsulates is always the same: the source IP is the 192.168.0.5 destination IP is 1.1.1.5. Always changing is a hop-hop hardware MAC address. In the encapsulation process from Host B to router to host A, we can also see that the information that the network layer encapsulates is always the same: the source IP is the 1.1.1.5 destination IP is 192.168.0.5. Always changes the hardware MAC address of a hop-hop.
The above conclusions we get in the IP routing encapsulation process do not apply to another network technology--nat (network address translation). We will continue our discussion on NAT in other articles.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.