【Computer Network】——Communication protocol overview (network protocol, network layering, ifconfige command line, DHCP and PXE)

1. Why learn network protocols

Three elements of the agreement:

There needs to be an agreement between humans and computers to communicate , and only through this agreement can the computer know what we want it to do.

It can be seen that computer language, as a protocol for programmers to control the work of a computer, has the three elements of the protocol.

Grammar means that the content of this paragraph must conform to certain rules and formats. For example, pair parentheses, end with a semicolon,
etc.
Semantics means that this paragraph of content should represent a certain meaning. For example, subtracting numbers from numbers makes sense,
but subtracting text from numbers generally doesn't.
The sequence is what to do first and what to do later. For example, you can first add a value and then subtract a value.

Only through network protocols can a large group of machines cooperate with each other and accomplish one thing together.

So what does a network protocol look like? What can you do?

If you want to buy a product, the conventional method is to open a browser and enter the address of the shopping website . The browser will show you a colorful page . Have you ever thought deeply about how browsers do this? The reason why it can display colorful pages is because it receives a piece of "stuff" from the HTTP protocol .

Take Netease Kaola as an example, the format is as follows:

First of all, it conforms to the grammar , that is to say, only according to the above format, the browser will recognize it. For example, up comes the status,
then the header, then the content.
Second, it conforms to the semantics , that is, it must follow the agreed meaning. For example, status 200 means that the web page is returned successfully
. If it is unsuccessful, it is our common "404".
Third, in accordance with the order , you click on the browser to send an HTTP request, and then there is the above string of HTTP
returned things.
The browser obviously did what was agreed in the agreement, and the last colorful page appeared in front of you.

 What are our commonly used network protocols?

Use the process of placing an order to see which network protocols are used in the operation of the Internet world.

First enter https://www.kaola.com in the browser, which is a URL .

                                        ↓

The browser only knows that the name is "www.kaola.com", but does not know the specific location, so it does not know how to access it .

                                        ↓

It opens the address book to look it up . You can use the general address book protocol DNS to search, and you can also use another more precise address book search protocol HTTPDNS .

                                        ↓

No matter which method you use to search, you will eventually get this address : 106.114.138.24. This is the IP address , which is the "house number" of the Internet world.

                                        ↓

Knowing the target address, the browser starts packaging its request .

Knowing the target address, the browser starts packaging its request. For ordinary browsing requests , the HTTP protocol is often used ;

However, for shopping requests, encrypted transmission is often required , so the HTTPS protocol will be used. No matter what the agreement is, it will state "what and how much you want to buy". 

The layer where DNS, HTTP, and HTTPS are located is called the application layer

                                         ↓

After application layer encapsulation, the browser will hand over the application layer package to the next layer for completion, which is realized through socket programming . The next layer is the transport layer .

                                         ↓

There are two protocols in the transport layer , one is the connectionless protocol UDP , and the other is the connection-oriented protocol TCP .

For payments, the TCP protocol is often used. The so-called connection-oriented means that TCP will ensure that the packet can reach the destination. If it cannot arrive, it will be resent until it arrives.

                                         ↓

There are two ports in the TCP protocol , one is the port monitored by the browser , and the other is the port monitored by the e-commerce server . The operating system often judges which process the package it gets should be given through the port.

                                         ↓

After the transport layer is encapsulated, the browser will hand over the packet to the network layer of the operating system .

The protocol of the network layer is the IP protocol . In the IP protocol, there will be a source IP address , that is, the IP address of the machine where the browser is located and a target IP address , that is, the IP address of the server where the e-commerce website is located.

                                         ↓

Now that the operating system knows the target IP address , it starts to think about how to find the target machine based on this house number .

                                         ↓

The operating system often judges whether the target IP address is a local or a foreigner . If you are a local, you can tell from the house number, but obviously the e-commerce website is not in the local area, but in a distant place.

                                         ↓

If you go to a foreign country, you have to go to the customs, and you have to go to the gateway when you go to other places .

When the operating system is started, the IP address will be configured by the DHCP protocol, as well as the default gateway IP address 192.168.1.1.

                                         ↓

How does the operating system send the IP address to the gateway?

                                         ↓

