I. Internet Protocol
Connecting two computers to the Internet is actually a set of uniform standards, which are called Internet protocols, and the essence of the Internet is a series of network protocols.
Second, why should have Internet Protocol
Internet Protocol is the equivalent of English in the computer world. Its features: a standard that defines how computers connect to the Internet, and computers that connect to the Internet.
Third, TCP/IP five layer model
The Internet Protocol is divided into OSI seven layer or TCP/IP five layer or TCP/IP four layer according to function, here only five layer model is discussed.
The user perceives the topmost application layer, the lower the closer the hardware, and each layer has its own specific protocol to run.
Physical layer: Transmits the Signal Data Link layer: Defines the grouping method of the electrical signal, ETHERNET,MAC, the broadcasting work way
- Ethernet Protocol Ethernet Provisions:
- A set of electrical signals constitutes a packet called ' frame '
- Each data frame is divided into: header head and Data two sections
Head contains: (fixed 18 bytes)
- Sender/Source Address, 6 bytes
- Recipient/Destination Address, 6 bytes
- Data type, 6 bytes
Data contains: (minimum 46 bytes, maximum 1500 bytes)
Head length +data length = Shortest 64 bytes, up to 1518 bytes, over maximum limit on shard send
- MAC Address: Ethernet Specifies that devices that are connected to the Internet must have a network card, and the address of the sending and receiving ends refers to the address of the network card, which is the MAC address.
Each NIC is fired from the factory. The world's only MAC address, 48-bit 2-digit length, usually represented by 12-bit 16 decimal digits (the first six bits are the vendor number, and the last six bits are the pipeline number)
- Broadcast: With a MAC address, two hosts within the same network can communicate (one host obtains the MAC address of another host via the ARP protocol)
Ethernet uses the most primitive way, the broadcast way carries on the communication, namely the computer communication basic roar
Network layer: IP, identify a subnet in the same network region of the computer communication by radio, otherwise, by way of routing, at this time we encounter the problem is how to distinguish which computers belong to the same broadcast domain, that is, the network layer function: Introduce a new set of addresses to distinguish between different broadcast domain/subnet, this address is the network address
The simple IP address segment only identifies the type of IP address, and it is not possible to identify the subnet in which an IP is located from either the network part or the host part
- Subnet Mask: A parameter that represents a sub-network feature. Formally equivalent to an IP address, is also a 32-bit binary number, its network portion is all 1, the host part is all 0.
The two IP addresses and the subnet mask are respectively performed with and operations (two digits are 1, the result of the operation is 1, otherwise 0), and then the results are the same, if so, it indicates that they are in the same sub-network, otherwise it is not.
- IP packet: Divided into head and data section, no need to define a separate field for the IP packet, directly into the data portion of the Ethernet packet
The "data" portion of the Ethernet packet, which is only 1500 bytes long. If the IP packet exceeds 1500 bytes, it needs to be split into several Ethernet packets, which are sent by the sub-development.
- ARP protocol: When a computer is contracted, it is easy to get its own Mac and how to get the target host's Mac, it needs to pass the ARP protocol.
ARP protocol feature: Send packets in a broadcast way, get the MAC address of the destination host
How the protocol works: Each host IP is known. For example: Host 172.16.10.10/24 access 172.16.10.11/24. First, through the IP address and subnet mask to distinguish their own subnet, analysis 172.16.10.10/24 and 172.16.10.11/24 is in the same network, is the same network, through ARP to obtain the target host Mac, target host IP; if it is not the same network, Then the ARP gets the gateway Mac, the target host IP. This package will be broadcast in the sending side of the network in the transmission, all hosts received after unpacking, found that the target IP for their own, on the response, back to their Mac.
all upper-layer packages are then encapsulated on the Ethernet header and then sent over the Ethernet protocol
Transport Layer: tcp/udp== "Port-based protocol, a unique application that identifies a single machine
- Transport Layer Capabilities: Establish Port-to-port communication
Port range 0-65535,0-1023 for system-occupied ports
TCP protocol: Reliable Transmission
UDP protocol: Unreliable transmission
- TCP three-time handshake and four waves: Connect three times, disconnect four times
Application layer: HTTP, user-defined protocol
- Application Layer functionality: Specifies the data format of the application.
Sending data is an encapsulated process, and receiving data is the solution encapsulation.
Iv. user access Flow 1. Native access
- IP address of this machine: 192.168.1.100
- Subnet Mask: 255.255.255.0
- IP address of the gateway: 192.168.1.1
- IP address of DNS: 8.8.8.8
2. Open the browser and want to access Google, in the address bar entered the URL: www.google.com. 3.dns protocol (based on UDP protocol)
Contents of the 4.HTTP section
We assume that the length of this part is 4960 bytes and it will be embedded in the TCP packet.
5 TCP protocol
- The TCP packet needs to set the port, the receiver (Google) HTTP port is 80 by default, and the sender (native) port is a randomly generated integer between 1024-65535, assuming 51775.
- The header length of the TCP packet is 20 bytes, plus the packet embedded in HTTP, the total length becomes 4980 bytes.
6 IP protocol
- Then, the TCP packet is then embedded in the IP packet. IP packets need to be set up on both sides of the IP address, which is known, the sender is 192.168.1.100 (native) and the receiver is 172.194.72.105 (Google).
- The header length of the IP packet is 20 bytes, plus the embedded TCP packet, the total length becomes 5000 bytes.
7 Ethernet Protocol
- Finally, the IP packet is embedded in the Ethernet packet. Ethernet packet needs to set the MAC address of both sides, the sender is the local network card MAC address, the receiver is the gateway 192.168.1.1 MAC address (through the ARP protocol).
- The data portion of the Ethernet packet, the maximum length is 1500 bytes, and now the IP packet length is 5000 bytes. Therefore, IP packets must be split into four packets. Because each package has its own IP header (20 bytes), the length of the IP packets for the four packets is 1500, 1500, 1500, 560, respectively.
8 Server-side response
- After the forwarding of multiple gateways, Google's server 172.194.72.105, received the four Ethernet packets.
- According to the IP header number, Google put four packages together, take out the full TCP packet, and then read the inside of the "HTTP request", and then make "HTTP response", and then sent back with the TCP protocol.
- After the native HTTP response is received, the Web page can be displayed to complete a network communication.
V. Other
- The IP address of the IP layer can uniquely identify the host, and the TCP layer protocol and port number can uniquely identify a process for the host, so we can use the IP address + protocol + port number to uniquely identify a process in the network.
- The DHCP:DHCP (Dynamic Host configuration Protocol, dynamically configured protocol) is a LAN protocol that uses UDP to work with two main purposes: assigning an IP address to an internal network or network service provider automatically, For users or internal network administrators as a means of central management of all computers. DHCP has 3 ports, where UDP67 and UDP68 are normal DHCP service ports, respectively, as DHCP server and DHCP client service ports, and a port number No. 546.
- Dns:dns (domain Name System), a distributed database that maps domain names and IP addresses on the Internet, makes it easier for users to access the Internet without remembering the number of IP strings that can be read directly by the machine. The process of obtaining the IP address of the host name through the hostname is called Domain name resolution (or hostname resolution). The DNS protocol runs on top of the UDP protocol, using the port number 53. There are two ways of recursive and iterative querying.
- Domain name definition: Host level two domain name top level domain root domain
Python Learning day3--Network-based network protocol chapter