Linux basics-basic computer network knowledge (OSI/TCP, loopback network card, encapsulation and decapsulation process, common port protocols, etc.)

1 Basic knowledge of computer network

1.1 What is the relationship between the functions of each layer of the OSI seven-layer model and the tcp/ip four-layer model?

  • The relationship between the two protocols on the hierarchical structure is as follows
TCP/IP structure OSI seven-layer structure
Application layer Application layer, presentation layer, session layer
Computer to computer layer (TCP) (also known as transport layer) Transport layer
Network layer (IP) Network layer
Network interface layer (link layer) Data link layer, physical layer
  • The TCP/IP protocol suite includes many sub-protocols. The relationship between the sub-protocols and the OSI seven-layer protocol is as follows
OSI protocol layer names (top to top) Features TCP/IP protocol family
Application layer Communication between user program and program, used for file transfer, mail, file service, virtual terminal, etc. HTTP、SNMP、TFTP、FTP、DNS、Telnet、等
Presentation layer Decide the encoding, encryption, and compression of data; data includes various multimedia files; functions include: encryption and decryption algorithms, compression and decompression algorithms, and format conversion algorithms No child agreement
Session layer Establish, manage, and terminate sessions between users on different machines No child agreement
Transport layer Realize port-to-port communication. There are two transmission methods for data message transmission: reliable (TCP protocol) and unreliable (UDP protocol), suitable for different scenarios; there is a timeout retransmission mechanism and a flow control mechanism; TCP、UDP
Network layer Logical address addressing, data packets are forwarded, and it has a forwarding judgment mechanism (routing algorithm) for data packets; packet transmission of data packets; logical address addressing IP、ICMP、OSPF、IGMP、RIP等
data link layer Device physical addressing, error detection of data frames transmitted at this layer , and upward transformation of the original bit stream into a logical transmission line PPP 、 ARP 、 MTU 等
Physical layer Modulation and demodulation of the data bits transmitted in the channel means that this layer determines the communication medium and interface standard for transmission IEEE802.2 etc.

1.2 Common protocols and functions of TCP/IP protocol stack?

Layer protocol Features
Network interface layer ARP Used to find the physical address, only the physical address can be determined before the data frame can be forwarded
Network interface layer MTU Inform the communication partner of the maximum value of the data unit that can be received from the other party, except for the header and tail of the data frame, the data part is generally between 46-1500 bytes
Network layer RIP Based on the "distance-vector" algorithm. Self-consistent system internal gateway protocol for dynamic routing selection.
Network layer BGP Used to exchange routing information between different self-consistent systems, each self-consistent system must specify a node running BGP
Network layer OSPF The link state protocol based on the "open shortest path first" routing algorithm works in a self-consistent system and uses the flooding method to exchange routing information with neighboring nodes.
Network layer IP Core protocol, including: IP addressing scheme, IP packet fragmentation, packet encapsulation format and packet forwarding rules
Network layer ICMP Used to transfer control information between IP hosts and routers, including: network operability, host reachability (transmission packets), timeout, etc.
Transport layer TCP Core protocol, face-to-face, reliable protocol, with data verification, flow control, timeout retransmission, piggyback confirmation function
Transport layer UDP A method of sending encapsulated IP data packets without establishing a connection is unreliable. Characteristic is no connection
Application layer HTTP Hypertext transfer protocol, based on TCP connection. It specifies what kind of message the client may send to the server and what kind of response it gets. It is mainly used for web content acquisition
Application layer DNS Domain name system. Mainly used for the conversion between domain name and IP address, like a phone book
Application layer FTP Allow users to communicate with another host in file operations (such as file addition, deletion, modification, check, transmission, etc.); based on TCP protocol
Application layer SMTP Reliable and effective email transmission protocol, based on TCP protocol

1.3 Describe the TCP protocol state machine and the process of three-way handshake and four waves

  • First understand the content of TCP messages

