Understanding of basic knowledge related to network communication (an article to understand network related content)

TCP/IP protocol : It is an agreed way of data communication between computers in the network, otherwise who knows that you are going to send it to me.


Port : An application will occupy a port in the system to access the network card. The port number is limited (65535), some of which have been used by fixed functions, and a port number can only be assigned to one application.


socket : It is a network communication API that encapsulates TCP/IP. The socket is the only determination of the source IP+end product and the destination IP+port, so the system can have many sockets (different from the port number).


The router also has its own IP (the first reserved in the intranet as its IP), and MAC address.


NAT workflow (Network Address Translation)
The function of NAT is to change the internal network IP + port to the external network IP + port (this person's port number is also to be applied for to distinguish different hosts),
NAT will create a The mapping table of the internal network IP+port and the external network IP+port makes the data returned by the later server prepared for that internal
host .

1. The host applies for access to the external network server with the internal network IP + port number, and the data packet is sent to the NAT (router).
2. The NAT resolution is sent to the external network, apply for a port number from NAT, and create a mapping table entry between the internal network IP+port and the external network IP+port.
And change the source IP and port number in the data packet to the external network IP + port, and then form a new data packet and send it to the server to be accessed by the external network.
3. The server gets the request and packages the data back to NAT.
4. NAT receives the data packet, parses and compares the contents in the mapping table of the intranet IP+port and the extranet IP+port, and then changes the extranet IP+port to
Intranet IP + port, and then send it to the original requesting machine, so that the original requesting machine will receive the data accessing the external network.

Refer to the original text: http://blog.sina.com.cn/s/blog_9d386e13010175rq.html


Ethernet frame format













Target address: 6 bytes, unicast, multicast or broadcast. Unicast addresses are also called personal, physical, hardware, or MAC addresses. The broadcast address is all 1, 0xFF FF FF FF.


MAC address table, the relationship table between the MAC address and the interface saved by the router.
ARP cache table, IP, MAC relationship table saved by the computer.
Routing table: The relationship table between network segments and interfaces saved by the router.



ARP protocol workflow
The IP address of host A is 192.168.1.1 and the MAC address is 0A-11-22-33-44-01;
the IP address of host B is 192.168.1.2 and the MAC address is 0A-11-22-33 -44-02; Workflow for

host A to communicate with host B:
1. Host A checks the matching MAC address (IP, MAC relationship) of host B in its own local ARP cache.
2. Host A checks the matching MAC address of host B in its own local ARP cache, thereby broadcasting the ARP request frame to all hosts on the local network,
the IP address and MAC address of source host A + destination IP and destination MAC (yes) 12 F) (this is the content of the broadcast packet), each host on the local network
receives the ARP request and checks whether it matches its own IP address. If the host finds that the requested IP address does not match its own IP address, it
will drop the ARP request.
3. Host B determines that the IP address in the ARP request matches its own IP address, and then adds the IP address and MAC address mapping of host A to the local ARP cache.
4. Host B sends an ARP reply message containing its MAC address directly back to Host A. (Because of the target IP and target MAC, it can be sent directly)
5. When host A receives the ARP reply message sent from host B, it will update the ARP cache with the IP and MAC address mapping of host B. The local cache has a lifetime
. After the lifetime expires, the above process will be repeated again. Once the MAC address of host B is determined, host A can send IP traffic to host B.

When the network card receives the data packet, if the MAC address is not given to itself or lost, so the ARP request is no longer obtained in the form of broadcast when crossing the network,
but sent to the target in the form of a datagram by the router, and the target returns after ARP request responses are processed.

When crossing the network
1. If it is found that it is not in the same network segment, encapsulate it into an ARP request packet and send it to the router (if you don't know the router's MAC, make an ARP request to get it, they are in the same network segment, and
you can broadcast the MAC).
2. When the router receives the packet, check whether it is its own IP. If not, check the routing table for data forwarding (if you don't know the router's MAC, you can get it by ARP request. They are in the same network segment and
can broadcast the MAC). If there is no relationship between the network segment and the interface in the routing table, it will be sent from the default interface car.
3. Until finally a router finds that the IP is its own network segment IP, it sends this data packet to it (if you don't know the target MAC, make an ARP request to get it, they are in the same network segment,
you can broadcast the MAC).
4. After the target receives the ARP data packet, it sends the ARP request response to the source, so that the source can obtain the IP and MAC of the target and store it in the local ARP cache of the source.
5. In the future, both parties can send data packets directly, no need to make ARP requests.

