Network Basics -IP protocol

IP

As the most important protocol in TCP/IP, IP is mainly responsible for sending packets to the ultimate target computer. Thus, IP enables communication between any two computers in the world.

Routing control

Routing controlRoutingThe ability to send packet data to the final destination address. Even if the network is very complex, routing control can determine the path to the destination address. Once the routing control is abnormal, packet data is likely to be “lost” and unable to reach the destination address. Therefore, a packet can successfully reach the final destination address, all rely on routing control.When an IP packet arrives at a router, the router first looks up its destination address, decides which router to send the packet to next, and then sends the packet out. When the IP packet arrives at the router, it goes through the process of searching for the next destination and forwards it to the next router that is found. This process may be repeated several times until the final destination address is found to send the packet to the node.

Routing control table

All hosts maintain a routing table in order to send packets to the target host. This table records which router IP data should be sent to next. IP packets will be transmitted on each data link according to this routing table.

Basic knowledge of IP addresses

An IP address consists of a network identifier and a host identifier
The IP address consists of network IDENTIFIER (network address) and host identifier (host address). [/24 in 192.168.128.10/24 indicates the number of bits from the first to the number of bits belonging to the network identifier.]Copy the code

Network identity configures different values for each segment of the data link. Network identifiers must ensure that the addresses of each connected segment do not duplicate each other. Hosts connected to the same segment must have the same network address. The Host ID of an IP address cannot appear repeatedly on the same network segment. Therefore, you can set the network address and host address to ensure that the IP addresses of each host do not overlap each other in the connected network. That is, the IP address is unique.

IP address classification
There are four levels of IP addresses: CLASS A, B, C, and D (and A still-unused class E). It distinguishes the network and host identities of IP addresses based on the first to fourth bit columns in the IP address.Copy the code
  • Class A Address: A class A address is the first address starting with 0, and its network identifier is the first to eighth digits. In decimal notation, 0.0.0.0 to 127.0.0.0 are class A network addresses. The last 24 bits of A class A address correspond to the host identifier. Therefore, a network segment can contain a maximum of 1,677,724 host addresses
  • Class B address: A Class B address is an address whose first two digits start with 10. The first to eighth bits are its network identity. In decimal notation, 128.0.0.0 to 192.255.0.0 are class A network addresses, and the last 16 bits of class B IP addresses are host addresses. Therefore, a network segment can contain 65535 hosts
  • Class C address: A class C address is an address whose first three digits are 110. From first to 24th its network identity. In decimal notation, 192.0.0.0 to 223.255.255.0 are network addresses of class C. The last eight bits of a class C address correspond to a host identifier. Therefore, a network segment can contain a maximum of 254 host addresses.
  • Class D address: A Class D address is an address whose first four digits are 1110. Bits 1 through 32 are its network identity. In decimal notation, 224.0.0.0 to 239.255.255.255 are network addresses of class D. Class D addresses have no network identity and are often used for multicast.
The broadcast address

Broadcast addresses are used to send packets between hosts linked to each other on the same link. Set all of the host addresses in the IP address to 1 to form a broadcast address. For example, 172.20.0.0/16 is expressed in binary as follows:

10101100.00010100.00000000.0000000 (binary)

Change all the host parts of this address to 1 to form a broadcast address:

10101100.00010100.11111111.11111111 (binary)

If the IP address is expressed in decimal notation, it is 172.20.255.255.

Two kinds of radio

There are two types of broadcasting: direct and local.

Broadcasts within a local network are called local broadcasts. For example, if the network address is 192.168.0.0/24, the broadcast address is 192.168.0.255. The broadcast IP packet will not reach any link other than 192.168.0.0/24 because it will be masked by the route.

Broadcasting between different networks is called direct broadcasting. For example, the host at 192.168.0.0/24 sends an IP packet to the target address at 192.168.1.255/24. The receiving router forwards the packet to 192.168.1.0/24 so that all hosts 192.168.1.1 to 192.168.1.254 can receive the packet.