在这里插入图片描述

  • The 32-bit confirmation sequence number is ACK, which is fatal to the next expected byte sequence number

  • 32-bit sequence number Seq: the sequence number of the first byte of the data group sent in this segment

  • Control bits (the last six bits of the 13th and 14th bytes of the message segment):

    1. ACK:确认序号标志。仅当ACK = 1 时确认号字段才有效,当ACK = 0时,确认号无效。TCP规定,在连接建立之后所有的传送的报文段都必须把ACK置为1。

    2. SYN:连接建立时用来同步序号。当SYN = 1时而ACK = 1时表示这是一个连接请求报文段。对方若同意连接,则应在响应的报文段中是SYN = 1 和ACK = 1,因此SYN = 1就表示这是以恶搞连接请求或连接接受报文;

    3. 用来释放一个连接,当FIN = 1时,表示次报文段的发送方的数据已经发送完毕,并要求释放运输连接;

    TCP三次握手分析如下:

在这里插入图片描述

第一次握手:客户端(Client)向服务器端(Server)发送第一个包,其中标志位:SYN=1、ACK=0,发送序号Seq=x。客户端进入:SYN发送状态,等待服务器确认;

第二次握手:服务器收到客户端发送的包,后发送第二个包,其中包的SYN=1、ACK=1,接收顺序号ack为x+1,发送序号Seq为y,服务器进入SYN接收状态;

第三次握手:客户端收到服务器端传过来的包后,向服务器发送最后一个包,其中标志位SYN=0、ACK=1,发送顺序号Seq为x+1,ack为y+1。此包发送完毕,客户端和服务器都进入ESTABLISHED即建立成功的状态。至此三次握手完成。

​ TCP四次挥手分析如下:

在这里插入图片描述

第一次挥手:主动方发送第一个包,FIN=1,发送顺序号seq=x;主动方进入FIN_WAIT 状态

第二次挥手:被动方收到主动方发送的包后发送第二个包标志位ACK=1,接收顺序号ack=x+1;被动方进入CLOSE_WAIT状态

第三次挥手:被动方再发送第三个包,其中FIN=1,发送顺序号seq=b,接收顺序号ack=x+1;被动房进入LAST_WAIT状态

第四次挥手:主动方接收到包后进入TIME_WAIT状态,主动方发送第四个包,ACK=1,其中发送顺序号seq=x+1。确认方收到后,进入CLOSED状态,至此,完成四次挥手;

1.4 回环网卡(Lookback Adaptor)功能?

定义:一种特殊的网络接口,不与任何实际设备连接,而是完全由软件实现,有了这个接口,就允许了运行在同一个主机上的客户程序和服务器程序通过TCP/IP进行通信。A类网络号127即为环回接口预留的。大多数系统会把ip地址为127.0.0.1分配给这一个接口,命名为localhost,ip数据包的传送不允许出现在网络上。

注意:

  • 传给环回地址(一般:127.0.0.1)的任何数据均作为IP输入(传回给本地网络层);
  • 根据广播/多播传送定义,传给广播/多播地址的数据报需要复制多一份传给环回接口,再继续传到以太网上
  • 任何传给本主机IP地址的数据均会送到环回接口

1.5 描述数据报封装解封装过程

  • 封装过程如下

在这里插入图片描述

  1. 应用层数据经过传输层封装头部形成TCP报文段或UDP数据报。

    TCP报文段头部最少20个字节,剩下有40字节的选项;而UDP报文段最少8个字节。

  2. 传输层的报文段当做网络层传输单位的数据部分,再加上一个IP头部组成IP数据报。报头固定长度为20字节,还有40字节可选部分。

  3. 网络层的IP数据报作文数据链路层传输单位的数据部分(可能有分片),数据部分的头部有14个字节帧头,还有4个字节帧尾;数据帧的大小范围为64字节-1518字节(包括头部)。至此帧不再继续封装,帧数据最终成为了在物理网络上的传输的字节序列。

  4. 帧转化为比特流

  • 解封装过程如下

