Network—Network layer protocol (IP protocol)

1. IP protocol:

  • The IP protocol is the core protocol in the TCP/IP protocol suite. All TCP, UDP, ICMP, and IGMP data are transmitted in IP datagram format;

2. IP protocol header format:

protocol format

  1. 4-bit version protocol : ipv4 and ipv6;
  2. 4-digit header length : IP protocol has variable length, the longest is 60 bytes, the shortest is 20 bytes; (40 bytes of option data)
  3. 8-bit protocol type (TOS) : 3-bit priority (deprecated), 4-bit service type (minimum delay, maximum throughput, maximum reliability, minimum cost); 1-bit reserved word;
  4. 16-bit total length : the size of an IP packet including the IP packet header; the maximum length must not be greater than 64k; tcp will select the appropriate mss size data transmission at the transport layer;
  5. 16-bit fragment identification : UDP data may be fragmented at the network layer to identify which packet the current fragment belongs to;
  6. 3-bit flag bits : 1 bit reserved, 1 bit prohibited fragmentation flag, 1 bit more fragmentation flag;
  7. 13-bit fragment offset : in eight bytes, indicating the position of the current fragment in the complete message;
  8. 8-bit survival time : the maximum life cycle of insulation; a piece of data can pass through as many routers as possible, and if it does not pass through a router, -1; if it is 0, the data will be discarded;
  9. 8-bit protocol : 8-bit upper layer protocol. The network layer needs to use this protocol type to retrieve data, which determines which protocol the transport layer uses to parse the data;
  10. 16-bit header checksum : Verify whether the data is consistent.
  11. Source IP address/destination IP address – 32 bits : describes the starting point to the end point;
  12. 40-byte option parameter : retain the passing router address information.
(1) Data fragmentation at the network layer:
  • If the size of the data delivered by the transport layer is too large, the large data will be divided into many small data fragments at the network layer, and then each fragment will be encapsulated in the IP message header and sent, and will be divided after reaching the opposite end. The fragments are reorganized into a complete message and delivered to the upper layer;
  • The transmitted data is fragmented if it is too large – How large will it be fragmented? – Depends on the limit of the link layer maximum transmission unit – MTU (Maximum Transmission Unit);
  • The mss negotiated in the transport layer protocol tcp is negotiated based on the MTU, so the tcp data will not be fragmented when transmitted to the network layer; but in the udp protocol, the data can be transmitted as long as the size is not larger than 64k-28, so in If the network layer is larger than the MTU size, it will be fragmented on the network layer to prevent data loss; therefore, the data fragmentation of the network layer is mainly for UDP.
(2) Why is the fragmentation offset in 8 bytes:
  • The maximum offset that can be represented by a 13-bit fragmentation offset is 2^13=8192; but a complete UDP may be 64k, and a 13-bit offset cannot be represented, so the size of the field is 8 bytes. Unit, then 8192 offsets represent 8192x8 = 64k; this fully represents the offset.

3. Network segmentation and routing selection:

(1) Address management and IP address composition:
1. Address management:

(1) IP address: an unsigned 32-bit integer that uniquely identifies a host on the network; uniqueness must be ensured when assigning an IP address to a host; (2) Network allocation of IP addresses is a very large task and requires machine allocation –
DHCP –Dynamic address allocation;
(3) The entire network is composed of many small networks and is allocated according to the network.

2. The composition of the IP address: network number + host number

