Network communication process (TCP communication) two hosts

Communication two hosts have two cases: one in the same segment in different network segments 2

(1) on the same subnet communication process

Host operating at the application layer:

  tcp on the TCP / IP protocol port corresponding to the various applications, the client wants to access an application will be asked to open the fixed port on the host. And the client that they will open a random port greater than 1024 is used to communicate with other hosts. User information editing application, a single session is actually a logical software between a host application layer connection.

Host transport layer Operation:

  Data segment (Segment), add the TCP header (including source port, destination port, sequence number, the acknowledge sequence number, etc.)

Segmented reasons:

(A): a plurality of applications can simultaneously transmit data.

(B): When a packet is too large an error, need to re-transmit, with fast and accounted cent of the time, small packets of data flow on effect on many small.

(C): which has a variety of network transmission media maximum transmission unit limit, a huge packet on the network is not allowed.

Hosts at the network layer operations:

  When the transport layer is a TCP header is added to data segments, the network layer delivers the processed data. The network layer IP header is added to the transport layer packet transmitted (including source IP address, destination IP address) encapsulated into packets

The number of host link layer operations:

  The data link layer in front of the encapsulated data packet header, the packet is encapsulated behind the parity bit, so the data packets encapsulated into frames. (Adding the source MAC address and destination MAC address, if the host does not want to know the destination MAC address switch sends ARP broadcast to obtain the destination MAC address)

 

Physical layer of host operating:

Sent over a logical link layer from the data frame into electronic signals can be transmitted on a physical line, it is passed to switch on the network forwarding device, processed by the switch.

 Switch processing of the data frame:

After the data stream is received the switch looks up the destination host according to the data frame sent from the MAC address, sends the data to the destination host. Forwarding process does not change the data frame structure.

 Destination host receives the operation data frame:

When comparing the destination MAC destination host receives the data frame, the case to their own transmission, then remove the header data, sent to the network layer, the IP network layer comparative purposes, the same as the hair unpacking transport layer, a transport layer, and then to compare destination port, the same data segment is confirmed that the application data to remove the assembly.

 

(2) located in different communication process between two hosts on the network

Work on the host A:

Since the host A and the host B is not in the same network segment, it is impossible to resolve the host A to host B through ARP MAC address, while A is also a master network node without routing capability, it is not possible to rely on their host A the power to send data to the host B up. A host must rely on the network router to route packets to the appropriate destination network.

  A host network configuration: configure your own IP subnet mask and gateway configuration simultaneously (Who hosts may provide access to other networks, the default gateway IP address who will fill 'router, proxy server'.)

  [DNS: DNS name resolution provides the destination address, as different network LAN, the DNS server may be filled within this LAN. If the external network access INTERNET domain name, then fill in the ISP's DNS server. ]

After filling in the default gateway, host A via ARP, you can know the MAC address of the router A's. When Host A to Host B sends a file, it may send packets through the router to the destination A.

Example: Host A sends data to the host process B other network segments.

1. A host transport layer to the application layer data is segmented, marked TCP header (including source port, destination port), and then sent down the network layer, marked with the IP address (including source IP, destination IP), and then sent down to the data link layer, the data frame marked with (including source MAC, MAC object), without knowing the purpose of MAC, the MAC address is marked in the gateway (router interface) in the MAC, sent to router A.

 2. After router A receives the message, re-encapsulates the frame data (that need to be sent to the host through a router B B), then modify the source MAC address as MAC address, the destination address is the MAC address of router A is B, (A router for NAT address translation)

 3. A router B receives information routers, the address check, the IP check, modify MAC, MAC source router B to the MAC, (if the host B subnet router B's) to fill the destination MAC MAC host B, i.e., the next step will send a message to host B.

4. After the host B receives the data frame to the data split, packets, TCP header, checks the destination address and check, re-integration of the data stream, this data stream to the application layer.

to sum up:

For lan in the same switch, the communication, needs to know the address of the destination and mac ip, by broadcasting packets occurs (typically 2 mac layer address of the target FFFFFFFF, 3 layers on certain target ip ip), as will be in the same All ip lan Compare to find the target after sending a single ip multicast packets to the source, so that you know the mac address of the destination ip, but if a segment or ip not the same lan, this time by arp broadcast, is not acceptable , a router needs to forward, which requires card configuration and ip source mask, gateway (router gateway needs to be configured to interface ip), the purpose of such a data packet on the mac become filled mac router interface, the occurrence of the packet to the router, the router then unpacking, checking layer 2 mac address, finding the target for their mac mac, tread, and then removed layer 3 checks ip, ip not find their target, and then holding the target network number and ip routing table entries are compared to find the optimal (the longest match principle), if not found discarded, and a return to the source icmp error, if found, repackaged (mac goal for the next Mac address corresponding hop ip), the occurrence of the next hop address data, when the data packet to, always unpacking, check whether the layer 2 for his mac address, and if yes, ip layer 3 header removed check whether the target ip, if it is, then split four layers, check whether the destination port number to listen or wait for the data, and if so, put the removed application data has its own port corresponding to the current process, if not found corresponding port, it will set the rst error

Note: 1 is bi-directional data communication, such as of ping, both data can occur and can receive data

   2. The router interface directly connected to the network, generated directly in the routing table, the other needs to be configured (such as Huawei general configuration is ip route-static source ip next hop address mask), it is necessary to configure the destination routing table ip routing, so that it could reach the destination, but also configure the back, is the source ip corresponding routing, so that it could return a response, this is a key to be able to ping

arp -a view the routing table

After reaching the target ip tracert to see how many routes, how many hops

 

Guess you like

Origin www.cnblogs.com/bwbfight/p/11131684.html