[Computer network] TCP / IP

First, the basic concept

TCP / IP (Transmission Control Protocol / Internet Protocol, Transmission Control Protocol / Internet Protocol) refers to the protocol suite enables transmission of information between multiple different networks. TCP / IP protocol refers not only TCP  and IP two protocols, but a means of the FTP , the SMTP , TCP, the UDP protocol cluster configuration, IP and other protocols, just as the TCP / IP protocol in the TCP and IP protocol the most representative, it is called TCP / IP protocol.

Second, the composition

TCP / IP protocol to a certain extent, reference is made to OSI architecture. A total of seven layers of the OSI model, from bottom to top is the physical layer, data link layer, network layer, transport layer, session layer, presentation layer and application layer. But this is obviously a bit complicated, so in the TCP / IP protocol, which is simplified to four levels.
(1) an application layer, presentation layer, session layer three service levels provided by the difference is not great, so that the TCP / IP protocol, which are combined into one level application layer;
(2) Since the position in the network layer and the transport layer network protocol is very important, so that the TCP / IP protocol as they are two separate levels;
(3) Since the contents of the data link layer and the physical layer are very similar, so the TCP / IP protocol which are merged in the network interface layer.
Only TCP four architecture / IP protocol, the OSI seven-layer architecture has compared to a lot of simple, it is this, TCP / IP protocol in practical applications higher efficiency and lower cost.

1, the application layer

The application layer is the highest level of open systems is to provide services directly to the application process. Its role is to communicate with each other while multiple systems application process, the processing required to complete a series of business services.

It is used to receive data from the transport layer or a different application requirements and methods to transmit data to the transport layer. The main protocols are HTTP , the DNS , the FTP , the SMTP , POP , the Telnet

1.1 DNS

DNS (Domain Name System domain name system) function is to domain names into corresponding IP addresses.

It acts as a distributed database of domain names and IP addresses will be mapped each other, it can make it easier to access the Internet. DNS uses TCP and UDP port 53.

Currently, for every level domain name length limit is 63 characters, the total length of the domain name can not be more than 253 characters.

DNS queries in two ways: recursive and iterative. DNS client settings to use DNS servers are generally recursive server, which is responsible solely DNS query request processing client until you return to the final result. The general iterative query between DNS servers.

To check www.baidu.com an example:
the client sends a query message "query www.baidu.com" to the DNS server, the DNS server first checks its own cache, if there is recorded directly return results.
If the record aging or does not exist:

  1. DNS server sends a query to the root domain name server message "query www.baidu.com", the root name server returns the .com top-level domain name server address.
  2. DNS server sends a .com domain name server queries from the DNS server addresses "query www.baidu.com", get second-level domain .baidu.com of.
  3. DNS server sends queries the domain name server .baidu.com message "query www.baidu.com", www host is recorded, and stored in its own cache and returned to the client.

1.2 FTP

 FTP (File Transfer Protocol File Transfer Protocol) is a standard protocol for file transfers over the network, working in the seventh layer of the OSI model, Layer 4 TCP model, namely the application layer, using TCP transport, clients and servers before establishing a connection to go through a "three-way handshake" process to ensure that the connection between client and server is reliable and connection-oriented, to provide a reliable guarantee for the data transmission. FTP file allows the user to operate in a manner (e.g., additions and deletions to change search file transfer, etc.) to communicate with each another host.

It is used in communications between two hosts of the two TCP connections, one for data transfer and a control connection for transmitting control information (commands and responses), which commands and data transmitted separately thought greatly improved FTP efficiency, and other client-server applications generally only a TCP connection.

Customers are three members: a user interface, the client process and the customer data transmission control processes. Server has two components: a server control process and server data transfer process. In the entire interactive FTP session, the control connection is always in the connected state, the data connection is closed after each opening the first file transfer.

2, the transport layer