Local communication basically relies on roaring, so the operating system roars, who is 192.168.1.1? The gateway will answer it, I am, my local address is at the east end of the village. This local address is the MAC address , and the roaring sound is the ARP protocol .

                                         ↓

So the operating system handed over the IP packet to the next layer, which is the MAC layer .

The network card then sends the packet out. Because there is a MAC address in this packet, it can reach the gateway.

                                         ↓

The gateway is often a router , how to go to a certain IP address, this is called the routing table .

                                         ↓

The router is a bit like the city gates of the countries that Xuanzang passed through on his westward journey . Each city gate is connected to two countries , and each country is equivalent to a local area network . Within each country , local address MAC can be used for communication .

                                         ↓

Once you cross the city gate, you need to take out the IP header, which says that the poor monk is from the Tang Dynasty in the East (that is, the source IP address), and wants to go to the west to worship Buddha and ask for scriptures (referring to the target IP address). Passing by Baodi, staying overnight, starting tomorrow, how should I go next? 

Chengguan often knows this "knowledge", because Chengguan and neighboring Chengguan often communicate with each other. Where to go and how to go, this kind of communication protocol is called routing protocol , commonly used are OSPF and BGP

                                         ↓

There is a country between Chengguan and Chengguan. When the network packet knows which Chengguan to go to next, it still needs to use the MAC address of the country to find the next Chengguan through the MAC address of the next Chengguan, and then ask the next step. Go until you walk out of the last gate.

                                         ↓

The last gate knows where this network packet is going. So, shout at this country, who is the target IP? The target server will reply with a MAC address. After the network packet passes the customs, the target server can be found through this MAC address.

                                         ↓

The target server finds that the MAC address matches, removes the MAC header, and sends it to the network layer of the operating system. It is found that the IP is also correct, and the IP header is removed. A layer of encapsulation will be written in the IP header, which is the TCP protocol, and then it will be handed over to the transport layer, that is, the TCP layer.

                                         ↓

That is to say, if the MAC address is matched , it will be followed by -> pick the MAC header -> pick the IP header -> pick the TCP header

                                         ↓

In this layer, for each packet received, there will be a reply packet indicating that it has been received. This reply packet is by no means the result of this order request , such as whether the shopping was successful, how much money was deducted, etc., but just a description of the TCP layer, that is, the reply after receipt. Of course, for this reply, I will walk back in the direction I came just now, and report that I am safe.

                                         ↓

Because once you leave the country, the journey to the west is full of difficulties and dangers. What if the network packet is lost during the process, such as entering the desert, or being robbed and killed by robbers? So when I arrived, I wanted to report my safety.

                                         ↓

If it still hasn't arrived after a while, the TCP layer at the sending end will resend the packet , and the above process will continue until one day a reply arrives safely.

                                         ↓

This retry is by no means your browser re-requesting the action of placing an order.

                                         ↓

For the browser, an order request is sent , and the TCP layer keeps retrying on its own . Unless there is a problem with the TCP layer, for example, the connection is broken, it is the turn of the browser's application layer to resend the order request .

                                         ↓

When the network packet arrives at the TCP layer safely, the TCP header contains the target port number . Through this port number, it can be found that the process of the e-commerce website is listening to this port number . Assuming a Tomcat, send this packet to the e-commerce website. 

                                         ↓

The process of the e-commerce website gets the content of the HTTP request, and knows what to buy and how much to buy.

Often the Tomcat that initially receives the request on an e-commerce website is just a receptionist, responsible for coordinating and processing the request , instead of doing everything by itself.

                                         ↓

For example, the receptionist needs to tell the order management process, register to buy a certain product, how much to buy, tell the inventory management process, how much to reduce the inventory, tell the payment process, how much should be paid, and so on.

                                         ↓

How to tell the relevant process?

                                         ↓

It is often implemented through RPC calls, that is, remote procedure calls.

                                         ↓

The remote procedure call means that when telling the management order process, the receptionist does not need to care about the network interconnection problem in the middle, and it will be handled uniformly by the RPC framework. There are many kinds of RPC frameworks, some based on the HTTP protocol are placed in the HTTP message, and some are directly encapsulated in the TCP message.

                                         ↓

