Computer network notes-2

IPv4

1. Introduction to IPv4 Packet Header

Insert picture description here
Explanation:

  • The version indicates the version number of the IP datagram, the length of the Internet header indicates the number of 32-bit words, the DS is the differentiated service field, and the ECN is the explicit congestion notification field. The total length of 16 bits indicates that an IPv4 data packet can be up to 2^16 bytes.
  • The minimum Ethernet payload is 46 bytes, and the host does not receive IP packets larger than 576 bytes
  • The identification field helps to identify the datagram sent by the IPv4 host and is used to implement fragmentation
  • The lifetime TTL is used to set the upper limit of the number of routers that a datagram passes through. It is reduced by 1 after each pass, and discarded when it reaches 0. (Prevent routing loops from causing datagrams to circulate forever)
  • The protocol field indicates the data type of the payload part of the datagram (17 means UDP, 6 means TCP). The
    header checksum only calculates the header.

2. IPv4 five types of addresses

Class A is reserved for government agencies, Class B is allocated to medium-sized companies, Class C is allocated to anyone who needs it, Class D is used for multicast, Class E is used for experiments, and the number of addresses that can be accommodated is different.

Insert picture description here

Class A address

  1. The first digit of the class A address network number is fixed to 0, and the other 7 digits can be assigned. The length of the host number is 24 digits, and the number of network numbers assigned is 2^7 = 128
  2. The address range is: 1.0.0.0—127.255.255.255
  3. 10.0.0.0-10.255.255.255 is a private address (the so-called private address is the address that is not used on the Internet but is used in the local area network. The router receives the private address and will not forward the packet to the Internet. Private address and NAT Related)
  4. 127.0.0.0-127.255.255.255 are reserved addresses, used for loop testing
  5. 0.0.0.0-0.255.255.255 is also reserved for special purposes
  6. Therefore, there are only 125 network numbers that can be allocated, and only 2^24-2=16777214 can be allocated for the host number of each network segment (the host number is all 0 and the host number is all 1 reserved)

Class B address

  1. The first and second digits of the class B address network number are fixed to 10, the other 14 digits can be allocated, and the length of the host number is 16 digits
  2. The address range is: 128.0.0.0—191.255.255.255
  3. 172.16.0.0-172.31.255.255 are private addresses
  4. 169.254.0.0—169.254.255.255 are reserved addresses (if your IP address is automatically obtained, and you do not find an available DHCP server on the network. You will get one of the IPs)
  5. The host number that can be allocated to each network segment is 2^16-2 = 65534 (the host number is all 0 and the host number is all 1 reserved)

Class C address

  1. The first 3 digits of the Class C address network number are fixed at 110, the other 21 digits can be allocated, and the length of the host number is 8 digits
  2. Class C address range: 192.0.0.0—223.255.255.255
  3. 192.168.0.0—192.168.255.255 is a private address
  4. The number of blocks that can be allocated to the network number is 2^21 = 2097152, and the number of host numbers that can be allocated without a network number is 2^8-2 = 254 (the host number is all 0 and the host number is all 1 reserved)

Class D address

  1. Class D IP address does not mark the network, the first 4 bits are fixed at 1110
  2. The address range is: 224.0.0.0—239.255.255.255
  3. Used for special purposes, such as multicast addresses

Class E address

  1. Class E address does not distinguish between network address and host address, the first four bits of its first byte are fixed at 1111
  2. Class E address range: 240.0.0.0—255.255.255.255
  3. For some experiments and future use

3. NAT

NAT separates the address space of the internal system from the address space of the Internet, and all internal systems can access the Internet using a locally assigned private IP.

The working principle of NAT is to rewrite the identification information of data packets passing through the router. (Modify the source IP address of the data packet to the address of the internet-facing network interface, and modify the check code at the same time)

NAT is divided into basic NAT and NAPT

  • Basic NAT uses the address in the address pool to rewrite the IP. Two IPs are required from the same port
  • NAPT will rewrite the port number to distinguish traffic from different hosts