Global address and private address

In the beginning, any host or router on the Internet must have a unique IP address, and the occurrence of duplicate IP addresses makes it impossible for the sender to determine which address to send the segment to. However, when the receiving end sends the reply receipt after receiving the data packet, the sending end cannot know which host returned the information due to the repeated address, which affects the normal communication. However, with the popularization of the Internet, the problem of IP address shortage is becoming more and more serious. And that’s where this technology comes in. Private IP addresses are reserved IP addresses. It is used only on a LAN, not on the Internet. There is a set of IP addresses that are reserved for private IP networks, called private IP addresses.

Private IP address range:

A: 10.0.0.0 – those that 10.0.0.0/8

B: along – 172.31.255.255 namely along / 12

C: 192.168.0.0-192.168.255.255 namely 192.168.0.0/16

These addresses will not be assigned by the Internet, they will not be routed on the Internet, although they cannot be directly connected to the Internet, but through technical means can still communicate with the Internet NAT technology. We can select the appropriate address class as needed and use these addresses as public IP addresses on the internal LAN. On the Internet, devices that do not need to communicate with the Internet, such as printers and manageable hubs, can also use these addresses to save IP address resources.

An IP address other than a private IP address becomes a global IP address, also called a public IP address.

Subnet mask

The network identification of an IP address is no longer limited by the type of address, but by an identification code called A subnet mask, the subnet network address is refined into smaller networks than class A, CLASS B, and class C. This approach is a mechanism for dividing the original network into multiple physical networks.

role

A subnet mask is used to divide an IP address into a network address and a host address. The default assigned subnet mask is either 255 or 0 for each segment

  • The default subnet mask of class A is 255.0.0.0
  • The default subnet mask of class B is 255.255.0.0
  • The default subnet mask of class C is 255.255.255.0
The principle of

A subnet mask is a 32-bit address like an IP address. You can calculate the IP address and the subnet mask to obtain the network address. Ex. :

The IP address is 192.168.10.2 and the subnet mask is 255.255.255.240.

First convert decimal to binary:

IP address: 11000000 10101000 00001010 00000010

Subnet mask: 11111111 11111111 11111111 11110000

Perform and calculate: ————————–

          11000000 10101000 00001010 00000000

The network id is 192.168.10.0 and the host ID is 2.

Different representations of masks

Having said that the subnet mask is also a 32-bit address, how to convert the beginning of the 25? 25 means that the network number is 25, which represents 25 consecutive ones, and then the rest are filled with zeros: 11111111 11111111 11111111 10000000

Additional information contained

Or take this information as an example: XX.xx.xx.128/25, what else can we get?

  • Host ID: Host ID + network ID =32, 32-25=7
  • Network address: If the 7-digit host ID is all 0, it is XX.xx.xx.128
  • Broadcast address: xx.xx.xx.255 when the 7-digit host number is all 1
  • Number of available addresses: 2^7 possible results for 7-digit host numbers, but without network and broadcast addresses: 2^7-2=126

IP segmentation and reconstitution processing

IP packet fragmentation and reassembly

Because Ethernet’s default MTU(maximum transmission unit of the link) is 1500 bytes, datagrams exceeding 1500 bytes cannot be sent in one frame. At this point, the router divides the IP packet into fragments and sends them.

After fragmentation, IP data can only be reassembled by the target host. Routers do sharding but they don’t reassemble.

Path MTU Discovery

Sharding also has its drawbacks. First of all, the processing load of the router increases. With the improvement of people’s requirements for network security, the router needs to do more and more other processing, such as network filtering. Therefore, the router is not expected to fragment IP packets.

To solve the above problems, a new technique called path MTU discovery was developed. The so-called path MTU (MTU) refers to the maximum MTU when no fragment is required between the sending host and the receiving host, that is, the minimum MTU of all data links in the path. The path MTU discovers that the sending host fragments datagrams according to the path MTU size and sends them. By discovering path MTU, you can avoid fragment processing on intermediate routers and send larger packets over TCP.