When the receptionist finds that the corresponding department has finished processing, he will reply with an HTTPS packet , informing the success of the order. This HTTPS package, like when it came, will go through all kinds of difficulties and dangers to reach your personal computer, and finally enter the browser, showing that the payment is successful.

Summarize: 

 


2. What is the real meaning of network layering?

Why is the network layered? 

Because it is a complex program that must be layered.

Complex programs must be layered, which is a requirement of program design. For example, complex e-commerce is also divided into database layer, cache layer, compose layer, controller layer and access layer, and each layer focuses on its own work.

How does the program work? 

The relationship between layers: 

All metaphors that do not express the meaning of layer-by-layer encapsulation are inappropriate.

When the general managers communicate with each other, the manager puts the general manager in his pocket, then the team leader puts the manager in his pocket, and the employees put the team leader in their pockets, just like a set of dolls. It would be inappropriate for the employee to communicate directly without the general manager.

In the online world, it should be the general manager who speaks, the manager adds two sentences, the team leader adds two sentences, and the employee adds two sentences.


What are the IP and MAC layers doing during the three-way handshake of TCP? Of course, every message sent by TCP will carry the IP layer and MAC layer. Because, every time TCP sends a message, all the mechanisms of the IP layer and the MAC layer have to run again. And you only see the TCP three-way handshake. In fact, the IP layer and the MAC layer have been busy for a long time.

Here's something to keep in mind:

As long as the package runs on the network, it is complete. There can be a lower layer without an upper layer, but it is absolutely impossible to have an upper layer without a lower layer.

Therefore, for the TCP protocol, whether it is a three-way handshake or a retry, as long as you want to send a packet, you must have an IP layer and a
MAC layer, otherwise you will not be able to send it out.


We all know the IP address of that machine, so send him a message directly, why do we need the MAC address? The key here is that messages cannot be sent without a MAC address.

So if an HTTP protocol packet runs on the network, it must be complete. No matter which devices the package passes through, it remains intact.


The so-called second-tier devices and third-tier devices are just different programs running on these devices.

An HTTP protocol packet passes through a layer-2 device, and what the layer-2 device receives is the entire network packet. There are HTTP, TCP, IP, and MAC.

What is a layer 2 device? Just take off the MAC header to see whether it is discarded, forwarded, or kept for yourself.

So what is a three-layer device? After removing the MAC header, remove the IP header to see if it is discarded, forwarded, or kept.

Summarize:

Always keep in mind a principle: as long as the package is running on the network, it is complete. There can be a lower layer without an upper layer, but it is absolutely impossible to have an upper layer without a lower layer.


3. ifconfig: the most familiar and unfamiliar command line

How to check IP address:

This is ipconfig on Windows and ifconfig on Linux.

Do you know of any other commands to view IP addresses on Linux?

The answer is ip addr. If you can't answer this question, then you probably haven't used Linux much.

Do you know the difference between ifconfig and ip addr?

There is no need to understand such details for the time being, but this is also a knowledge point that is often tested.

Imagine that you log into a very small Linux system that has been cut and found that there is neither ifconfig command nor ip addr command. Do you feel that this system is useless at all? At this time, you can install the two tools net-tools and iproute2 by yourself. Of course, most of the time these two commands come with the system.

After installation, let's run ip addr. Not surprisingly, the following should be output.

This command shows all network cards on this machine. Most network cards will have an IP address, of course, this is not required. In the following sharing, we will encounter the situation that there is no IP address.

The IP address is the communication address of a network card in the network world, which is equivalent to our house number in the real world .

The purpose of the IP address: to distinguish the address information.

Since it is a house number, it cannot be the same for everyone , otherwise there will be conflicts.

As the result of the above output, 10.100.122.2 is an IP address. The address is divided into four parts separated by dots, each part is 8 bits, so the IP address is 32 bits in total.

That is to say: the IP address is composed of 4 groups of 8-bit binary.

The resulting number of IP addresses quickly becomes insufficient.

Because it is not enough, there is IPv6 , that is, inet6fe80::f816:3eff:fec7:7975/64 in the above output. This has 128 bits, which seems to be enough now, but who knows what will happen in the future?

 The original 32-bit IP address is not enough, and it is divided into 5 categories.

