【Computer Network】IP Protocol

 

Table of contents

Preface        

IP protocol

basic concept

IP protocol format

Fragmentation 

16-bit identifier

3-bit flags and 13-bit slice offset

Sharding process

Network segmentation

Network number and host number

DHCP protocol

CIDR division scheme

special ip address

IP address limit

Private IP address and public IP address

Routing and forwarding


Preface        

        We talked about the HTTP/HTTPS protocol and the TCP/UDP protocol earlier, which correspond to the first two layers of the four-layer model: application layer and transport layer. Now we should explain the third layer: the network layer. The protocol used in this network layer is IP protocol.

        At the application layer, we solve the problem of how to use data . At the lower three layers, we need to solve the problem of how to reliably send data from host A to host B.

        The TCP protocol solves the problem of data transmission reliability, while the IP protocol solves the ability to send host A to host B. How can we be reliable without even having the ability to send data from host A to data from host B? So we used the IP protocol: to provide a capability to send data from host A to host B.

IP protocol

basic concept

Host: A device that is equipped with an IP address but does not perform routing control.

Router: It is equipped with an IP address and can perform routing control.

Node: The collective name for hosts and routers.

As shown in the figure, from host B to host C, it is sent to the destination host hop by hop by the router. The specific router to which it is transferred is determined by the other party's IP address, which will be discussed in detail later.

IP protocol format

  • 4-digit version number (version): Specifies the version of the IP protocol. For IPv4, it is 4.
  • 4-bit header length : header size not containing data . Like TCP's 4-bit header length, 4bit means that the maximum number is 15, but the unit is 4 bytes, so the maximum length of the IP header is 60 bytes.
  • 8-bit Type of Service : 3-bit priority field (deprecated), 4-bit TOS field, and 1-bit reserved field (must be set to 0).   4-bit TOS respectively represents: minimum delay, maximum throughput Volume, highest reliability, and lowest cost. These four conflict with each other, and you can only choose one. For applications such as ssh/telnet, the minimum delay is more important; for programs such as ftp, the maximum throughput is more important.
  • 16-bit total length : How many bytes (including data) does the IP datagram occupy as a whole .
  • 16-bit identification (id): uniquely identifies the packet sent by the host. If the IP packet is fragmented at the data link layer, then the ID in each fragment is the same.
  • 3-bit flag field : The first bit is reserved (reserved means that it is not used now, but it may be used in the future). The second bit is 1, which means fragmentation is prohibited. At this time, if the message length exceeds the MTU, the IP module The message will be discarded. The third bit indicates "more fragments". If fragmented, the last fragment is set to 1, and the others are 0. It is similar to an end mark.
  • 13-bit fragmentation offset (framegament offset): It is the offset of the fragment relative to the beginning of the original IP message. In fact, it indicates where the current fragment is in the original message. The actual number of bytes of the offset is This value is obtained by * 8. Therefore, except for the last message, the length of other messages must be an integer multiple of 8 (otherwise the messages will not be continuous).
  • 8-bit Time To Live (TTL): The maximum number of hops for a datagram to reach its destination. It is usually 64. Each time it passes through a route, TTL= TTL-1, and it decreases to 0 before it reaches the destination, then Discarded. This field is mainly used to prevent routing loops ( when the router receives a packet, it will select the next hop according to the routing table and forward the packet to the next hop router. If the routing table is not configured correctly Or if a loop exists, the router may incorrectly choose a jump path, causing packets to loop around the network. ).
  • 8-bit protocol : Indicates the type of upper layer protocol, TCP/UDP.
  • 16-bit header checksum : Use CRC for verification to identify whether the header is damaged.
  • 32-bit source address and 32-bit destination address : represent the sender and receiver. This can also explain why ip in IPv4 is four bytes, because there are 32 bits
  • Option field (variable length, up to 40 bytes): Omitted

Here we still need to solve the two most basic problems:

1. How to unpack? (separate header and data)

        Fixed-length header + self-describing field, first extract the fixed-length 20-byte header, and then obtain the total length of the header (excluding data) (excluding data) based on the 4-bit header length in the header (4*4-bit header length), and then subtract 20 bytes is the length of the option [get header]; then use the 16-bit total length to get the total length of the datagram, and subtract the 4-bit header length to get the length of the data [get data].

That is, payload = 16 bits total length - 4*4 bits header length.

2. How to deliver it upward (decommissioning)?

The TCP or UDP delivered to the upper layer is determined based on the 8-bit protocol         in the header .