(1) Network number : Some network identifiers corresponding to a router when establishing a local area network; (Each router determines the source address of the received data to determine whether the host belongs to its own network. It will forward it if it does, and discard it directly if it does not. , you must use the address I assigned you to access the Internet to avoid conflicts caused by your own allocation);
(2) Host number : The host number is a host that everyone in the LAN has the same network number and uniquely identifies;
(3) The composition of the network segment :

  • In the early days : all IP addresses were divided into five types of addresses. What kind of network was built, what kind of network number was used, and what kind of address was assigned.
    Class A : used to build very large networks. In the IP address: the upper 1 bit is fixed at 0, the upper 7 bits are the network number, and the lower 24 bits are the host number ****0.0.0.0 ~ 127.255.255.255 ;
    Class B : used to build a medium-sized network. The IP address: the high 2 digits are fixed at 10, the high 14 digits are the network number, and the low 16 digits are the host number ****128.0.0.0 ~ 191.255.255.255 ;
    Class C : used to set up a small network. The IP address: the high 3 digits are fixed at 110, the high 21 digits are the network number, and the low 8 digits are the host number ****192.0.0.0 ~ 223.255.255.255
    Class D : Special network, the upper 4 digits of the address are fixed at 1110, and the 28-bit multicast group number;
    Class E : Special network, the upper 5 digits of the address are fixed at 11110, and the 27-bit reserved number is reserved;
    ⑥ What network do you want to build, and then go to The authoritative organization applies and is assigned a network number. Then the network is set up and the host number is assigned by itself.

  • Current division method: CIDR scheme – introduces a new field: subnet mask :
    Subnet mask : unsigned 32-bit integer, but the data consists of consecutive binary 1s;

    • The subnet mask is inverted to get the maximum host number; for example: 255.255.255.0 is inverted to get 0.0.0.255 – the maximum host number is 255;
    • Add the subnet mask and IP address to get the network number;

    ②Example question :
    There is now a company that has applied for a Class C address, 192.168.122.0/24. The company has 4 departments and wants to divide it into 4 subnets equally. How to divide it? After division, the network number of each subnet is How many? What is the subnet mask? What is the IP address range?
    Subnet mask: Class c network: has 256 host numbers 0 -255; divided into 4 subnets on average - then each subnet has 64 host numbers, and the host The number range is 0~63;
    so 0.0.0.00111111 is inverted to get the subnet mask: 255.255.255.192;
    192.168.122.0~192.168.122.63–192.168.122.0/255.255.255.192;
    192.168.122.12 8~192.168.122.191 – 192.168.122.128/ 255.255.255.192;
    192.168.122.128~192.168.122.191 – 192.168.122.128/255.255.255.192;
    192.168.122.192~192.168.122.255 – 192.1 68.122.192/255.255.255.192

(4) Special IP address :
① IP address with host number all 0: network number – used to identify the network – this host number cannot be assigned to the host 192.168.122.0;
② IP address with host number all 1: udp LAN broadcast address —This host number cannot be assigned to a host;
udp supports LAN broadcast, and the broadcast address for sending data can be considered to be sent to all hosts in the LAN – all hosts in the LAN can recognize it;
tcp does not support a LAN address broadcast, because tcp is Connection-oriented.
③127.0.0.1: This address is a local virtual loopback network card address on each host – mainly used for network testing of this machine;
④0.0.0.0: This address adapts to any network card address on this machine, commonly used Monitoring address on the server side – means monitoring all network card IPs of this machine;
⑤255.255.255.255: Network-wide broadcast address – any host that gets the data sent to this address will think it matches itself – often used for DHCP broadcasts.

(2) Routing selection:
1. Concept:
  • Select an appropriate path for the data based on the destination address in the data;
  • After each host connects to the router, it will broadcast a DHCP request to the entire network, and the router will receive a reply: ①DHCP response; ②Assign an address to the host; ③The current subnet mask of all networks; ④The current gateway address of all networks;
2. IP datagram transmission:
  • When an IP data packet reaches the router, the router will first check the destination IP;
  • The router decides whether the data packet can be sent directly to the target host or needs to be sent to the next router;
  • Repeat this sequence until you reach the target IP address.
  • If the destination IP hits the routing table, just forward it directly;
  • The last row in the routing table is mainly composed of the next hop address and the sending interface. When the destination address does not match other rows in the routing table, it is sent to the next hop address according to the interface specified by the default routing entry.
3. Public network and private network:
  • IP addresses are not enough. In addition to DHCP technology, there is another technology – NAT technology: network address translation technology;
  • A router can form a private network, and the hosts in the private network use a network card address of the router to access the Internet;
  • Then there is no fear of conflict between the IP addresses of the hosts in these private networks and the IP addresses in other private networks, because they all use different IP addresses to access the Internet externally;
  • Just make sure it doesn't conflict with the IP address of the external network, but two adjacent networks cannot use the same network number. Whether the network is adjacent mainly depends on the connection of the router. The networks connected to the router are all adjacent networks.
  • What are the addresses that can form a private network:
    ①10.*: Large private network
    ②172.16.-172.31.: Neutral private network
    ③192.168.: Small private network

Guess you like

Origin blog.csdn.net/weixin_42357849/article/details/107593626