Refer to the original text: http://www.xpc8.com/wd/xpc8044856.html


Router : The function of routing is to determine the function of sending data packets to which router or server according to the destination IP.
The router determines the IP of the next station through the routing table, until it reaches the target machine. The forwarding process is also the generation process of the router's routing table (saved locally to the router to facilitate the next lookup). The port is forwarded out.
During the forwarding process, the router will parse the forwarding IP address in the data packet, but the source and destination IP and port numbers in the data packet are unchanged, but the MAC address of the Ethernet data frame during the forwarding process changes, because The data communication at the bottom layer of the network (the data communication between machines is carried out by the MAC address) is uniquely determined by the MAC address.


DHCP
DHCP (Dynamic Host Configuration Protocol, Dynamic Host Configuration Protocol) is a network protocol of a local area network, used for dynamic allocation of IP addresses.

DHCP Client: DHCP client, a client that requests an IP address through the DHCP protocol.
DHCP Server: The DHCP server is responsible for providing IP addresses to DHCP clients and managing the assigned IP addresses.

DHCP working principle:
1. Discovery phase: the client sends DHCP Discovery, because the DHCP Server corresponding to the DHCP client is unknown, so the DHCP Discovery packet
sent is a broadcast packet, the source address is 0.0.0.0 The destination address is 255.255.255.255. All support on the web
All TCP/IP hosts will receive the DHCP Discovery message, but only the DHCP server will respond to the message.
If there are multiple DHCP Servers on the network, multiple DHCP Servers will reply to the DHCP Discovery message.

2. DHCP Server providing stage: After the DHCP Server receives the DHCP Discovery message, it parses the Subnet to which the IP address requested by the message belongs.
And take out an available IP address from the matching subnet in the dhcpd.conf file, after selecting an IP address from the available address segment, first
send ICMP message to ping the IP address, if the ICMP of the IP address is received message, then discard the IP address, re-select the IP address to continue the
ICMP message test, until an IP address that is not used in the network is found, in order to prevent the dynamically allocated IP address from
conflicting with the IP addresses of other devices in the network. This IP address conflict detection mechanism is configurable), set in the yiaddress field in the DHCP Discovery message, indicating the IP address assigned to the
client , and set the Option of the Subnet configuration for the Lease, such as the default leases lease period, the maximum Lease, router
and other information.

3. DHCP Client selection stage: After the DHCP Client receives the DHCP Offer messages responded by several DHCP Servers, it selects one of the
DHCP Servers as the target DHCP Server. The selection strategy is usually to select the DHCP Server to which the first responded DHCP Offer packet belongs.

Then reply a DHCP Request message in broadcast mode, the message contains information such as the IP address requested from the target DHCP. The reason is wide
The purpose is to notify other DHCP Servers that they will select the IP address provided by the DHCP Server.

4. DHCP Server confirmation stage: When the DHCP Server receives the DHCP Request sent by the DHCP Client, and confirms
the IP address to be provided for the DHCP Client, it responds to the DHCP Client with a message containing the IP address and other Options. to tell the DHCP Client that the IP address can
be used. Then the DHCP Client can bind the IP address to the network card. In addition, other DHCP Servers will take back the IP addresses they
previously provided to DHCP Clients.

5. DHCP Client re-login to the network: When the DHCP Client re-logs in, it sends a DHCP Request message containing the IP address
information DHCP Server. When the DHCP Server receives the request, it will try to let the DHCP client continue to use it. the IP address. And reply
with an ACK message.

However, if the IP address cannot be reassigned to the DHCP Client, DHCP replies with a NAK packet. When the DHCP Client receives the NAK
packet , it will resend the DHCP Discovery packet to obtain the IP address again.

6. The DHCP Client renews the lease: The IP address obtained by DHCP has a lease. After the lease expires, the DHCP Server will reclaim the IP address,
so if the DHCP Client wants to continue to use the IP address, it must renew the lease. The renewal method is that when half
of , the DHCP client will send a DHCP Renew message to renew the lease term.

Reference text: http://network.51cto.com/art/201406/441752.htm




Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327069033&siteId=291194637