The network layer consists of three protocols
- ipv4: Internet Protocol Version 4
- icmp: internet control message protocol
- ipx: Internet packet exchange protocol (obsolete)
What does the network layer do
- ip addressing
- routing
IP header
Version: ipv4 or ipv6
Service type: distinguish data packets and identify a certain service frame
ttl: life cycle, every time a router is reduced by one
protocol: Serving the transport layer, select the resolution protocol (TCP (6) or UDP (17) or ICMP (1))
Representation of IP address
An ip address has 32 bits. For the convenience of memory, they are divided into 4 groups, each group is 8 bits, separated by a decimal point. Our common representation is commonly known as "dotted decimal"
The minimum is: 00000000.00000000.00000000.00000000 --> 0.0.0.0
The maximum is: 11111111.11111111.11111111.11111111 --> 255.255.255.255
Network bits and host bits
Network bits plus host bits must be 32 bits
The network part is to identify the different networks
The host part is to distinguish multiple hosts on different networks
IP address classification
mainly divided
- Type A: generally used by large enterprises, the high digit starts with 0, that is, 0xxxxxxx.xxxxxxxx.xxxxxxxx.xxxxxxxx (but 0 and 127 will be excluded in practice)
- Type B: generally used by medium-sized enterprises, the high digit starts with 10,
- Type C: generally used by small businesses, the high digit starts with 110,
- Type D: used for multicast, the high bit starts with 1110,
- Class E: for research, the high digit starts with 1111,
Class A default netmask: 8bit, 0.0.0.0~127.255.255.255/8
Class B default network mask: 16bit, 128.0.0.0~191.255.255.255/16
Class C default netmask: 24bit, 192.0.0.0~223.255.255.255/24
Classes D and E have no host and network bits.
Class A host bits 8, network bits 24
Class B host bit 16, network bit 16
Class C host bit 24, network bit 8
subnet mask
Distinguishing between the network part and the host part of an IP address
The method of calculating the subnet mask is: set the network position to 1 and the host position to 0. For example, the subnet mask of class C IP is:
11111111.11111111.11111111.00000000 is 255.255.255.0
website address
identify a network
The method of calculating the network address is: the network bits are unchanged, and the host bits are all 0. For example, the network address of 10.1.1.1 is
10.0.0.0
broadcast address
A special address used to send data to all hosts on the network
The method of calculating the broadcast address is: the network bit remains unchanged, and the host bit is all 1.
private IP address
Public network IP: uniformly assigned by IANA to ensure that any IP is unique on the Internet
Private network IP: In fact, some networks do not need to be connected to the Internet, as long as the network addresses of the same network do not conflict.
Private addresses cannot directly access the Internet and need to be converted by NAT
special IP address
How to Subnet
Two methods of subnetting (detailed steps)_sunshin boy's blog-CSDN blog_subnetting
ICMP redirection
Under certain circumstances, when a router detects that a machine uses a non-optimal route, it will send an ICMP redirect message to the host, requesting the host to change the route. For example, the sent message is sent to the server through the gateway. After optimization, it is sent directly to the server without going through the gateway.
ICMP error detection
The most classic is ping, sending a message and receiving a response. Probe the reachability of network nodes.
ICMP Error Reporting
The most classic is tracert, which traces the packet capture path hop by hop based on the ttl value of the packet header to detect network packet loss and delay.