The host in the NAT initiates the TCP connection process:

  1. The destination is the Web server host (IPv4 address 212.110.167.157), and the data packet is represented as (source IP: port is 10.0.0.126: 9200, destination IP: port is 212.110.167.157: 80).

  2. As the default router, NAT will receive this packet. Note that the SYN flag in the TCP header is open, which is a new connection. The source IP in the data packet will be modified to the IP of the external interface of the NAT router (source IP: port is 63.204.134.177: 9200, destination IP: port is 212.110.167.157: 80), and then the data packet is forwarded.

  3. NAT also creates an internal state (NAT session) that represents the processing of new connections. The state includes at least the source port and IP of the client, which is called NAT mapping.

  4. The server replies with the NAT external address and initial port (port reserved). After NAT receives it, it compares the mapping and determines the internal host.

IPv6

IPv6 address representation

Under the IPv6 binary system, the length is 128 bits, with 16 bits as a group, each group is separated by a colon ":", which can be divided into 8 groups, each group is represented by a 4-digit hexadecimal system, and the leading 0 of each group The
IPv6 address can be omitted . It usually consists of two logical parts: a 64-bit network prefix and a 64-bit host address. The host address is usually automatically generated based on the physical address and is called EUI-64.

IPv6 address classification

There are three types of IPv6 addresses:

  • Unicast address A
    unicast address indicates a network interface. The protocol will send the data packet sent to the address to its interface.
    IPv6 requires that the subnet of all unicast addresses must be 64 bits
  • Anycast (anycast) address
    Anycast is a unique way to send data in IPv6. Like IPv4 multicast, there will be a list of addresses of receiving nodes, but the data packets designated as Anycast will only be sent to the nearest or lowest sending cost. (Judging from the routing table) one of the receiving addresses, when the receiving address receives the data packet and responds, and joins the subsequent transmission. The other nodes in the receiving list will know that a certain node address has responded, and they will no longer join the subsequent transmission operation.
    Taking the current application as an example, the Anycast address can only be allocated to intermediate devices (such as routers, Layer 3 switches, etc.), not to terminal devices (mobile phones, computers, etc.), and cannot be used as the address of the sender.
  • Multicast address
    Multicast address is also called multicast address. The multicast address is also assigned to a group of different interfaces, and packets sent to the multicast address will be sent to all addresses. Multicast addresses start with bytes that are all one, that is, their prefix is ​​FF00::/8. The last four bits of the second byte are used to indicate the "category".

IPv6 special address

IPv6 special address (using double colon "::" to indicate a group of 0 or more consecutive groups of 0, but it can only appear once)

  • Unspecified address
    ::/128-An address where all bits are zero is called an unspecified address. This address cannot be assigned to a network interface, and will only be used in the software when the host does not know its source IP. The router cannot forward data packets containing unspecified addresses.
  • Link local address
    ::1/128-is a unicast wraparound address. If an application sends packets to this address, the IPv6 stack will forward these packets back to the same virtual interface (equivalent to 127.0.0.1/8 in IPv4).
    fe80::/10-These link-local addresses indicate that these addresses are only valid in the area connection, which is similar to 169.254.0.0/16 in IPv4.
  • Unique locale field
    fc00::/7—Unique local address (ULA) can only be routed in a group of websites. This is defined in RFC 4193 and is used to replace the site-local status domain. This address contains a 40-bit pseudo-random number to reduce the risk of collisions when websites are merged or data packets are mistransmitted to the network. These addresses can only be used in regions, but also have a global scope, which violates the definition of site-local addresses replaced by unique region bit fields.
  • Multicast address
    ff00::/8-This prefix indicates the multicast address defined in "IP Version 6 Addressing Architecture" (RFC 4291) [11]. Among them, some addresses have been used to specify special protocols, such as ff0X::101 corresponding to NTP servers in all areas (RFC 2375).

IPv6 packet

Insert picture description here

