传输控制层的tcp协议
面向连接的
三次握手(socket面向连接是双向的,确保client 和server都能发出和接收数据包)
三次握手成功后 双方开辟资源 连接建立 三次握手-->数据传输-->四次分手。不可被分割
可靠的传输
三次握手的确认机制保证可靠的连接(ack)
成对出现的 源ip port --> 目标 ip port
服务端 22 80 8080
客户端 随机的端口号 0-65535
掩码:二进制按位的与运算(全1则1 有0则0) IPV4地址是四个字节 32位,一个字节表示十进制数范围是0~255
DEVICE eth0 IPADDR 192.168.150.11 NETMASK 255.255.255.0
ip地址包括 网络号和主机号
IPADDR和NETMASK按字节进行8位二进制与运算,得到 192.168.150.0(得到网络号)
eth0网卡的网线连接的局域网网号是192.168.150.0
这个网卡对应主机对应局域网里的第11号机器
路由表
[root@master1 ~]# route -N Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 172.16.227.254 0.0.0.0 UG 100 0 0 eth0 10.0.0.192 10.128.24.6 255.255.255.192 UG 0 0 0 tunl0 10.0.1.64 10.128.158.6 255.255.255.192 UG 0 0 0 tunl0 [root@master1 ~]# ping www.baidu.com PING www.a.shifen.com (14.215.177.39) 56(84) bytes of data. 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=1 ttl=54 time=5.39 ms 64 bytes from 14.215.177.39 (14.215.177.39): icmp_seq=2 ttl=54 time=5.32 ms
ping baidu后 的外网地址和路由表中的掩码做与运算,能和条目中的Destination匹配上,说明数据包是通过那个条目中的Gateway中转出去的(下一跳)
网络层的工作其实就是跳出路由表中的下一跳(网关) 或者直接发出去,不走网关(局域网)
链路层
[root@master1 ~]# ping baidu.com PING baidu.com (220.181.38.251) 56(84) bytes of data. 64 bytes from 220.181.38.251 (220.181.38.251): icmp_seq=1 ttl=52 time=33.1 ms 64 bytes from 220.181.38.251 (220.181.38.251): icmp_seq=2 ttl=52 time=32.9 ms 64 bytes from 220.181.38.251 (220.181.38.251): icmp_seq=3 ttl=52 time=32.8 ms ^C --- baidu.com ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms rtt min/avg/max/mdev = 32.868/32.988/33.188/0.205 ms [root@master1 ~]# route -N Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 172.16.227.254 0.0.0.0 UG 100 0 0 eth0 10.0.0.192 10.128.24.6 255.255.255.192 UG 0 0 0 tunl0 [root@master1 ~]# [root@master1 ~]# arp -a|grep 227.254 gateway (172.16.227.254) at 28:de:e5:22:11:0a [ether] on eth0
网络层选好下一跳之后 就进入链路层
链路层协议 arp协议
一个数据包既有传输控制层端口号还有 网络层ip地址 和 链路层硬件地址
链路层mac地址(网卡地址)是主机通过arp协议在局域网做广播拿gateway地址做匹配返回的