In the network address, at least when it was designed at that time, there are mainly two parts for classes A, B, and C. The first part is the network number , and the latter part is the host number .

 This is easy to understand, for example:

Everyone is No. 1001, Unit 6,

I am No. 1001, Unit 6 of Community A, and you are No. 1001, Unit 6 of Community B.


The table below shows in detail the number of hosts that can be included in the three types of addresses A, B, and C.

The maximum number of hosts that a class C address can contain is too small, only 254.

And the maximum number of hosts that can be included in the class B address is too much.

More than 60,000 machines are placed under one network, and ordinary enterprises basically cannot reach this scale, and idle addresses are a waste.

Typeless Inter-Domain Routing (CIDR) 

This method breaks the practice of several types of addresses originally designed, and divides the 32-bit IP address into two, with the network number in front and the host number in the back.

10.100.122.2/24 , this IP address has a slash in it, followed by the number 24. This address representation is CIDR .

24 means that among the 32 bits, the first 24 bits are the network number, and the last 8 bits are the host number.

 

 In order to solve the unreasonable allocation, the subnet mask was born.

 

 

 

 

Along with CIDR, one is the broadcast address , 10.100.122.255. If this address is sent, all machines in the 10.100.122 network can receive it. The other is the subnet mask , 255.255.255.0.

AND the subnet mask and IP address.

The first three 255 are all 1 when converted into binary. 1 and any value take AND, which is the original value, so the first three numbers remain unchanged, which is 10.100.122.

The latter 0 is 0 when it is converted into binary, and if 0 and any value are ANDed, they are all 0, so the last number becomes 0, and the combination is 10.100.122.0 .

This is the network number. The network number can be obtained by ANDing the subnet mask and the IP address bit by bit .

Public and private IP addresses

The rightmost column of the table is the private IP address range .

In the data center we usually see, the IP addresses of offices, homes or schools are generally private IP address segments.

Because these addresses allow the IT staff within the organization to manage and assign themselves, and they can be repeated.

Therefore, a certain private IP address segment of your school may be the same as that of my school.


The public IP address is assigned uniformly by an organization, and you need to buy it.

If you build a website for people in your school to use, just ask your school's IT staff to give you an IP address. But if you want to make a website like NetEase 163, you need a public IP address so that people all over the world can visit it.


192.168.0.x in the table is the most commonly used private IP address. If you have Wi-Fi at home, you will have an IP address corresponding to it. Generally, there are no more than 256 Internet devices in your home, so /24 is basically enough. Sometimes we can also see CIDR of /16, these two are the most common and the easiest to understand.


Without converting decimal to binary 32 bits, it is obvious that 192.168.0 is the network number followed by the host number.
And the first address 192.168.0.1 in the entire network is often the egress address of your private network.

For example,
if your home computer is connected to Wi-Fi, the address of the Wi-Fi router is 192.168.0.1, and 192.168.0.255 is the broadcast address. Once this address is sent, all machines in the entire 192.168.0 network can receive it.

Example: A CIDR that is prone to "mistakes"

Let's look at the CIDR of 16.158.165.91/22. Find the first address, subnet mask, and broadcast address of this network.

If you just write 16.158.165.1 when you come up, you are making a big mistake.

/22 is not an integer multiple of 8, so it is difficult to handle, so it can only be viewed in binary. The 16.158 part doesn't move, it occupies the first 16 positions. The middle 165 becomes 10100101 in binary.

Supplement becomes a binary fast method:

In addition to the previous 16 bits, there are 6 bits left. So, the first 6 of these 8 bits are the network number, 16.158.<101001>, and <01>.91 is the machine number.

The first address is 16.158.<101001><00>.1, which is 16.158.164.1.

The subnet mask is 255.255.<111111><00>.0, which is 255.255.252.0.

The broadcast address is 16.158.<101001><11>.255, which is 16.158.167.255.

The first address is 16.158.164.1.

The subnet mask is 255.255.252.0.

Broadcast address 16.158.167.255.


Among these five types of addresses, there is another type D type which is a multicast address.

With this type of address, all machines belonging to a certain group can receive it. This is a bit like everyone in the company joined a mailing group. Send an email and everyone who joins this group will receive it. The multicast address will be mentioned later when describing the VXLAN protocol.