An IPv6 packet consists of two main parts: header and payload.
The packet header is the first 64 bits of the packet and contains the protocol version, communication type (8 bits, packet priority), flow mark (20 bits, QoS service quality control), packet length (16 bits), and the next header (used for Stack decoding, similar to the protocol number in IPv4), limit on the number of hops (8 bits, time to live, equivalent to TTL in IPv4), source and destination addresses. Behind is the load.
The MTU is at least 1280 bytes long, which is 1500 bytes in a common Ethernet environment. The maximum load can be 65535 bytes in standard mode.
The header is fixed at 40 bytes, and the extended header is only added when needed. There is a next header field in the header, which can form a concatenated header.

IPv6 protocol

Protocol:
ICMPV6: internet control management protocol, sub-protocols:
1. PMTU—Path MTU discovery protocol uses ICMPV6 error packet to obtain the minimum MTU value on the entire path
2. NDP—Neighbor Discovery Protocol—used to replace IPV4 Under the ARP protocol
3. Prefix notification ------ auto-config Only the
IPv6 unicast routing function exists in the Ethernet environment . After this function is turned on, the auto-config on the device is activated, and the IPV6 routing protocol can be sent and received at the same time Information; and can route ipv6 traffic, provided that the router interface already has a valid ipv6 unicast address;
as long as the IPV6 unicast routing function is turned on on the router, the router will send to all Ethernets with IPV6 addresses The interface sends the prefix of its address periodically

Comparison of IPv4 and IPv6

Link: The difference between IPv4 and IPv6 is super detailed

Route forwarding

The difference between a host and a router in processing datagrams: the host does not forward datagrams that are not generated by him, but the router will forward them.
The host can also be configured as a router

Direct delivery and indirect delivery

In IP forwarding, if the source host and the destination are in the same Ethernet (without a router, they have the same network number after calculating with the network subnet mask), the datagram is sent directly to the destination, which is called direct delivery.

In direct delivery , because in the same network segment, only the switch forwarding principle is involved (learning the source MAC and forwarding according to the destination MAC), IP datagrams are encapsulated into frames, and data decapsulation will only be solved to the second layer (link layer). The source of the data can already be identified.
The source host sends an ARP request broadcast packet, requesting the MAC address of the destination host. After receiving the ARP reply of the destination host, obtain its MAC address, and then send the message as the destination MAC.
Switch principle: The
switch receives a data packet from a certain port, it will first read the source MAC address in the packet, then read the destination MAC address in the packet, and look up the corresponding port in the address table, as shown in the table If there is a port corresponding to the destination MAC address, the data packet is directly copied to this port.

For the detailed process, see: Computer Network Notes 1 MAC Address Learning Process

In indirect delivery , the principle of router forwarding is involved.
The forwarding principle of the router is to forward according to the routing table. Only if there is a route in the routing table, it will be forwarded, and if there is no route, it will be directly discarded.

Routing and forwarding process

(Assuming that no hardware forwarding entries have been established on the Layer 3 switch)

  • The source host judges that the destination host is located on a different network segment from itself, and first sends an ARP request to obtain the MAC corresponding to the gateway IP address. After receiving the response, it sends the message using the gateway MAC as the destination MAC of the message.

  • When the router receives a message, it first updates the MAC address table according to the source MAC. Because the switch chip (ASIC) has not established any table entries, it sends the message to the CPU for processing.

  • The CPU will decapsulate the message to the third layer and check the destination IP address in the IP header. Then use the bitwise AND operation of the mask to find whether there is a route in the routing table (matching direct route, longest prefix matching algorithm)

  • If it has, it will be forwarded (assuming that the MAC of the next hop is known). Routing forwarding determines the interface (the network interface of the next hop) and the next hop (the IP address of the router or host).

  • When the router forwards to the next router, it replaces the source MAC address of the message with the MAC address of the outgoing interface, replaces the destination MAC address of the message with the next hop MAC address, and decreases the TTL by 1. And the corresponding destination IP, next hop MAC, outgoing interface and other information are stored in the hardware forwarding table. Subsequent messages sent to the same network segment can be directly forwarded through the switching chip.

  • After the destination host receives the message, it decapsulates it to the third layer and sends a response packet.

Guess you like

Origin blog.csdn.net/MinutkiBegut/article/details/112847082