Computer network learning-the network layer of the TCP/IP four-layer model

Network layer IP protocol related

IP protocol

Virtual interconnection network

When A needs to transmit data to B through multiple devices and networks, all that passes in the middle can be regarded as a virtual interconnection network, and there is no need to care about the details in the middle, and only end-to-end transmission is realized.
Insert picture description hereInsert picture description hereThe actual computer network is intricate and complicated. The physical device uses the IP protocol to shield the differences between the physical networks; when the hosts in the network use the IP protocol to connect, there is no need to pay attention to network details.

The IP protocol turns the complex actual network into a virtual interconnected network. The IP protocol enables the network layer to shield the underlying details and focus on data forwarding at the network layer. The IP protocol solves the problem of the datagram transmission path in the virtual network.

IP protocol

The difference between MAC address and IP address:
MAC address is unique and unchangeable, and each network device has its own unique MAC address.
The IP address is changeable, and is affected by the network environment. Different networks are connected to different IP addresses.
The length of the IP address is 32 bits, often divided into 4 8 bits; the
IP address is often expressed in dotted decimal notation (0~ 255.0~ 255.0~ 255.0~255)

The structure of the IP datagram and data frame:
Insert picture description hereThe format of the
Insert picture description here IP header : The first 5 lines of the IP header are required. Each line has 32 bits, that is, 4 bytes. The IP header must be at least 20 bytes long.
If the total length of the IP data is greater than the MTU (the transmission unit of the data link layer), the data link layer will fragment the IP protocol and divide the longer IP datagram into multiple frames for transmission.

Version : 4 digits, which refers to the version of the IP protocol. The versions of both parties must be consistent . The current mainstream version is 4, which is IPv4. There are also IPv6
headers. Length : 4 digits, the maximum value is 15, which means the IP header Length, the unit is "32-bit words" (4 bytes), that is, the maximum length of the IP header is 60 bytes. The
total length : occupies 16 bits, the maximum value is 65535, which represents the total length of the IP datagram (IP header +IP data)
TTL : occupies 8 bits, indicating the lifetime of an IP data message in the network. Every time a device passes through, the TTL is reduced by 1. When TTL=0, the network device must discard the message. Function: If the target device cannot be found, avoid unlimited transmission.
Protocol : occupies 8 bits, indicating what protocol the specific data carried by the IP data is (such as: TCP, UDP, etc.)
Header checksum : occupies 16 bits, check whether there is an error in the IP header

IP protocol forwarding process

Routing table: The computer or router has a routing table.
Insert picture description here
Only the data transmission process from computer A to computer C is viewed from the network layer:
Insert picture description here each device queries its own local routing table

View the data transmission process from computer A to computer C from the network layer and network interface layer:

A sends out an IP datagram with a destination of C, queries the routing table and finds that the next hop is E.
A delivers the IP datagram to the data link layer and informs that the destination MAC address is E. The
data link layer fills in the source MAC address A and the destination MAC address E
data link layer sends data to E routing table IP protocol forwarding process through the physical layer

The data link layer of E receives the data frame, and delivers the frame data to the network layer
E to query the routing table, and finds that the next hop is F
E. The datagram is delivered to the data link layer, and the destination MAC address is
the data of F E. The link layer encapsulates the data frame and sends it

The data link layer of F receives the data frame, and sends the frame data to the network layer
F to query the routing table, finds that the next hop is CF
, delivers the datagram to the data link layer, and informs
the data whose destination MAC address is CF The link layer encapsulates the data frame and sends it

We found:
1. The MAC address of each hop of the data frame is changing
2. The IP address of each hop of the IP datagram is always the same

Subnetting

Insert picture description hereSpecial
host number All 0s in the host number indicate the current network segment and cannot be assigned to a specific host
. All 1s in the host number indicate a broadcast address and send messages to all hosts in the current network segment. The
special network number
A type address network segment all 0 (00000000) indicates The
last 7 bits of the special network class A address network segment are all 1s (01111111:127) indicating that the loopback address
class B address network segment (10000000.00000000:128.0) is unusable and the
C address network segment (192.0.0) is unusable
Insert picture description here
127.0. 0.1, usually called the local loopback address (Loopback Address), does not belong to any class of address classes. It represents the local virtual interface of the device, so by default it is regarded as an interface that will never go down. There is a similar definition in the Windows operating system, so you can usually ping this local loopback address before installing the network card. It is generally used to check whether the local network protocol, basic data interface, etc. are normal.

Network address translation NAT technology

Network Address Translation (NAT)
NAT technology is used in a private network where multiple hosts access the Internet through a public IP.
NAT slows down the consumption of IP addresses, but increases the complexity of network communication.

Other protocols at the network layer

ARP protocol and RARP protocol

ARP (Address Resolution Protocol) address resolution protocol.
RARP (Reverse Address Resolution Protocol) reverse address resolution protocol.
Function: Convert the network layer IP 32-bit address to the data link layer MAC 48-bit address to obtain the destination MAC address of the next hop in the IP protocol forwarding process. Query the ARP cache table before knowing the destination MAC address.
Coordinate and complete the work of the network layer and the data link layer.

The structure of the ARP cache table:
Insert picture description hereWhen the ARP cache table does not cache the mapping relationship between the IP address and the MAC address, it is also obtained by broadcasting.

The ARP cache table is the key to the operation of the ARP protocol and the RARP protocol.
The ARP cache table caches the mapping relationship between IP addresses and hardware addresses.
The records in the ARP cache table are not permanently valid and have a certain period.
The ARP protocol is directly encapsulated in the data frame, and the IP address is used inside, so it belongs to the network layer.

Command line to view ARP cache table command:

arp -a

The RARP/ARP protocol is the basic protocol in the TCP/IP protocol stack.
The operation of ARP and RARP is transparent to the programmer.

ICMP protocol

Detailed ICMP protocol

Internet Control Message Protocol (Internet Control Message Protocol) The
ICMP protocol can report error messages or abnormal conditions.

IP protocol: transfer data.
ARP protocol: 32-bit IP address is converted to 48-bit MAC address.
RARP protocol: 48-bit MAC address is converted to 32-bit IP address.
ICMP protocol: encapsulated in IP datagrams, auxiliary IP protocol to transmit data.

Insert picture description here
Insert picture description here

ICMP protocol application

  • Ping application
    Ping loopback address 127.0.0.1
    Ping gateway address
    Ping remote address

  • Traceroute application
    Traceroute can detect the path taken by IP datagrams in the network

Guess you like

Origin blog.csdn.net/weixin_44776894/article/details/107449821