There is a scope behind the IP address. For the eth0 network card, it is global, indicating that this network card can be external and can receive packets from various places. For lo, it is host, which means that this network card can only communicate with each other locally.
The full name of lo is loopback, also known as the loopback interface, which is often assigned to the address 127.0.0.1. This address is used for
local communication, and returns directly after being processed by the kernel, and will not appear in any network.

MAC address

The line above the IP address is link/ether fa:16:3e:c7:79:75 brd ff:ff:ff:ff:ff:ff, this is called the MAC address, which is the physical address of a network card. Hexadecimal, represented by 6 bytes.

The MAC address is said to be globally unique, and no two network cards will have the same MAC address, and the network card will carry this address since it is produced.


In this case, all communications on the Internet should use MAC addresses, which is of course not acceptable. For a network packet to be transmitted from one place to another, in addition to having a definite address , it also needs to have a positioning function . Only the IP address with house number attribute has remote location function .

The MAC address is more like an ID card, a unique identifier. Its unique design is for networking, when different network cards are placed in a network, there is no need to worry about conflicts. From a hardware perspective, ensure that different network cards have different identifiers.

Internet communication is equivalent to going to Liu Chao on the 6th floor of Building B, No. 599 Wangshang Road, Hangzhou City. If you ask for directions on the road, the person you ask may not know which building B is, but they can give you directions to Wangshang Road. . But if you ask a person, do you know where the person with this ID number is? Predictably, no one knew.


The MAC address has a certain positioning function, but the range is very limited.

You can find the 6th floor of Building B, No. 599, Wangshang Road, Hangzhou City according to the IP address, but you still can’t find me, so you can rely on yelling, who is it that shouted ID card XXXX? I hear it, and I stand up and say, it's me. But if you are in Shanghai, who is calling ID card XXXX everywhere, I am not there, of course I will not answer, because I am in Hangzhou and not in Shanghai

Therefore, the communication range of the MAC address is relatively small, limited to a subnet. For example, accessing 192.168.0.3/24 from 192.168.0.2/24 can use the MAC address. Once the subnet is crossed, that is, from 192.168.0.2/24 to 192.168.1.2/24, the MAC address will not work, and the IP address will work.

Status identification of network devices

 After parsing the MAC address, let's look at what <BROADCAST, MULTICAST, UP, LOWER_UP> does? This is called net_device flags, the status identifier of the network device .

UP indicates that the network card is in the activated state;

BROADCAST indicates that this network card has a broadcast address and can send broadcast packets;

MULTICAST indicates that the network card can send multicast packets;

LOWER_UP indicates that L1 is activated, that is, the network cable is plugged in.

What does MTU1500 mean? What level of concept is it? The maximum transmission unit MTU is 1500, which is the default for Ethernet.


MTU is the concept of Layer 2 MAC layer. The MAC layer has a MAC header, and the Ethernet stipulates that the total length of the MAC header and the text is not allowed to exceed 1500 bytes. There are IP headers, TCP headers, and HTTP headers in the text. If it cannot fit, fragmentation is required for transmission.

qdisc pfifo_fast  

What does qdisc pfifo_fast mean? The full name of qdisc is queuing discipline, which is called queuing discipline in Chinese .

If the kernel needs to send data packets through a network interface , it needs to queue the data packets according to the qdisc (queuing discipline) configured for this interface.


The simplest qdisc is pfifo, which does not do any processing on the incoming data packets, and the data packets pass through the queue in a first-in-first-out manner. pfifo_fast is a bit more complicated, its queue consists of three bands . Within each band, the first-in-first-out rule is used.

The priorities of the three bands are also different. Band 0 has the highest priority and band 2 the lowest. If there are data packets in band 0, the system will not process the data packets in band 1, and the same is true between band 1 and band 2.


Data packets are assigned to three bands according to the Type of Service (TOS).
TOS is a field in the IP header, which represents whether the current packet is of high priority or low priority.

Summarize:

Through this section, I hope to remember the following knowledge points, which can be used later:

IP is an address and has a positioning function; MAC is an ID card and has no positioning function;
CIDR can be used to judge whether a person is a local;
IP is divided into public IP and private IP.
In the following chapters, I will talk about "going abroad", which is related to this. 

