TCP

背景linux操作系统通信过程

解释一下tcp协议连接过程

传输控制层

面向连接的?

  • 利用三次握手来建立连接(是传输控制层做,由内核完成)。保证接受和发送是通畅的,光通没有用,要为对方开辟资源,为对方进行服务。
  • 四次分手来分开连接:我要和你断开连接,我知道了,我也想跟你断开,我听到了。开始断开释放资源。
  • socket:是客户端ip+port+ 服务端ip+port的四元组(socket表)port:0-65535,

可靠协议?

  • 确认机制保证通畅
  • 发送的数据包是有序的

网络层

ip+路由表

ip和掩码(Genmask)按位与(就是你在找是不是你的目的ip),不是则进行下一跳

链路层

我们最找的还是物理地址也就是mac地址

所以有:arp协议,找到我目的IP地址的mac地址。并缓存下来ip和mac地址的表

linux操作系统网络通信过程

所有的网络发送都需要有个设备叫做网卡来发送:下面是一个lunix网卡的配置说明

DEVICE=eth0 #指出设备名称

NM_CONTROLLED=yes #network mamager的参数,实时生效,不需要重启

ONBOOT=yes #设置为yes,开机自动启用网络连接

IPADDR=192.168.21.129 #IP地址,网络里面都是通过ip地址来寻址的,是必须的

BOOTPROTO=none #设置为none禁止DHCP,设置为static启用静态IP地址,设置为dhcp开启DHCP服务

NETMASK=255.255.255.0 #子网掩码(ip地址和掩码做按位与就是你的网络号,你的主机在192.168.21这个网段的编号)

DNS1=8.8.8.8 #第一个dns服务器,我们通过域名来找到主机,换取主机的ip地址来通信

TYPE=Ethernet #网络类型为:Ethernet

GATEWAY=192.168.21.2 #设置网关

DNS2=8.8.4.4 #第二个dns服务器

IPV6INIT=no #禁止IPV6

USERCTL=no #是否允许非root用户控制该设备,设置为no,只能用root用户更改

HWADDR=00:0C:29:2C:E1:0F #网卡的Mac地址

PREFIX=24

DEFROUTE=yes

IPV4_FAILURE_FATAL=yes

NAME="System eth0" #定义设备名称

再来看下linux路由表

root@centos6 ~]#route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.27.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     1002   0        0 eth0
0.0.0.0         192.168.27.2    0.0.0.0         UG    0      0        0 eth0

主要字段说明:

  • Destination: 目的地址,可以是主机地址、网络地址,常用的是网络地址
  • Gateway: 网关地址,所有未知地址都会找网关,有网关统一转发,只有边缘网络才会配置网关,并且直连网络不需要配置网关
  • Genmask:目的地址的子网掩码
  • Iface: 接口,去往目的地址的网络路径的出口(也就是从那个出口可以去往目的地址) 

你要去那个ip,你就跟genmask做按位与,如果和Destination相同,就找到了。如果网关地址是0.0.0.0,就代表是在本局域网内通信,直接从端口eth0就发出去了,走交换机。

如果不是,就走网关的那个ip,通过交换机发arp数据包找到这个ip的路由器的mac地址,去进行下一跳。

OUTPUT
  The output of the kernel routing table is organized in the following columns

  Destination
    The destination network or destination host.
  Gateway
    The gateway address or '*' if none set.
  Genmask
    The netmask for the destination net; '255.255.255.255' for a host destination and '0.0.0.0' for the default route.
  Flags  Possible flags include
    U (route is up)
    H (target is a host)
    G (use gateway)
    R (reinstate route for dynamic routing)
    D (dynamically installed by daemon or redirect)
    M (modified from routing daemon or redirect)
    A (installed by addrconf)
    C (cache entry)
    !  (reject route)
  Metric 
    The 'distance' to the target (usually counted in hops).      
    It is not used by recent kernels, but may be needed by routing daemons.
  Ref
    Number of references to this route. (Not used in the Linux kernel.)
  Use
    Count of lookups for the route.     
    Depending on the use of -F and -C this will be either route cache misses (-F) or hits (-C).
  Iface
    Interface to which packets for this route will be sent.
  MSS
    Default maximum segment size for TCP connections over this route.
  Window
    Default window size for TCP connections over this route.
  irtt
    Initial  RTT  (Round Trip Time).     
    The kernel uses this to guess about the best TCP protocol parameters without waiting on (possibly slow) answers.
  HH (cached only)
    The number of ARP entries and cached routes that refer to the hardware header cache for the cached route. 
    This will be -1 if a  hardware address is not needed for the interface of the cached route (e.g. lo).
  Arp (cached only)
    Whether or not the hardware address for the cached route is up to date.

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值