Fragmentation 

So what are the 16-bit identifier, 3-bit flag, and 13-bit slice offset in the second line?

        Due to physical characteristics, the link layer generally cannot forward large data. Therefore, the link layer generally has a limit on the size of packets that can be forwarded to the network at one time. So we need to fragment the data , and the fragmentation work is implemented at the network layer of this layer. When transmitted to the other party's network layer, it is assembled again. That is, who slices and who assembles.

        Therefore, the receiver will have the following four issues to deal with when assembling and processing fragments:

  • 1. How to identify different messages
  • 2. How to identify whether a packet has been fragmented
  • 3. How to identify where fragmented packets start and end?
  • 4. Exception handling: How to identify the loss of a certain fragment during the assembly process?

So the following fields are to solve these problems.

16-bit identifier

1. How to identify different messages

        When we receive a lot of packets (already fragmented), how do we determine which fragments belong to the same packet and which are different?

        What we think of is: different messages should have different identifiers; fragments of the same message should have the same identifier.

        The 16-bit identification field is a 16-bit field used to identify the original data packet. When the original data packet needs to be fragmented during transmission , each fragment will contain the same identification value so that the receiving end can identify that these fragments belong to the same original data packet.


3-bit flags and 13-bit slice offset

  1. 3-bit flags field : The flags field is a 3-bit field, which includes the following three flag bits:

    • The first flag bit (Reserved): a reserved bit that will be used for other purposes in the future and should be set to 0 currently.
    • The second flag bit (Don't Fragment, DF): If this flag bit is set to 1, it means that the data packet does not allow fragmentation, that is, it cannot be fragmented during transmission. If the packet needs to be fragmented during transmission but the DF flag is set, the router will drop the packet and send an error message to the source host.
    • The third flag bit (More Fragments, MF): If this flag bit is set to 1, it means that the fragment is not the last fragment of the data packet . If set to 0 , it means this is the last shard .

 

     2. Fragment Offset field : The Fragment Offset field is a 13-bit field used to specify the position of the current fragment in the original data packet. It represents the offset (in 8 bytes) of the current fragment's data in the original packet . Through the fragment offset field, the receiving end can reassemble different fragments into the complete original data packet in the correct order.

        For example, a 24-byte data will be fragmented into 3 parts. The first fragment has a fragment offset of 0, the second fragment has a fragment offset of 8, and the third fragment has a fragment offset of 16.

Now you can solve the problem just now: 2. How to identify whether the message has been fragmented?

        a. If the third flag of the 3-bit flag is 1, it means that the packet must have been fragmented.

        b. If the third flag bit of the 3-bit flag is 0, it means that the message is the last fragment or has not been fragmented.

How to tell the difference ? When the third flag bit of the 3-bit flag is 0, the 13-bit fragment offset at this time is not 0, indicating that the message must be fragmented (because the fragment must be the last one, if fragmented, Then the fragment offset must not be 0); if the 13-bit fragment offset is 0, it means that this is an independent message and has not been fragmented.


 3. How to identify where fragmented packets start and end?

According to what we said above:

If the third flag bit of the 3-bit flag is 1 and the slice offset is 0, it means that this is the beginning of fragmentation.

If the third flag bit of the 3-bit flag is 1 and the slice offset is >0, it means that this is the middle part of the slice.

If the third bit of the 3-bit flag is 0 and the slice offset is >0, it means that the slice is at the end.


4. Exception handling: How to identify the loss of a certain fragment during the assembly process?

Sort in ascending order         according to the offset of each fragment , and combine the offset + its own size = the offset of the next message.

        Scan the entire message and if there is no match with the offset of the next message, it means there must be missing fragments in the middle; if the match can be calculated normally to the end, it means that the message must have been received completely.


Sharding process

First of all, we need to know that before fragmentation, it must be an independent and complete IP message. After fragmentation, each fragment must also have an IP header, because the fragmentation information (16-bit identification, 3-bit flag, 13-bit slice offset, etc.) are in the header. Instead of fragmenting directly, the header follows the first fragment.

So suppose there is a 16-bit IP message with a total length of 3000 bytes, and the link layer MTU is set to 1500 bytes, so the data needs to be fragmented.

        First perform the first fragment. Assume that the 16-bit identifier is 1234. More fragments in its 3-bit flag must be set to 1. At this time, since it is the first fragment, the fragment offset is 0, plus The original header, the total 16-bit length of the IP message is now 1500.

        Next, there are 1500 pure data left. If we directly extract these 1500 data and then add a 20-byte header, the total size of the IP message will become 1520, which is greater than the maximum limit of 1500 at the link layer. Bytes.

        So only the first 1480 bytes can be extracted , and then a 20-byte header is added. At this time, the 16-bit flag is 1234, and the more fragments in its 3-bit flag must also be set to 1. This is the second slice, the slice offset is the length of the previous IP message 1500, plus the newly added header (note that the first fragment carries the original header, this is newly added), the total length of the IP message is 16 bits. Time is 1500.

        Since the upper layer only extracted 1480 bytes, there are still 20 bytes of data left. We need to add a 20-byte header to the 20-byte data. At this time, the 16-bit identifier is 1234, and its 3 - bit More shards in the flag are set to 0 (last shard). The fragment offset is the length of the previous IP message 1480 + the length of the first message 1500 = 2980. The total 16-bit length of the IP message is now 40.

 As for the offset, you can understand that when calculating, only the first header is counted, other headers are newly added, and the length is not included in the offset.

However, we strongly do not recommend fragmentation operation because fragmentation will increase the probability of packet loss. How to completely solve the fragmentation problem, we will talk about it later at the link layer.

Network segmentation

Network number and host number

The IP address is divided into two parts: the network number and the host number .

  • Network ID: Ensure that two network segments connected to each other have different identities;
  • Host number: In the same network segment, hosts have the same network number, but they must have different host numbers.

You can add a / at the end of the IP address , and a number after / to represent the network identification (network number) from the beginning to the number .

        For example, 192.168.128.10/24 means that the first to the 24th digit belongs to the network identification, that is, "192.168.128", and the following 10 belongs to the host number.

        For example, let's just assume that we use the first 8 digits of the IP as the beginning of the IP of various countries in the world, assuming that China is 1 and the United States is 10; then in China, the second 8 digits are used as the identifier of provinces. For example, Hebei Province is 1, Beijing is 2, Tianjin is 3..., and then the bits are divided according to the corresponding counties, cities, etc.

        At this time, at the national level, 1 and 10 are counted as the network number, that is, the first 8 digits, and the following 24 digits are counted as the host number; then at the provincial level, 1, 2, and 3 plus the first 8 digits (1 ) A total of 16 digits is the network number, the next 16 digits are the host number, and so on.

        In fact, the IP addresses of each country have been divided at the beginning. International routers have their own routing tables, which can forward country-to-country information.


  • Different subnets actually put hosts with the same network number together.
  • If a new host is added to the subnet, the network number of the host must be the same as the network number of the subnet, but the host number must not be the same as that of other hosts in the subnet. 

By properly setting the host number and network number, you can ensure that the IP address of each host in the interconnected network is different.

DHCP protocol

        Manually managing IPs in a subnet is quite troublesome. When a new host is added to the subnet, it needs to be assigned an IP address. When a host in the subnet disconnects from the network, its IP address needs to be recycled. It is easy to assign to subsequent newly added hosts.

        The DHCP protocol solves the problem of IP address allocation and configuration in computer networks. It can automatically assign IP addresses to new host nodes in the subnet, avoiding the inconvenience of manual IP management. Generally, routers are equipped with DHCP function. Therefore, routers
also Can be thought of as a DHCP server.

Find the target network first, then the target host

        When data needs to be sent across a network from one host to another, the data is usually not sent to the target host immediately. Instead, the data is first sent to the target network where the target host is located , and then the target is found within that network. host .

        The first step in this process is not to find the target host, but to find the target network. This design is to improve routing efficiency . If the goal is to find the target host from the beginning, only one host can be excluded at a time during the search process, which will be very inefficient. On the contrary, if the target network is found first, a large number of hosts that are not within the target network can be excluded at once, thereby significantly improving the retrieval efficiency.

        Therefore, networks are divided into subnets (also called network segments or subnetworks) to help routers more quickly determine where packets are destined. This layered approach enables routers to more quickly determine the next hop for a packet and send it to the correct network before finding the destination host within that network. This way of routing data is called hierarchical routing, and it helps improve the performance and efficiency of the entire Internet.

        As for how the network is divided ?

In the past, a solution for dividing network numbers and host numbers was proposed, which was to divide all IP addresses into five categories, as shown in the figure below

Therefore, the value ranges of various types of IP addresses are as follows:

Class A: 0.0.0.0 to 127.255.255.255.
Class B: 128.0.0.0 to 191.255.255.255.
Class C: 192.0.0.0 to 223.255.255.255.
Class D: 224.0.0.0 to 239.255.255.255.
Class E: 240.0.0.0 to 247.255.255.255.
        When you want to determine which category an IP address belongs to, you only need to traverse the first five bits of the IP address. Which bit first appears with a 0 value, then the IP address belongs to A, B, C, or D. , Class E address.

        With the rapid development of the Internet, the limitations of this division scheme soon became apparent. Since only 2^7 Class A addresses can be applied for, which is a relatively small number, most organizations apply for Class B network addresses, resulting in Class B addresses. It was all allocated quickly, but Class A wasted a lot of addresses;

        For example, if you apply for a Class B address, theoretically more than 65,000 hosts can be allowed in a subnet. The number of hosts in the subnet of a Class A address is even greater. However, in actual network setup, there will not be a subnet There are so many situations. Therefore a large number of IP addresses are wasted.

A new division scheme is proposed for this situation, called CIDR (Classless Interdomain Routing):

CIDR division scheme

    • Introduce an additional subnet mask to distinguish network numbers and host numbers;
    • The subnet mask is also a 32-bit positive integer. It is usually terminated by a string of "0";
    • Perform a "bitwise AND" operation on the IP address and subnet mask, and the result is the network number;
    • The division of network numbers and host numbers has nothing to do with whether the IP address is Class A, Class B or Class C.

        At this time, a network is divided into smaller subnets in a more fine-grained manner. Through continuous subnet division, the host number corresponding to the IP address in the subnet becomes shorter and shorter, so the available IP addresses in the subnet The number of IP addresses will become smaller and smaller, which will avoid a large amount of waste of IP addresses.

        For example, if the first 24 bits of the IP address in a certain subnet are the network number, then the first 24 bits of the 32 bits of the subnet mask corresponding to the network are 1, and the remaining 8 bits are 0. , the mask representation is 255.255.255.0. Assume that there is a host in the subnet with an IP address of 192.168.128.10. Then the bitwise AND operation between
        this IP address and the subnet mask corresponding to the network is 192.168.128.0. This is the subnet . The network number corresponding to the network .         In fact, when using the subnet mask to perform a "bitwise AND" operation with the IP address of the subnet host, the essence is to retain the first 24 bits of the host IP address and clear the remaining 8 bits. , that is, the host number is cleared to 0, so the result after "bitwise AND" is the network number corresponding to the network.

The first example is to add each bit of the IP address 140.252.20.68 bitwise to 255.255.255.0, and finally get 140.252.20.0. 

The second one is the same. Convert the last digit of 68 into binary to be 01000100, and then do the bitwise AND with 240. When converted into binary, it is 11110000. The bitwise AND is 01000000. When converted into hexadecimal, it is 40, and the decimal is 64. Meet our expectations


special ip address

Not all IP addresses can be used as host IPs, some IPs themselves have special purposes.

  • Set all the host addresses in the IP address to 0, which becomes the network number, representing this LAN ;
  • Set all host addresses in the IP address to 1, which becomes a broadcast address, used to send data packets to all hosts connected to each other on the same link;
  • The IP address of 127.* is used for local loop back testing, usually 127.0.0.1

IP address limit

        We know that an IP address (IPv4) is a 4-byte 32-bit positive integer. Then there are only 2 to the power of 32 IP addresses, which is about 4.3 billion. The TCP/IP protocol stipulates that each host needs to have An IP address.
        
        In fact, due to the existence of some special IP addresses, the number is far less than 4.3 billion; in addition, IP addresses are not configured according to the number of hosts, but each network card needs to be configured with one or more IP addresses.
        CIDR The utilization rate of IP addresses has been improved to a certain extent, but the absolute upper limit of IP addresses has not been increased, and it is still not enough. There are three ways to solve this problem:

  • Dynamically assign IP addresses: Only assign IP addresses to devices connected to the network. Therefore, devices with the same MAC address may not necessarily get the same IP address every time they connect to the Internet, which avoids the need for IP addresses to be forcibly bound to a certain device. a device.
  • NAT technology : NAT (Network Address Translation) is a network technology used to manage and map communications between devices within a private network and the public Internet . It allows multiple devices in a private network to communicate with external networks using a shared public IP address , while improving network security and management flexibility.
  • IPv6: IPv6 is not a simple upgraded version of IPv4. These are two unrelated protocols and are not compatible with each other; IPv6 uses 16 bytes and 128 bits to represent an IP address; but IPv6 is not yet popular.

Private IP address and public IP address

If an organization establishes a LAN internally, the IP address is only used for communication within the LAN and is not directly connected to the Internet. In theory, any IP address can be used, but RFC 1918 stipulates the private IP address used to establish a LAN:

  • 10.* , the first 8 digits are the network number, a total of 16,777,216 addresses
  • 172.16.* to 172.31.* , the first 12 digits are the network number, a total of 1,048,576 addresses
  • 192.168. *, the first 16 digits are the network number, a total of 65,536 addresses, I believe this is what we often see starting with it.

Those included in this range become private IPs (internal network IPs), and the rest are called global IPs (or public network IPs) ;

When we xshell connect to the cloud server:

You can see that the public IP of the cloud server I am connected to is 182.42.111.236, and there are many subnets under a public network. We can use the ifconfig command to view it.

        You can see that my intranet IP is 10.0.0.110, which belongs to the 10.* standard mentioned above.

        Of course, there are many internal IP addresses in the world that are 10.0.0.110 like mine, but our public IP addresses must be different.

        At the same time, we can press Win+R, enter cmd, enter the command control line, enter ipconfig, and then we can see the intranet IP of our host.

Generally speaking, the address of the default gateway is *.1, which is the first digit         of the host number in the current subnet . It (gateway) is used to connect devices or systems on different networks . A gateway acts as a relay point for data packets to travel from one network to another. It is able to understand the protocols and data formats between different networks to ensure that data can be forwarded and routed correctly.


How is the data sent to the server?

Since we have an intranet IP, how is our data sent to the server step by step?

First of all, we need to know: a router is a hardware device that connects two or more networks. There are two network interfaces on the router , namely the LAN port and the WAN port.

  • LAN port (Local Area Network): Represents the port connected to the local network, mainly connected to the switch, hub or your own computer in the home network.
  • WAN port (Wide Area Network): WAN port refers to the interface on the network device used to connect to the wide area network. Generally refers to the Internet.

It can be said that the LAN port is responsible for the communication of these local network devices, while the WAN port is responsible for connecting to the upper layer subnet.

In most home and small office environments, common routers usually have one WAN port and multiple LAN ports . The WAN port is used to connect to the external Internet, while the LAN port is used to connect to devices in the local area network. The WAN port is usually connected to the Internet through various broadband access technologies (such as optical fiber, DSL or coaxial cable), while the LAN port is usually an Ethernet interface used to connect devices to the local area network.

This picture can help you understand. Looking at the part on the left, the LAN port of the home router is equivalent to 192.168.1.1 (used for local communication), and their WAN port is equivalent to the subnet 10.1.1.* of the operator's router.

  • Different routers have the same subnet IP ( usually 192.168.1.1). The host IP addresses within the subnet cannot be repeated, but the IP addresses between subnets can be repeated.
  • Each home router is actually a node in the subnet of the operator's router. Such operator routers may have many levels. The WAN port IP of the outermost operator router is a public network IP .

So this is how the data is sent to the server :

        Since the private network IP cannot appear in the public network (because there will be many duplicates of the private network IP) , in order to solve this problem, when the hosts in the subnet communicate with the external network , the router will continuously add the IP header of the data packet to the The source IP address is replaced with the WAN port IP of the router, and the source IP address in the final data packet becomes a public IP. This technology is called NAT (Network Address Translation).

According to the above example, assume that a certain host 192.168.1.201 wants to access the server 122.77.241.3.

In the IP message sent at this time, the source IP address is 192.168.1.201 and the destination IP address is 122.77.241.3.

When passing through the home router, replace the source IP with its WAN port IP: 10.1.1.2, and the destination IP is 122.77.241.3.

When passing through the operator's router, replace the source IP with its WAN port IP: 122.77.241.2, and the destination IP is 122.77.241.3.

At this point, the communication is successful. When the destination IP returns the result, it still returns it to 122.77.241.2 first, and then how to solve the problem of where to go next is a problem to be solved by the link layer. We will talk about it later.

Can hosts in two different LANs communicate across the public network?

  • Hosts in two LANs theoretically cannot communicate across the public network, because in order for one host to send data to another host, it must first know the IP address of the other host.
  • Even though this host now knows the IP address of another host, it is possible that the IP addresses of the two hosts are the same because their IP addresses are both private IP addresses.
  • When this host sends data, fill in the destination IP address with the same IP address as its own, and the operating system will think that the data is sent to itself and will not send it out.

        Therefore, it is basically impossible to send data from one LAN host to another LAN host without going through the public network . When we chat with others, we do not directly send data from one LAN to another. Instead, we first send the data to the server through the public network, and then the server forwards the data to another LAN through the public network.

        But in reality, there are some technologies that can make the data packets be sent to the target host correctly without replacing the public network IP during the sending process. This technology is called intranet penetration, also called NAT penetration.

Routing and forwarding

        The routing process is the process of "data asking for directions".
        During the routing process, data passes through the router and reaches the destination host hop by hop. The so-called "one hop" is an interval in the data link layer, specifically in Ethernet, it refers to the frame transmission interval from the source MAC address to the destination MAC address.

The transmission process of IP data packets is also the same as asking for directions. 

  • When an IP data packet reaches the router, the router will first check the destination IP;
  • The router decides whether the packet can be sent directly to the destination host, or whether it needs to be sent to the next router or subnet;
  • Repeat in sequence until the target IP address (host) is reached.

 

Regarding the second point, there will be three situations

  • After querying the routing table, the router learns which subnet the next hop of the data should jump to.
  • After the router queries the routing table and finds no matching subnet, the router will forward the data to the default route.
  • After querying the routing table, the router learns that the target network of the data is the current network. At this time, the router will transfer the data to the corresponding host in the current network.

For example, suppose you arrive somewhere for the first time. Suppose you want to find Hebei University. At this time, you get off the train station and your wallet and other items are stolen. You have no choice but to ask someone for directions first. The person said Go to the intersection in front of you first, then turn left and then ask someone else . At this time, this person is equivalent to a router. He tells you the location of the next hop (not the destination location). Since our destination is the school dormitory, the decision is equivalent to being sent to the next router . So after turning left at the intersection, I asked another person. The person said, there is no need to look for it. Hebei University is in front of you. Then you can see the dormitory you are looking for by turning left after entering the door. This is equivalent to the router sending it directly to the target . Hosted . Instead of continuing to send it to the next router. 

So how to determine where the current data packet should be sent?

This relies on each node maintaining a routing table internally.

Routing table query process

The routing table can be viewed using the route command

Since this is a PC, not a router, the display is not complete.

in:

Destination  represents the destination network address.
Gateway  represents the next hop address.
Genmask  represents the subnet mask.
Among Flags , the U flag indicates that this entry is valid (some entries can be disabled)

        G flag: Indicates that the next hop address of this entry is the address of a router . If the G flag is not set, the next hop address is considered to be the address of the destination host to which the packet is intended .

        H flag:  This flag indicates that the routing entry is for a specific host, not for the entire network or subnet. When the H flag is set, the router will send the packet directly to the specified destination host without further routing. This routing entry is typically used to process packets for a specific host to provide more precise routing.

Iface represents the sending interface. When the IP data packet arrives at the router, it first performs a "bitwise AND" operation on the destination IP address and subnet mask Genmask
        in the headercompares the result with the destination network address Destination  . If it matches, the packet is The first hop should be to this subnet, and the data packet will be sent out through the corresponding sending interface .Iface

        If no result in the entire routing table matches it, that is, no matching destination network address is found , the router will send the packet to the default route, which is the destination network address in the routing table default. You can see that the default route corresponds to actually transferring the data to another router, so that the data can continue to search for routes on the other router.Flags含有G标志

        In this way, after the data packet is continuously routed, it reaches the network where the target host is located, and then is routed according to the host number to reach the target host.

for example:

Assume that the network interface configuration and routing table on a certain host are as follows:

Forwarding process example 1: If the destination address of the data packet to be sent is 192.168.56.3

  • The AND operation with the subnet mask in the first line results in 192.168.56.0, which does not match the destination network address in the first line.
  • Then do the AND operation with the subnet mask in the second line to get 192.168.56.0, which is the destination network address in the second line, so it is sent out from the eth1 interface;
  • Since 192.168.56.0/24 is the network directly connected to the eth1 interface, it can be sent directly to the destination host without forwarding through a router.

Forwarding process example 2: If the destination address of the data packet to be sent is 202.10.1.2 

  • Compare it with the first few items in the routing table and find that none of them match;
  • According to the default routing entry, it is sent from the eth0 interface and sent to the 192.168.10.1 router;
  • The 192.168.10.1 router determines the next hop address based on its routing table.

At this time, the problem of how to determine the next hop location of the data in the network has been solved. So how is each piece of data achieved? We will introduce the data link layer in detail in the next chapter.

Guess you like

Origin blog.csdn.net/weixin_47257473/article/details/132969082