4. DHCP and PXE: How did IP come about, and how did it disappear?

If we need to communicate with other machines, we need a communication address, and we need to configure such an address for the network card.

How to configure the IP address?

You can configure an address yourself using the command line. You can use ifconfig or ip addr.

After setting, use these two commands to up the network card, and then you can start working.

Use net-tools:

$ sudo ifconfig eth1 10.0.0.1/24
$ sudo ifconfig eth1 up

Using iproute2:

$ sudo ip addr add 10.0.0.1/24 dev eth1
$ sudo ip link set up eth1

Do you have too much freedom to configure yourself? What if you configure an address that does not match anyone?

For example, the machines next to me are all 192.168.1.x, and I have to configure a 16.158.23.6, what will happen?

There will be no phenomenon, that is, the package cannot be sent out. Why can't it be sent out?


You see that it has its own source IP address 16.158.23.6 and destination IP address 192.168.1.6, but the packet cannot be sent out because the MAC layer has not been filled .

(This principle was mentioned in the previous section: as long as the packets running on the network are complete, there can be lower layers without upper layers, and it is absolutely impossible to have upper layers without lower layers. )

I know my own MAC address, but what to fill in the target MAC?

Linux will first judge, is the address to be in the same network segment as me, or is it in the same network segment as one of my network cards? Only in one network segment, it will send ARP request to obtain MAC address . What if it turns out not to be?

The default logic of Linux is that if this is a call across network segments, it will not directly send the packet to the network, but will try to send the packet to the gateway .

If you configure a gateway, Linux will obtain the MAC address of the gateway, and then send the package. For the machine 192.168.1.6, although the target IP of the packet passing through its door is it, but the MAC address is not its own, so its network card will not accept the packet.

What if no gateway is configured? The package couldn't be sent out at all.

What if the gateway is configured as 192.168.1.6? Impossible, Linux will not allow you to configure successfully, because the gateway must be on the same network segment as at least one network card of the current network, how could the gateway of 16.158.23.6 be 192.168.1.6?


Therefore, when you need to manually configure the network IP of a machine, be sure to ask your network administrator. If you are in the computer room, go to the network administrator to apply and ask him to assign you a correct IP address. Of course, when actually configuring, it must not be configured directly with commands, but placed in a configuration file. Different systems have different configuration file formats, but nothing more than CIDR, subnet mask, broadcast address, and gateway address.

Dynamic Host Configuration Protocol (DHCP):

After the IP is configured, it generally cannot be changed. To configure a client machine, the IP address must be configured every time it is used. What should I do?

We need an automatic configuration protocol , which is called Dynamic Host Configuration Protocol (Dynamic Host Configuration Protocol), referred to as DHCP .

Only need to configure a shared IP address. Each newly connected machine applies for this shared IP address through the DHCP protocol, and then configures it automatically.

so:

If it is a server in a data center, once the IP is configured, it will basically not change, which is equivalent to buying a house and decorating it yourself. The way of DHCP is equivalent to renting a house. You don't need to decorate, it's all configured for you. You can use it for a while, and then you can cancel the lease when you are done.

To resolve how DHCP works:

When a machine newly joins a network, it must be in a daze. It doesn't know what's going on, only its own MAC address. what to do? Shout out, I'm coming, anyone? Communication at this time basically relies on " roaring ". This step, we call DHCP Discover.

The newcomer sends a broadcast packet with IP address 0.0.0.0, with a destination IP address of 255.255.255.255. Broadcast packets encapsulate UDP, and UDP encapsulates BOOTP. In fact, DHCP is an enhanced version of BOOTP, but if you go to capture packets, the name you may see is still BOOTP protocol.

If a network administrator configures DHCP Server in the network, he is equivalent to the administrator of these IPs.
He knew immediately that a "newcomer" was coming. At this time, we can realize the unique importance of MAC address. When a machine joins a network with its own MAC address, MAC is its unique identity . If this is repeated, there is no way to configure it.

Only when the MAC is unique, the IP administrator can know that this is a newcomer and needs to lease an IP address to it. This process is called DHCP Offer. At the same time, the DHCP Server reserves the IP address provided for this client, so that this IP address will not be allocated to other DHCP clients.

 The DHCP Server still uses the broadcast address as the destination address, because at this time, the newcomer who requests to assign an IP does not have his own IP yet. The DHCP Server replied, I have allocated an available IP to you, how do you see it? In addition, the server also sends information such as subnet mask, gateway, and IP address lease period.