The transport layer is responsible for providing services to communication between two processes in the host. Since a host running multiple processes, thus having a transport layer has functions of multiplexing and demultiplexing. Transport layer on a given link through flow control, segmentation / reassembly and error control to ensure the reliability of data transmission. Some transport layer protocol is a link-oriented, which means that the transport layer can keep track of the segments and retransmit those segments of failure. The network layer can establish and terminate network connections and find the IP address and other functions, there are major protocol TCP, UDP.

2.1TCP

UDP protocol defines a port, the same application on each host to specify a unique port number, and a predetermined data packet transmission network port information must be added, When the packet arrives at the host, can be found according to the port number corresponding application. UDP protocol is relatively simple and easy to implement, but it did not confirm the mechanism, packet once issued, can not know if it was received, and therefore less reliable, in order to solve this problem, improve network reliability, TCP protocol was born.

2.2 UDP

TCP Transmission Control Protocol, a connection-oriented, reliable byte stream protocol based communication. In simple terms is to have the UDP protocol TCP acknowledgment mechanism, each sends a data packet asked to confirm, if a packet is lost, it can not receive confirmation, the sender must retransmit the packet. In order to ensure the reliability of transmission, TCP protocol to establish a mechanism to confirm the three dialogues in UDP basis, that is, before the official send and receive data, you must create a reliable connection and each other. TCP and UDP packets, are composed of a header and a data portion composed of two parts, the only difference is, the length of the TCP packet is not limited, and can be theoretically infinite, but in order to ensure the efficiency of the network, typically the length of the TCP packet is not over IP packet length, to ensure a single TCP packet does not have to re-segmentation.

 3, the network layer

Network layer packet routing and forwarding. Communication two hosts are generally not directly connected, but by a plurality of intermediate nodes (routers) connected. Tasks The network layer is to select these intermediate nodes, in order to determine a communication path between two hosts. Meanwhile, the upper protocol of the network layer hides the details of the connection of the network topology, such that the transport layer and network applications opinion, both sides are directly connected in communication. The main protocols are IP , ARP , RARP , ICMP

 3.1 IP

 IP (Internet Protocol Internet Protocol), responsible for Internet communications between the network and provides for the transmission of data packets from one network to another network rules to be followed. IP protocol only defines the basic unit and a data transmission format, also defines a method and submitted datagram routing. Further, the TCP / IP network, the address necessary for communication between hosts, is achieved through the IP protocol.

 3.2 ARP

ARP (Address Resolution Protocol ARP), acquires a physical address of the TCP / IP protocol based on IP address. ARP containing the target host IP address when sending an information request is broadcast to all hosts on the local area network, and receiving the return message, in order to determine the physical address of the target; the return message after receiving the IP address and physical address is stored in the machine ARP cache and retain a certain time, to directly query the ARP cache when the next request to conserve resources.

working principle:

A host IP address is 192.168.1.1, MAC addresses 0A-11-22-33-44-01;
IP address of the host B is 192.168.1.2, MAC addresses 0A-11-22-33-44-02;
When the host A to host B communicate with, ARP may be the IP address of host B (192.168.1.2) resolves the MAC address of host B, the following workflow:
  1. The routing table of contents on the host A, IP forwarding IP address is used to determine access to the host B is 192.168.1.2. Host A then checks for a matching MAC address of host B in their own local ARP cache;
  2. If the host A mapping is not found in the ARP cache, it will ask the hardware address of 192.168.1.2 to broadcast an ARP request frame to all hosts on the local network. IP address and MAC address of the source host A are included in the ARP request. Each host on the local network receives the ARP request and checks whether the IP address matches its own. If the host IP address discovery request does not match the own IP address, it discards the ARP request;
  3. Host B determines that the IP address in the ARP request with its own IP address match, the host A's IP address and MAC address mapped to the local ARP cache;
  4. Host B will contain the MAC address of an ARP reply message is sent directly back to the host A;
  5. When the host A receives B sent from the host ARP reply message, it will update the ARP cache mapping with the MAC address and IP host B. This local cache is survival, survival after the end of the period, repeat the process again. Once the MAC address of host B is determined, Host A can send a communication to the IP host B.

 3.3 ICMP