在这里插入图片描述

  1. 如图,当数据帧到达目的主机的时候,沿着协议栈向上传递。每一个帧根据头部信息识别对应不同的协议,将数据部分(IP数据报)分发到不同网络协议指定的区域中;

  2. 同样的,网络层识别IP数据报的报头,将分片的数据部分组装成完整的传输层报文段,分发到报文段不同协议指定的区域中;

  3. 同样的,传输层根据报文段头部的端口号,将数据部分发送到指定的操作系统端口中,最后数据到达目标的APP;

  4. 到达应用层,APP(or ARP服务、RARP服务、ICMP服务)会收到被操作系统封装前的源应用数据(经过了各种解码/译码)。在APP看来,数据包封装/解封装好像是没有发生过一样。

1.6 端口号作用及常用协议端口号有哪些?

  • 一个APP应用程序可能需要执行多种服务,那么多种服务执行过程中,传输层在往应用层传递数据中,为了识别不同类型的数据,势必就需要识别不同的端口,以此对应不同的服务。所以端口号的作用是区分服务类型
  • 另一个作用是,可以保证在同一时间进行多个会话(数据传输服务)。
基于TCP/IP的常见端口号 协议服务
TCP 21 20 FTP文件传输服务
TCP 23 TELNET终端仿真服务
TCP 25 SMTP邮件传输服务
UDP 53 DNS域名解析服务
TCP 80 HTTP超文本传输服务
TCP 110 POP3 邮局协议版本3 使用的端口
TCP 443 HTTPS加密的超文本传输服务
TCP 1521 Oricle数据库服务
TCP 22 SSH

注意:

  • 以上是服务器端使用的端口即熟知端口号,在端口号为1-1023之间。在服务器上使用。
  • 1024-49151的端口号叫做登记端口号,为没有熟知端口号的应用程序使用。使用这类端口号必须在IANA按照规定的手续登记,以防止重复。在服务器上使用。
  • 49152-65535位客户端使用的临时端口号,动态选择的端口号,C-S之间通信结束之后,端口号就释放出来,供其他客户进程使用。

1.7 IP模块

  1. ip地址功能
  • 标识主机:标识其网络接口,即主机在网络中的具体位置
  • 网络寻址:该功能的目的是将IP数据报从一个网络模块 送到 目的地。寻址的过程叫做路由,每个IP数据报包含了发送主机的IP地址和目的主机的IP地址
  1. ip地址分类
A类IPV4地址 B类IPV4地址 C类IPV4地址 D类IPV4地址 E类IPV4地址
网络标志位 0 10 110 1110 11110
IP地址范围 1.0.0.0~127.255.255.255 128.0.0.0~191.255.255.255 192.0.0.0~223.255.255.255 224.0.0.0~239.255.255.255 240.0.0.0~247.255.255.255
可用IP地址范围 1.0.0.1~127.255.255.254 128.0.0.1~191.255.255.254 192.0.0.1~223.255.255.254
主机可以使用? × ×
网络个数 126(2^7-2) 16384(2^14) 2097152 (2^21)
每个网络可以容纳主机数量 16777214 (2^24-2) 65534 (2^16-2) 254 (2^8-2)
适用范围 拥有大量主机的大型网络 中等规模主机数的网络 小型局域网组播地址 ** 保留,仅作为搜索、Internet的实验和开发用
  1. 子网掩码功能

    含义:一种用来指明一个IP地址的哪些位标识的是主机所在的网络地址以及哪些位标识的是主机地址的位掩码。

    功能:将一个单一的大型网络按需求划分成若干个较小的网络。

  2. 网关作用

    网关工作在OSI参考模型的高三层,因此,并不使用冲突域、广播域的概念。网关主要用来进行高层协议之间的转换。例如,充当两个基于不同邮件协议的邮件服务之间的邮件网关。

    注意:这里网关的概念完全不同于PC主机以及路由器上配置的默认网关(default gateway).

  3. 什么是网络地址

    把IP地址转成二进制和子网掩码进行与运算所得的IP地址

  4. 什么是广播地址

    网络地址的主机位有5位全部变成1 所得的IP地址

  5. 什么是主机地址

    主机位数介于网络地址主机位和广播地址主机位数之间(不包括)的IP地址:网络地址+1即为第一个主机地址,广播地址-1即为最后一个主机地址

  6. 给定一个地址 192.168.1.0/255.255.255.240,子网数为多少?每个子网可用主机地址数为多少

    • IP地址中的192换算成二进制为11000000,故得出这个IP地址是一个C类地址,子网掩码为255.255.255.0,有八位是主机位

    • 实际子网掩码为255.255.255.240;240换算成二进制数为:

      11100000,故该掩码向主机位借了四位,实际主机位只有4位;

    • 子网数为2^4=16个(CIDR的计算方法)

    • 每个子网用主机数(平均划分)为:2^4-2=14个,除去的两个是全零、全一,这两种情况:全零用于标识网段、全一用于广播;除此以外,这14个可用主机地址还包含了分配给路由器端口的情况。