The new machine is happy, its "roar" is answered, and someone is willing to lease it an IP address, which means it can gain a foothold on the network. Of course, what is even more pleasing is that if there are multiple DHCP Servers, this new machine will receive multiple IP addresses, which is simply flattering.

It will choose one of the DHCP Offers , usually the one that arrives first, and will send a DHCP Request broadcast packet to the network, which contains the MAC address of the client, the IP address in the accepted lease, and the DHCP that provided this
lease Server address
, etc., and tell all DHCP Servers which server will accept the IP address
, tell other DHCP servers, thank you for your acceptance, and request to revoke the IP addresses they provide , so as to provide them
to the next IP lease requester .

At this time, because the final confirmation from the DHCP Server has not been obtained, the client still broadcasts using 0.0.0.0 as the source IP address and 255.255.255.255 as the destination address. In BOOTP, accept the IP assigned by a certain DHCP Server.

When the DHCP server receives the client's DHCP request, it will broadcast and return a DHCP ACK message packet to the client, indicating that the client's choice has been accepted, and put the legal lease information and other configuration information of this IP address into the The broadcast packet is sent to the client to welcome it to join the network family.

 When the final lease agreement is reached, it still needs to be broadcast to let everyone know.

Reclaiming and Renewing IP Addresses

Since it is renting a house, there is a lease term. When the lease expires, the administrator will take back the IP.

If you don't use it, take it back and take it back.

If you want to renew the lease, you can't renew the lease when the time comes, but you have to tell the landlord some time in advance. The same goes for DHCP.

When 50% of the lease period expires, the client will directly send a DHCP request message package to the DHCP Server that provided the IP address for it. After receiving the DHCP ACK message package responded by the server, the client will update its configuration according to the new lease period and other updated TCP/IP parameters provided in the package. In this way, the IP lease renewal is completed.

The network administrator can not only automatically assign IP addresses, but also automatically install the operating system for you!

Preboot Execution Environment (PXE)

First, boot the BIOS. This is a very small system that can only do one very small thing. In fact, it is to read the MBR boot sector of the hard disk and start GRUB; then give the power to GRUB, GRUB loads the kernel, loads the initramfs file as the root file system; then gives the power to the kernel; finally the kernel starts and initializes the entire operation system.


Then the process of installing the operating system can only be inserted after the BIOS is started. Because there is no boot sector before the system is installed. Therefore, this process is called Pre-boot Execution Environment, or PXE for short .

The PXE protocol is divided into client and server. Since there is no operating system, the client can only be placed in the BIOS first. When the computer starts, the BIOS transfers the PXE client into the memory, and then it can connect to the server to do some operations.

 Analyze the working process of PXE

First, start the PXE client. The first step is to tell the DHCP Server through the DHCP protocol that I have just arrived, poor and white, and have nothing. The DHCP Server leases it an IP address, and at the same time gives it the address of the PXE server and the startup file pxelinux.0.


Second, after the PXE client knows to go to the PXE server to download this file, it can initialize the machine. So the download started, and the TFTP protocol was used when downloading. Therefore, a TFTP server is often required on the PXE server. The PXE client requests the TFTP server to download the file, and the TFTP server says yes, so it passes the file to it.


Then, after the PXE client receives the file, it starts executing the file. This file instructs the PXE client to request the computer's configuration information pxelinux.cfg from the TFTP server. The TFTP server will give the PXE client a configuration file, which will say where the kernel is and where the initramfs is. PXE clients request these files.


Finally, boot the Linux kernel. Once the operating system is started, everything will be easy to handle in the future. 

 

Summarize:

The DHCP protocol is mainly used to rent IP addresses for customers, which is very similar to real estate agencies. To negotiate, sign contracts, and renew leases, the broadcast cannot "grab orders"; the DHCP protocol can recommend "
decoration team" PXE to customers, and can install operating systems , which is very useful in the field of cloud computing.

Guess you like

Origin blog.csdn.net/qq_50497708/article/details/128247038