ICMP (Internet Control Message Protocol Internet Control Message Protocol) for transferring control messages between IP hosts, routers. Refers to the network control messages through the operation fails, the host is reachable, a message such as whether the available route network itself. These control messages, while not transmitting user data, but for the transfer of user data plays an important role.

ICMP uses the basic support of IP as if it were a higher level protocol, however, ICMP is actually an integral part of IP, and must be implemented by every IP module.

From a technical point of view, ICMP is a "error detection and reward system", its purpose is to allow us to detect the network connection status, but also to ensure the accuracy of connection. Accidental router processing a data packet in the process may report the event to the source as ICMP packets through.
Its functions are: to detect the existence of the remote host, build and maintain routing information, redirect data transmission path (ICMP redirect), data flow control, ICMP in communication, mainly through different Type and Code allows machine condition to identify different connections.
TYPE CODE Description Query Error
0 0 Echo Reply-- echo reply (Ping reply) x  
3 0 Network Unreachable-- network unreachable   x
3 1 Host Unreachable-- host unreachable   x
3 2 Protocol Unreachable-- protocol unreachable   x
3 3 Port Unreachable-- Port Unreachable   x
3 4 Fragmentation needed but no frag. Bit set-- fragmentation needed but do not fragment bits set   x
3 5 Source routing failed-- source routing failure   x
3 6 Destination network unknown-- destination network unknown   x
3 7 Destination host unknown-- destination host unknown   x
3 8 Source host isolated (obsolete) - source host isolated (obsolete without)   x
3 9 Destination network administratively prohibited-- purpose of the network is forced to ban   x
3 10 Destination host administratively prohibited-- destination host is forced to ban   x
3 11 Network unreachable for TOS-- due to the type of service TOS, network unreachable   x
3 12 Host unreachable for TOS-- due to the type of service TOS, host unreachable   x
3 13 Communication administratively prohibited by filtering-- since the filter, a communication is forcibly prohibited   x
3 14 Host precedence violation-- host of ultra vires   x
3 15 Precedence cutoff in effect-- priority to suspend the entry into force   x
4 0 Source quench-- source is turned off (elementary stream control)    
5 0 Redirect for network-- of the network redirector    
5 1 Redirect for host-- host redirect    
5 2 Redirect for TOS and network-- type of service and network redirector    
5 3 Redirect for TOS and host-- type of service and host redirection    
8 0 Echo request-- echo request (Ping requests) x  
9 0 Router advertisement-- router advertisement    
10 0 Route solicitation-- router request    
11 0 Survival during TTL equals 0 during transit-- transmission time is 0   x
11 1 TTL equals 0 during reassembly-- during the lifetime of the datagram assembly 0   x
12 0 IP header bad (catchall error) - Bad IP header (including a variety of error)   x
12 1 Required options missing-- missing required options   x
13 0 Timestamp request (obsolete) - timestamp request (not obsolete) x  
14   Timestamp reply (obsolete) - timestamp reply (void without) x  
15 0 Information request (obsolete) - Information request (not void) x  
16 0 Information reply (obsolete) - Information reply (void without) x  
17 0 Address mask request——地址掩码请求 x  
18 0 Address mask reply——地址掩码应答    

 4、网络接口层

网络接口层是数据包从一个设备的网络层传输到另外一个设备的网络层的方法。这个过程能够在网卡的软件驱动程序中控制,也可以在韧体或者专用芯片中控制。这将完成如添加报头准备发送、通过物理媒介实际发送这样一些数据链路功能。另一端,链路层将完成数据帧接收、去除报头并且将接收到的包传到网络层。

Guess you like

Origin www.cnblogs.com/6970-9192/p/11545547.html
Recommended