Computer Networks - Network Layer 1.1

IPv4

When the network layer packs and transmits data, if the amount of data is small, it is called IP datagram, if the amount of data is large, it is fragmented, and each piece is called IPv4 packet

packet format

The fixed part is 20B long, and the variable part is used to provide mechanisms such as error detection and safety
insert image description here
insert image description here

  • Version: refers to the IP version
  • Header length: in units of 4B, the maximum value is 60B, and the commonly used 20B means that no option is used
  • Total length: the length of the sum of the header and data
  • Identification: counter, plus 1 for each datagram generated. Whenever the data packet length exceeds the network MTU, it must be fragmented. Each datagram fragment is copied once for the identification number for reassembly
  • Flag: Fragmentation can only be performed when the lowest bit MF is 1, MF=0 indicates the last fragmentation, and fragmentation can only be performed when the middle bit DF=0
  • Slice offset: the relative position of a certain slice in the original packet, in units of 8B
  • Header checksum: check the header of the packet, do not check the data part
  • Time-to-live TLL: The maximum number of routers that a datagram can pass through the network, which identifies the lifetime of the packet in the network to ensure that the packet will not loop forever in the network, -1 before forwarding, and discard when it is 0
  • Protocol: Indicate which transport layer protocol the data part adopts
  • Source address/destination address: IP address of sender/receiver
    insert image description here

Forwarding packet flow

  • 1. Take out the destination address and source address from the header
  • 2. Check whether the destination address is directly connected to the router, if so, deliver it directly to the destination host, otherwise it is indirect delivery, go to step 3
  • 3. If there is a specific route that matches the destination address in the routing table, it will be sent to the specified route, otherwise, go to step 4
  • 4. If there is a route to the destination address in the router, then send the datagram to the designated router, otherwise go to step 5
  • 5. If there is a default route in the routing table, it will be sent to the default route, if not, an error will be reported

When the IP address of the next-hop router is obtained, it is not directly filled in the datagram, but the IP address is converted into a MAC address, placed in the header of the MAC frame, and the next-hop router is found according to the MAC address, and transmitted in different networks , the source address and destination address of the MAC will change, but they will not change when the bridge forwards

IPv4 address

composition and classification

Each group office connected to the Internet is assigned a 32-bit globally unique identifier, which is divided into five types of AE. The
insert image description here
network number marks the network to which the host is connected, and the host number marks the host, which are unique
insert image description here

features

  • The IP address is divided into two parts, the network and the host number, so that the host number is assigned by the unit as the second level, and only the network number needs to be considered when forwarding packets, which is convenient
  • An IP address is an interface that marks a host and a link. When a host is connected to two networks, the host must have two IP addresses.
  • LAN connected by bridge, etc., the network number is still the same
  • All networks are equal
  • The network numbers of all networked devices in the same LAN are the same

NAT

Network address translation NAT hides the internal management IP address from the outside by converting the private network address into a public address. It allows the entire private network to be connected to the Internet with only one IP address, and the internal IP address can be reused, hiding the internal structure

private IP address

Private IP addresses rely on NAT to convert to legal IP addresses, and cannot be directly connected to the Internet. All routers in the Internet will not forward datagrams whose destination addresses are private addresses. This type of Internet using private IP addresses is called a private Internet or local Internet. Private IP address is also called reusable address
insert image description here

subnet

The utilization rate of the IP address space by the two-level IP address is sometimes very low. Assigning a network number to each physical network will make the routing table too large and deteriorate the network performance, and it is not flexible enough

Therefore, the subnet number field is proposed to form a three-level IP address, which is called subnetting

insert image description here
When forwarding, it is still forwarded according to the network number. After reaching the network of the unit, search for the destination host according to the subnet number

subnet mask

When the external network wants to obtain the subnet network of the unit, it needs to logically AND the IP address of the destination host with the subnet mask. The default subnet mask is both the network number and the subnet number are 1, and the host number area is 0
insert image description here
. When packet forwarding is required, each entry in the routing table needs to give the destination network address and next hop address, and the subnet mask of the destination network

All hosts and router ports belonging to the same subnet need to be set with the same subnet mask, which is similar
insert image description here
to the previous packet forwarding steps. First, check whether direct alternation is possible. If not, follow a specific route, which can be obtained from the routing table. Routing in the order of routing and default routing

Classless Inter-Domain Routing CIDR

Eliminate the concepts of ABC classes and subnets
insert image description here
Propose the concept of supernet/route aggregation, shorten the routing tableinsert image description here

Address Resolution Address ARP

The IP address is the address used by the network layer, which is hierarchical.

The hardware address is the address (such as MAC address) used by the data link layer, and it is flat.

The IP address is used on the network layer and above the network layer, and the IP address is placed in the header of the IP datagram.

The MAC address is placed at the head of the MAC frame.

Through data encapsulation, after the IP datagram packet is encapsulated into a MAC frame, the data link layer cannot see the IP address in the datagram packet.

No matter what protocol the network layer uses, it needs to use the hardware address when transmitting on the actual link, so a method is needed to complete the mapping from the IP address to the MAC address, which is the address resolution address protocol. Every host has an
ARP Cache, store ARP table, use ARP to dynamically maintain this ARP table
insert image description here

Dynamic Host Configuration Protocol - DHCP

Dynamically assign IP addresses to hosts, allowing hosts to obtain IP addresses after joining a new network without manual participation.
DHCP is essentially an application layer protocol based on UDP

working principle

insert image description here

Use C/S method

The host that needs an IP address will broadcast and send a discovery message to the DHCP server at startup. At this time, the host becomes a DHCP client, and all hosts on the local network can receive it, but only the DHCP server can respond and send an offer message.

The DHCP server first searches the configuration information of the corresponding host in the database, returns if found, and assigns an address from the IP address pool to the host if not found

Internet Control Message Protocol-ICMP

The ICMP protocol supports hosts or routers to improve the chance of forwarding IP data packets and delivering them successfully by sending characteristic ICMP messages for error reporting and network inquiry. ICMP messages
include ICMP error messages and ICMP query messages.
insert image description here

ICMP error report message

  • Destination unreachable: When a router or host cannot deliver a datagram, it sends a destination unreachable message to the source
  • Source Suppression: When a router or host discards a datagram due to congestion, it sends a source suppression message to the source to make the source slow down the transmission data rate
  • Time Exceeded: When the router receives a datagram with TLL=0, in addition to discarding the datagram, it will also send a Time Exceeded message to the source point. When the end point cannot receive all datagrams of a datagram within the predetermined time When the time exceeds the time limit, calculate all the datagrams received, and send the time-exceeded message to the source
  • Parameter problem: When the value of some fields in the header of the datagram received by the router or the destination host is incorrect, the datagram is discarded and a parameter problem message is sent to the source
  • Change route/redirection: The router sends the change route message to the host, so that the host can choose to send it to another router next time
    insert image description here

ICMP query message

Echo request and reply message: The host/router sends an inquiry to a specific host, and the host receiving this message must send an ICMP echo reply message to the source host/router to test whether the destination is reachable and its related status

Timestamp request and answer message: request a host/router to answer the current date and actual, clock synchronization and time measurement

ICMP application

The two common applications of ICMP are packet network detection PING and Traceroute/Tracert, which are used to test the connectivity between two hosts and track the route of the packet respectively. PING
uses the echo request and reply message, and
Tracert works at the application layer. Using the time exceeded message, working at the network layer

Guess you like

Origin blog.csdn.net/weixin_51109304/article/details/130992320