1.8 基础路由和交换技术

  1. 交换机工作原理

    • 封装和解封装
    • MAC-端口表/广播寻址
    • 转发

    交换机工作在数据链路层。内部会形成一张MAC-端口对应表,在存储和转发一个TCP/IP数据包时会查看该包的目的MAC地址,再核对自己的表确认要从交换机的哪一个端口转发出去;如果没有找到,就需要广播搜索以得到目的MAC地址;同样的当收到一个包的时候也会检查这个包的目的MAC地址是不是自己本身,并不断维护这一个MAC-端口表。

  2. 路由器工作原理

    • 解封装数据
    • 查找/维护路由表寻址,转发
    • 重新封装数据

    ​ 主要任务是接收来自某个网络接口的数据包,根据其中所含的目的地址,决定转发到下一个目的地址。因此,路由器首先得在转发路由表中查找它的目的地址,若找到了目的地址,就在数据包的帧格前添加下一个MAC地址,同时IP数据包头的**TTL(Time To Live)**位也开始减1,并重新计算校验和。当数据包被送到输出端口时,它需要按顺序等待,以便被传送到输出链路上。

    ​ 路由器的工作是通过协议来实现。

  3. 路由协议功能

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-tlIVQwvH-1595226585460)(assets/2020-06-27_150310.jpg)]

  4. LAN&WLAN区别

    WLAN LAN
    无线局域网 局域网
    完全无线通信 连接包括无线和有线
    容易受到外部干扰,信号不稳定 信号稳定
    不安全 安全
    不需有线连接交换机和路由器 需要物理连接交换机或路由器
    不需要连接以太网电缆 相关中继设备需要连接以太网电缆
    昂贵 便宜
    应用在:无线路由器连接/热点连接,主要在电脑笔记本、平板电脑、手机普及 主要应用在类似大学里的计算机
  5. NAT工作原理

​ 网络地址转换(NAT)是为保护 IP 地址而设计的。 它使得使用未注册 IP 地址的私有 IP 网络能够连接到互联网。 工作原理如下:

  • NAT 操作在一个路由器上,通常将两个网络连接在一起,在数据包转发到另一个网络之前,将内部网络中的私有地址(不是全局唯一的)转换成合法的地址
  • 涉及到多级NAT 转换
  • 局域网内用私网地址,互联网用公有地址

​ 作为此功能的一部分,NAT 可以被配置为只向外部世界发布整个网络的一个地址。 这可以有效地将整个内部网络隐藏在该地址后面,从而提供额外的安全性。 Nat 提供了安全和地址保护的双重功能,通常在远程访问环境中实现。

IPV4中,私有IP地址的范围有:

  • 10.0.0.0-10.255.255.255 (8位网络号)
  • 172.16.0.0—172.31.255.255(12位网络号)
  • **192.168.0.0-192.168.255.255 **(16位网络号)

Guess you like

Origin blog.csdn.net/weixin_31789689/article/details/107462911