Computer Network (IP)


The IP protocol is at the network layer, and the main tasks are: address management, routing selection

IP protocol header format

insert image description here

4位版本号(version):Specifies the version of the IP protocol, which is 4 for IPv4. (IPv4 is commonly used now, and there is a 6-bit version number, IPv6, which is rarely used now)
4位首部部长度(header length):The length of the IP header is 32 bits, which is the number of bytes of length * 4. 4bit means that the maximum number is 15, so the maximum length of the IP header is 60 bytes. (Similar to TCP, it is variable and has options).
8位服务类型(Type Of Service):In fact, there are only 4 effective bits ( 4位TOS分别表示:minimum delay, maximum throughput, maximum reliability, minimum cost...At the same time, only one state can be taken, You can compare TOS here to switching form (same as transforming, [Diga's three forms switching this]))
16位总长度(total length):How many bytes does the IP datagram occupy as a whole. The maximum length of a single IP datagram cannot exceed 64k
. What if a longer datagram is to be formed (for example, the load part of the payload has exceeded 64k)?
==> That is, the IP protocol itself implements subcontracting and grouping. Operation, the following three fields are used for subcontracting and grouping

16位标识(id):Uniquely identifies the packets sent by the host. If the IP packet is fragmented at the data link layer, the id in each fragment is the same.
3位标志字段:The first one is reserved (reserved means that it is not used now, but I haven't thought about it, maybe it will be used in the future). The second bit is 1 to prohibit fragmentation. At this time, if the packet length exceeds the MTU, the IP module will discard the packet. The third bit means "more shards", if sharded, the last shard is set to 1, the others are 0. Similar to a closing tag.
13位分片偏移(framegament offset):is the offset of the fragment relative to the beginning of the original IP packet. In fact, it indicates where the current fragment is in the original packet. The actual number of bytes offset is obtained by this value * 8. Therefore, except for the last packet, the length of other packets must be an integer multiple of 8 (otherwise the packets will not be consecutive).
insert image description here

8位生存时间(Time To Live,TTL):The maximum number of packet hops for a datagram to reach its destination. Usually 64. Every time a route is passed, TTL -= 1, and it has been reduced to 0 and has not been reached, then it is discarded. This field is mainly used to prevent routing loops. (That is, how long can this IP datagram exist on the network, every time the IP datagram passes through a router, the TTL will be reduced by one, if it is reduced to 0, it means that the IP address in these packets may never be reached. , can't let him forward endlessly on the network (occupy hardware resources), and lose him when it reaches 0)
8位协议: indicates the type of the upper-layer protocol. (Which protocol is used by the transport layer, TCP or UDP have different values)
16位头部校验和:Use CRC for verification to identify whether the header is damaged. (It is used to check whether the data is correct)
32位源地址和32位目标地址:indicates the sender and the receiver. For IPv4, an IP address is essentially a 32-bit integer...usually "dotted decimal" is used to represent the IP address...three dots divide a 32-bit integer into 4 parts, each part 1 word Section, the value of each part is 0 ~ 255 (8 1s is 255)
like this: 192.168.0.1, it is usually dotted decimal for people to see, the IP stored for the machine is still in accordance with 4 at the bottom byte integer

address management

The IP address is mainly divided into two parts: network number (describes the current network segment information [identification of the local area network]) + host number (distinguishes the hosts inside the local area network...)
Requirements: In the same local area network, the network number between the hosts is The same, the host number cannot be the same, two adjacent LANs (connected to the same router), the network number is also different...

insert image description here
How many bits are the network number? What is the regulation? Are there three specified bytes?

In fact, this is not fixed. The concept of "subnet mask" is introduced here to indicate how many bits are the network number
子网掩码. It is also a 32-bit, dotted decimal integer. The left side is 1, and the right side is 1. The sides are all 0 (not mixed with 0 and 1), the 1s on the left indicate which are the network numbers, and the remaining 0s indicate which bits are the host numbersinsert image description here

Some special IP addresses:

1:如果IP的主机号全0,该IP就表示网络号(局域网里的一个正常设备,主机号不能设为0)
2:如果IP主机号全为1,该IP就表示"广播地址",往往广播地址上发的消息,整个局域网中都能找到
3:IP地址是127开头的,该IP都表示"环回IP",表示自己主机
4:IP地址是10开头,192.168开头,172.16 - 172.31开头,表示该IP地址是一个局域网内部的IP(内网IP),剩下的都是外网IP(直接在广域网上使用的IP)

It is required that the external network IP must be unique. Each external network IP will correspond to a unique device. The internal network IP is only unique in the current local area network. Different local area networks can have devices with the same internal network IP.

How to solve the problem of insufficient IP address?

Let each device be assigned a unique IP address, so many devices, how much?

Dynamically assign IP addresses

Let each device have an IP when it is connected to the Internet. If it is not connected to the Internet, there is no IP. Let this IP be used by others, but this solution cannot fundamentally solve the problem (the device is not reduced, and the IP is not increased)

NAT mechanism

Let multiple devices share the same IP (external network IP), and in the current network environment (just like a school's students fill in a school's delivery address),
the network is divided into an internal network (LAN) and an external network (wide area network). ), it is required that the external network IP must represent a unique device, and at the same time several devices in the internal network can share an external network IP (that is, the internal network can appear repeatedly, and it is unique only in the current local area network)

IPv6

IPv6 uses a longer field in the header to represent the IP address
16 bytes, 128 bits
insert image description hereeach digit is a hexadecimal number (4bit), each colon splits two bytes, the biggest problem That is, IPv6 and IPv4 are not compatible, otherwise IPv6 may be used more

routing

That is to say, planning a path. To find a channel between two devices to complete the transmission process, it is necessary to know the path.
The routing selection of the IP protocol is also similar. The destination address in the IP datagram represents this Where to send the packet, if the current router does not know it, it will tell you a general direction, go there and ask again, get closer and you are there...

data link layer

insert image description hereThe source address and destination address are represented by 6 bytes, which is more than 6w times longer than IPv4...
The address here is called "mac address",
mac地址so that each device is one (each network card is unique)
The mac address and IP address are used at the same time to indicate different functions:
IP is used to indicate the starting point and end point of a transmission process (regardless of NAT, the source IP and destination IP in an IP datagram are fixed)
mac is used for Indicates the address between any two adjacent nodes during the transmission process (an Ethernet data frame, in each forwarding process, the source mac and destination mac will change)

MTU

The data range that an Ethernet data frame can carry depends on the hardware device.
Ethernet is also closely related to hardware. Other hardware devices, corresponding to the data link layer protocol, may be different, and the MTU is also different from the
data link . The layer considers the data transmission between adjacent nodes. When considering this detail, you should pay attention to what the means of transportation are. What
if the datagram exceeds the MTU?
IP layer packetization

DNS protocol

It is an application layer protocol, that is, the domain name resolution
IP address is not easy to remember, so a string of English words are used to represent the IP address, which is a one-to-one correspondence.

Guess you like

Origin blog.csdn.net/chenbaifan/article/details/124227832