傳輸控制層的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地址做匹配返回的