CS-Notes/notes/计算机网络.md
2018-02-22 14:47:22 +08:00

849 lines
30 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!-- GFM-TOC -->
* [????? ????](#?????-????)
* [?????????](#?????????)
* [ISP](#isp)
* [???????????](#???????????)
* [?????????????](#?????????????)
* [??·????????齻??](#??·????????齻??)
* [1. ??·????](#1-??·????)
* [2. ???????](#2-???????)
* [3. ???齻??](#3-???齻??)
* [???](#???)
* [1. ???????](#1-???????)
* [2. ???????](#2-???????)
* [3. ???????](#3-???????)
* [4. ??????](#4-??????)
* [??????????????*](#??????????????)
* [1. ???Э??](#1-???э??)
* [2. ???Э??](#2-???э??)
* [3. ???????????????????](#3-???????????????????)
* [4. TCP/IP ?????](#4-tcpip-?????)
* [????? ?????](#?????-?????)
* [?????](#?????)
* [???????](#???????)
* [??????ü???](#??????ü???)
* [1. ?????á???????](#1-?????á???????)
* [2. ?????????](#2-?????????)
* [3. ???????](#3-???????)
* [4. ??????](#4-??????)
* [?????? ??????·??](#??????-??????·??)
* [????????????](#????????????)
* [1. ??????](#1-??????)
* [2. ???????](#2-???????)
* [3. ?????](#3-?????)
* [??????? -PPP Э??](#???????--ppp-э??)
* [????????????](#????????????)
* [????? - CSMA/CD Э??*](#?????---csmacd-э??)
* [??????](#??????)
* [MAC ??](#mac-??)
* [?????????](#?????????)
* [?????? ?????*](#??????-?????)
* [????Э?? IP ????](#????э??-ip-????)
* [IP ????????](#ip-????????)
* [IP ??????](#ip-??????)
* [1. ????? IP ???](#1-?????-ip-???)
* [2. ????????](#2-????????)
* [3. ??????? CIDR???????????](#3-???????-cidr???????????)
* [IP ????? MAC ???](#ip-?????-mac-???)
* [???????Э?? ARP](#???????э??-arp)
* [·???????](#·???????)
* [????????·??????????](#????????·??????????)
* [·???????????????](#·???????????????)
* [·?????Э??](#·?????э??)
* [1. ???????Э?? RIP](#1-???????э??-rip)
* [2. ???????Э?? OSPF](#2-???????э??-ospf)
* [3. ??????Э?? BGP](#3-??????э??-bgp)
* [??????????Э?? ICMP](#??????????э??-icmp)
* [??????????? PING](#???????????-ping)
* [IP ??](#ip-??)
* [????????? VPN](#?????????-vpn)
* [????????? NAT](#?????????-nat)
* [?????? ?????*](#??????-?????)
* [UDP ?? TCP ?????](#udp-??-tcp-?????)
* [UDP ??????](#udp-??????)
* [TCP ??????](#tcp-??????)
* [TCP ??????????](#tcp-??????????)
* [TCP ????λ???](#tcp-????λ???)
* [TCP ????????](#tcp-????????)
* [TCP ???????](#tcp-???????)
* [TCP ????????](#tcp-????????)
* [TCP ???????](#tcp-???????)
* [??????????????](#??????????????)
* [??????????](#??????????)
* [?????? ??ò?*](#??????-??ò?)
* [?????? DNS](#??????-dns)
* [1. ??ν?](#1-??ν?)
* [2. ????????](#2-????????)
* [???????Э?? FTP](#???????э??-ftp)
* [??????Э?? TELNET](#??????э??-telnet)
* [????? WWW](#?????-www)
* [???????Э??](#???????э??)
* [POP3](#pop3)
* [IMAP](#imap)
* [SMTP](#smtp)
* [???????????Э?? DHCP](#???????????э??-dhcp)
* [?????? P2P](#??????-p2p)
* [Web ??????????](#web-??????????)
* [??????](#??????)
* [?ο?????](#?ο?????)
<!-- GFM-TOC -->
# ????? ????
## ?????????
?????????????????????????????????????????????????????????????????????硣
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/04ff7ae6-7bee-4cf8-82f8-dfe2ba1f3616.jpg)
## ISP
?????????????? ISP ??????????????????????? IP ???????????????·???·???????????豸???????????? ISP ?????????????????????????
????????????????? ISP ????ISP ?????????????С??????? ISP?????? ISP ????? ISP??
???????????? IXP ??????????????????????????????????????????顣
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/17d807ef-03bf-4824-a97c-ea5fb58ec61d.jpg)
## ???????????
1. ??????????????????????????????????????????????
2. ??????????????????????????Щ?????·??????ɡ????????????????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/005d83c2-e64a-41f0-bbdd-51c71d494a18.jpg)
## ?????????????
**1. ??? - ????????C/S??**
????????????????????????????????
**2. ????P2P??**
?????????????????
## ??·????????齻??
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/b97958dd-3e43-45f7-97f5-3ec20f3f8b88.jpg)
### 1. ??·????
??·????????绰????????????????????????????????????????·?????????????????????????????·??????????????в?????????????????·??????·????????·??????????????????? 10%??
### 2. ???????
???????????????????????????????????????洢???????????????????????????????????????????????????洢????????
### 3. ???齻??
???齻????????洢???????????????????????????????????????????????????????????????????????????з??????????????????С????????з?????????????????????????飬??????????????????????????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/6f4af159-8b03-4246-8d0e-222db65bb83c.jpg)
?洢??????????????????·???????????????飬???????齻?????????????????·?????
?????????????????????????С???洢??????????????
## ???
????? = ??????? + ??????? + ??????? + ??????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/ceee91c2-da26-4169-94c3-e4608b46b9ac.png)
### 1. ???????
??????·???????????????????????
![](http://latex.codecogs.com/gif.latex?\\\\delay=\frac{l(bit)}{v(bit/s)})
???? l ??????????????v ????????????
### 2. ???????
??????????д????????????????????????????????????????
![](http://latex.codecogs.com/gif.latex?\\\\delay=\frac{l(m)}{v(m/s)})
???? l ???????????v ???????????????????????
### 3. ???????
??????·???????????????д????????????????????????????????????????????
### 4. ??????
??????·????????????к????????????????????????????統??????????
## ??????????????*
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/1005dc9d-9049-4b06-9524-6171e56ebd8c.png)
### 1. ???Э??
??? a ????????б????????????????
1. ???????????????????????????????????????????????????????
2. ???????????????????佨???????????
### 2. ???Э??
1. ??ò???????ó??????????????????? HTTP??DNS ????????λ??????
2. ???????????????????????????????????ò?Э?????????????????Э???????????????????ò?Э?顣????????????Э?飺???????Э?? TCP?????????????????????????????????λ?????Σ?????????Э?? UDP????????????????????????????????????λ???????????
3. ???????????????????????????????Э??????????????е?????????????????????????????λ????????????????????????д???
4. ??????·??????????????????????????????????к????·????·??Э???????????????????????????·??????????????????????
5. ?????????????????????????????????????????????????????????塣????????????????????δ????????????ε???????????????????·??о???????Щ????
### 3. ???????????????????
???????????У??????????Э????????????????β?????????????????в?????????β????
·???????????????Э?飬???·????λ??????????У????????????????ó?????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/f7d5da89-2d75-4d8f-85e7-6b608865dc00.jpg)
### 4. TCP/IP ?????
???????????????Э??????????·??????????????????
????? TCP/IP ????????????? OSI ????????ò??????????? IP ????????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/3e2200b3-1c18-4853-ae42-7788e8e1f939.png)
TCP/IP Э?????????????????м?С?????IP Э????????????????????λ??
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/9ecaebee-670e-4cb2-9cdb-3029c00f33bd.png)
# ????? ?????
## ?????
1. ????????????????????
2. ??????????????????????
3. ?????????????????????
## ???????
??????????????????????????????????????????????????????????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/d2c55c84-aa1f-43c1-bd97-457bcb7816b3.png)
## ??????ü???
### 1. ?????á???????
??????????????????????????ò?????????????????????????????????????????????????????????
??????????????????????????????????????????????????????????????????????????????????????????????????ó????????????????????????????????????????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/543d47a1-f0dd-414f-b23c-0c142c814854.png)
### 2. ?????????
??????????????????????????????????????е?λ???????????????????????????????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/29058e09-bb72-4040-a73d-4c497895e9ce.jpg)
### 3. ???????
????????á??????????????????????ò?????????????????????????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/78534153-88d1-4f83-a6e0-59064dbdc43a.png)
### 4. ??????
??????????? m bit ??????????????е????????????????????????? $\vec{S}$ ?? $\vec{T}$ ??
![](http://latex.codecogs.com/gif.latex?\\\\\vec{S}\cdot\vec{T}=0)
??????? m=8??????? $\vec{S}$ ? 00011011??????и???????????????? 1 ??????????????????? 0 ??????????????? 11100100??
???????? 00011011 ???? (-1 -1 -1 +1 +1 -1 +1 +1)????????
![](http://latex.codecogs.com/gif.latex?\\\\\frac{1}{m}\vec{S}\cdot\vec{S}=1)
![](http://latex.codecogs.com/gif.latex?\\\\\frac{1}{m}\vec{S}\cdot\vec{S'}=-1)
???? $\vec{S'}$ ? $\vec{S}$ ?????
?????????????????????????????????? $\vec{S}$ ????????????????????????????? 0 ????????????????????????? 1 ??????????????? 1?????? -1 ??????????????? 0??
?????÷??????????????? m ????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/0042edad-8e3b-4279-bd93-6906fcd1b640.jpg)
# ?????? ??????·??
## ????????????
### 1. ??????
????????????????????????β??????????????????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/ea5ed9b2-6d9f-48fb-b890-0288caf9088a.jpg)
### 2. ???????
????????????????????????????????????
??????????β???????????????????к????β?????????????????????????λ??????????ж?????????????г??????β???????????????????????????????????????????????????????????????????????????????????????????д????????????????????????????????????????????????????????????????????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/44e1d90e-3fe6-4dd6-8dce-6daab12e7663.jpg)
### 3. ?????
????????·?????????????????飨CRC????????????
## ??????? -PPP Э??
??????????????????????? ISP ?????????????????PPP Э??????????????? ISP ????????????????????·??Э?顣
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/8b5bd2c8-8425-4a8b-89db-235c95800de9.jpg)
?? PPP ????У?F ?????????????A ?? C ?????????塣FCS ????? CRC ????????С??????ε????????? 1500??
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/a5fa89e7-54b9-4e2f-8c48-a35712d7b2f5.jpg)
## ????????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/8b15e36f-69b4-46b6-a07c-7234ac7c7927.jpg)
## ????? - CSMA/CD Э??*
?????????????????????????????????????
CSMA/CD ???????????????? / ??????
**??????**??????????????????磬??????????????????????????
**???????**??????????????????????????????????????????????????????????
**??????**????????У??????????????????????????????????????????????????????????????????????????????????У??????????????????????????????п???????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/f9ed4da5-0032-41e6-991a-36d995ec28fd.png)
?????????????? ??????????????????? 2?? ?????????????????????? 2?? ? **??????**????о??????????????м???????????????η?????????????
??????????????????????????????????????????????? **????????????????** ?????????????????????? {0, 1, .., (2<sup>k</sup>-1)} ??????????????????? r?????? r ??????????????????????
## ??????
????????????ü??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????С?
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/897a4f4e-2683-44e1-a26a-c0d0234dc576.jpg)
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/40c3f8e5-3a20-45b6-a60c-77b9b952e104.jpg)
## MAC ??
MAC ????? 6 ????48 λ????????????Ψ????????????????????ж???????????ж?? MAC ??????????????????????????????????????????????????????
MAC ???????????????????????Э?飻??????γ????? 46-1500 ???????С????????FCS ?????????У??????? CRC ???鷽?????????????????????????? FCS ????????????????????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/50d38e84-238f-4081-8876-14ef6d7938b5.jpg)
## ?????????
??????????????????????λ??????????飬???????????????????е????????????????????????? (A1, A2, A3, A4) ??????????????????A1 ???????? A2??A3??A4 ?????????????????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/a74b70ac-323a-4b31-b4d5-90569b8a944b.png)
# ?????? ?????*
## ????Э?? IP ????
???????????????????????????????????????????????????????????????????????????????????????????????
??? IP Э?飬?????????????????????????????????????????????????????????硣
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/fe3d224c-8ffd-40f9-85b1-86ffe1393f6c.jpg)
?? IP Э?????????????????Э?飺
1. ???????Э?? ARP??Address Resolution Protocol??
2. ??????????Э?? ICMP??Internet Control Message Protocol??
3. ?????????Э?? IGMP??Internet Group Management Protocol??
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/163cf8b4-5f30-46c9-af00-316a71b3c890.jpg)
## IP ????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/8681db55-0873-434b-aa98-83d07e8392ae.jpg)
**?汾** : ?? 4??IPv4???? 6??IPv6?????????
**???????** : ? 4 λ?????????? 15???? 1 ??????? 1 ?? 32 λ???????????? 4 ?????????????????? 20 ???????????С? 5??????????????????? 4 ????????????????β??????????????
**???????** : ??????????????????????????á?
**?????** : ???????????????????????
**???** : ??????????????????????????????????????????????????????????????
**????** : ????????????????????????????????λ? 8 ????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/45c86855-9b18-4cf4-a9a7-f8b6eb78d133.png)
**???????** ??TTL????????????????????????????????????в??????????·???????????λ???? TTL ? 0 ?????????????
**Э??**?????Я???????????????????Э????д??????? ICMP??TCP??UDP ???
**????????**??????????????????·?????????????????????????????????????????????????????????
## IP ??????
IP ?????????????????????????Σ?
1. ????? IP ?????
2. ??????????
3. ?????????
### 1. ????? IP ???
????????????????????????????в???????в????????????????????????
IP ??? ::= {< ????? >, < ?????? >}
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/2ddd6132-60be-4a72-9daa-3d9756191f4a.png)
### 2. ????????
?????????????????????????????????????? IP ???????????? IP ?????????????翴??????????????
IP ??? ::= {< ????? >, < ?????? >, < ?????? >}
????????????????????????????? B ?????????????????? 255.255.0.0????? B ???????????????????????????????? 11111111 11111111 11000000 000000??????? 255.255.192.0??
### 3. ??????? CIDR???????????
CIDR ???????? A ??B ??? C ????????????????????????????????????????? IP ??????б????????????????????????仯??
IP ??? ::= {< ???????? >, < ?????? >}
CIDR ??????????? IP ?????????????????????????????? 128.14.35.7/20 ???? 20 λ?????????
CIDR ??????????????????????????????????? 1 ?????????????????
??? CIDR ????????к????????? CIDR ??????????????????????????磬??????·????????????·????????????????·?????????·????????????????????????????????????·???????????·??????????????????
??·????????????ɡ??????????????????????????????????????????????????????????????????
## IP ????? MAC ???
????????????????????????·?????????????·????????????????????У?IP ?????????????????????????? MAC ?????????·????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/86b71296-0d1e-4a63-bcd9-54955b6b781b.jpg)
## ???????Э?? ARP
????? IP ?????? MAC ?????
?????????????? ARP ??????棬????????????? IP ??? ?? MAC ?????????????У?????????????????? ARP ??????飬??? IP ????????????? ARP ????????? MAC ?????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/8bc6fc2c-d198-4759-b06c-18d94d851e97.png)
## ·???????
·??????????????????·??????????????
???????????????????????????????????????????????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/3a676c54-b559-4466-9b21-eb10f1e25879.jpg)
????????????????????????????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/7f82fd18-7f16-4125-ada6-bb6b795b4fda.png)
## ????????·??????????
- ??????????????????·??????? MAC ????????? MAC ????????·????????????????????????? IP ????? MAC ????????
- ·????λ???????????? IP ????????? IP ?????????顣?????·???????·?????????·???
## ·???????????????
1. ???????????????????????? IP ??? D?????????????? N????·????????????????? IP ???????????????????·????????????
2. ?? N ???????·?????????????????????????????????????
3. ??·????????????? D ?????????·????????????????????????????????·??????
4. ??·??????е??????? N ??·????????????????·?????????????????·??????
5. ??·?????????????·????????????????·???????????????·??????
6. ??????????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/8d211911-0e62-4190-ab00-d8610adec4a0.jpg)
## ·?????Э??
??????????·?????Э?鶼???????????????????????????????仯???????????е?????
??????????????????С???????? AS????? AS ????????????? AS ?????·?????Э?顣
?????·?????Э?黮?????????
1. ???????Э?? IGP??Interior Gateway Protocol?? ????????????????? RIP ?? OSPF??
2. ??????Э?? EGP??External Gateway Protocol?? ????????????????? BGP??
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/e0be6970-5b0e-44a2-bc71-df4d61c42b8f.jpg)
### 1. ???????Э?? RIP
RIP ??????????????????????·?????Э?顣??????????????????????·????????? 1?????????? 15?????? 15 ????????
RIP ????????????????????·?????????????·???????????ν??????????·?????????????????????????κ?????????????????????·?????????
????????????
1. ????? X ??????·?????????? RIP ??????????????е?????????????????????е?????? X?????????е??????μ? 1??
2. ??????? RIP ?????е????????????????????裺
- ???????·??????????????? N?????????????·????У?
- ???????????·????????? X??????????????滻???·????е?????????????????????е???? d С??·????е????????и??????????·?????? Net2, 5, P???±???? Net2, 4, X???????????????????????
3. ?? 3 ???????????????·?????????·???????????·?????????????????????? 16??
RIP Э???????????С?????? RIP ????????????? 15???????????????????????????????????????????????????????????????????·??????
### 2. ???????Э?? OSPF
???????·?????? OSPF????????? RIP ?????????????????
?????? OSPF ???????????????????????????????·???????????????? Dijkstra ????????·???? SPF??
OSPF ???????????
1. ?????????е?????·??????????????????????鷺????
2. ??????????????????·????????·??????·??????????Щ·?????????????·????????????÷??á?????????????????????
3. ??е???·???????仯???·??????????????
????·??????????????????????????????????????? RIP??OSPF ????????????????
### 3. ??????Э?? BGP
AS ????·????????????????????????????????? AS ?????ò????·?????Э?飬???????????·????????????? AS ????·???????????й????????????Щ AS ??????????? AS ??????
BGP ??????????????·????????????·?ɡ???????·??????·?????Э?顣
??? AS ?????????? BGP ???????????????????? BGP ????????佨?? TCP ??????????·???????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/eb6271de-22c9-4f4b-8b31-eab1f560efac.png)
## ??????????Э?? ICMP
ICMP ????????Ч????? IP ???????????????????????????? IP ??????У????????????Э?顣
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/9b5e0fa0-9274-4219-a3a9-84fbb509c735.jpg)
ICMP ??????????汨??????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/6e11b122-95ce-4869-bf7d-3b0d7591707e.jpg)
## ??????????? PING
PING ?? ICMP ????????????????????????????????????????
PING ??????
1. PING ???????ε???????????????????? MAC ??????????????????????????? MAC ??????????????? ARP ????
2. PING ??????ε?????????????????????????????????????????????????????????? MAC ????????? MAC ????????????
## IP ??
???????????У?????????????鸴??????????????????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/c77b6a18-dfac-42a2-ac89-7e99481275dc.jpg)
## ????????? VPN
???? IP ???????????????????????? IP ??????????С???????????е????????????????????????????????е???????????????????У?????????????????????????????Ч?? IP ??????????????
????????????飺
1. 10.0.0.0 \~ 10.255.255.255
2. 172.16.0.0 \~ 172.31.255.255
3. 192.168.0.0 \~ 192.168.255.255
VPN ??ù???????????????????????????????????塣?????????????????????????????????????????????????????????????????????о???????????????
????У????? A ?? B ????????????????????????? A ?????? X ???????????? B ?????? Y ????IP ????????????? 10.1.0.1????????? 10.2.0.3?????????????????????????·???? R1??R1 ???????????м????????????????????????????????·???? R1 ??????? 125.1.2.3?????????·???? R2 ??????? 194.4.5.6??·???? R2 ???????????????????н???????????????????????????? 10.2.0.3????????? Y??
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/bf4ed077-d481-4db7-9e7a-85d841a5a8c3.jpg)
## ????????? NAT
???????????????????? IP ????????????????????????????????? NAT ???????? IP ??????? IP??
???????NAT ?????? IP ????? IP ?????????????????? n ????? IP ???????????????????????? n ?????????????????????Ч????????? IP ????????????? NAT ???????????????????????????????????????????????????????????? IP ???????????? NAT ?????????????????? NAPT??
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/0f31bc7a-d60b-48a6-8e3f-597708369e52.png)
# ?????? ?????*
??????????鷢??????????????????????????????????????????е?????
??????????????????????????????????????????????????????????????ó????????????????????????????????????????????????
## UDP ?? TCP ?????
????????Э?? UDP??User Datagram Protocol??
???????Э?? TCP??Transmission Control Protocol??
UDP ???????????????????????????????????????????????ó????????????????????????????? UDP ???????
TCP ???????????????????????????????????????????????????????????????????ò?????????????????????????????????С?????????飩
## UDP ??????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/bd6c05f3-02ee-4c8a-b374-40c87154a898.jpg)
????????? 8 ????????????????????????????????12 ????α????????????????????????
## TCP ??????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/21a00b02-c0a6-4bcd-9af0-5ec6bb66e34c.jpg)
**???** ???????????????б??????????? 301????????????????? 301?????Я???????????? 100 ????????????????ε?????? 401??
**????** ????????????????????ε????????? B ?????? A ???????????????Σ????? 501??Я???????????? 200 ??????? B ?????????????ε????? 701??B ????? A ????????????????? 701??
**???????** ?????????????????????????????????????????????????????
**??? ACK** ???? ACK=1 ??????????Ч????????Ч??TCP ?涨????????????????д???????ζ?????? ACK ?? 1??
**??? SYN** ????????????????????????? SYN=1??ACK=0 ?????????????????????Ρ??????????????????????????? SYN=1??ACK=1??
**??? FIN** ??????????????????? FIN=1 ???????????ε?????????????????????????????????????
**????** ????????????????÷??????????????????????????????????????????????????????????????????
## TCP ??????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/086871db-5871-460f-97b7-126cd738bb0e.jpg)
???? A ???????B ??????????
1. ???? B ???? LISTEN????????????????????????????
2. A ?? B ??????????????Σ?SYN=1??ACK=0???????????????? x??
3. B ?????????????Σ?????????????????? A ??????????????Σ?SYN=1??ACK=1??????? x+1??????????????????? y??
4. A ??? B ????????????κ????? B ????????????? y+1?????? x+1??
5. B ??? A ???????????????
## TCP ????λ???
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/78f65456-666b-4044-b4ee-f7692dbbc0d3.jpg)
??????????????????????????????????????????????????? ACK????? ACK ????????????? 1??
1. A ??????????????Σ?FIN=1??
2. B ?????????????? TCP ???????????B ???? A ??????????? A ?????? B ?????????
3. ?? B ????????????????????????????????Σ?FIN=1??
4. A ?????????????????????
**TIME_WAIT**
?????????????????? FIN ???????????????????????????? CLOSED ??????????????????????????????????????????????
1. ?????????????????????????? B ???? A ??????????????Σ??????????·????????????????Σ?A ????????????????????????????????
2. ??????????????Ч????????????Ρ???????????????γ???????????????????????????
## TCP ????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/223fc26e-2fd6-484c-bcb7-443cac134f15.jpg)
???????????????????????????????????????????????????????????????? TCP ??????е??????θ????????????????С?????????????????????????????????????С??
???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
???????????????????????????????????????????????????????????? {31, 32, 34, 35}?????? {31, 32} ??????? {34, 35} ??????????????? 32 ?????????????????????????????????????????????????????????????
## TCP ???????
TCP ??ó????????????????????????????????????????????????????????????????????Ρ?
???????δ????????????????????????????????? RTT??????????????? RTTs ?????????
![](http://latex.codecogs.com/gif.latex?\\\\RTTs=(1-a)*(RTTs)+a*RTT)
??????????????? RTO ???????? RRTs??TCP ?????????????????
![](http://latex.codecogs.com/gif.latex?\\\\RTO=RTTs+4*RTT_d)
???? RTT<sub>d</sub> ??????????? RRT ?? RRTs ?й??
## TCP ????????
????????????????????????????????????????ü??????
?????????????????е??????ο????????????????????С????????????????????????罫???????????? 0???????????????????
## TCP ???????
??????????????????齫????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????ü???????????????????????????????????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/a69af9bb-b5ad-4896-862d-697e5ee4feb1.png)
TCP ?????????????????????????????????????????????????????????????????????????????????cwnd????????????????????????????????????????????????????????????????????????????????????????????
???????????????????裺
1. ?????????????????棬?????????????????
2. ??? TCP ?????????????????????贰????С??λ?????Ρ?
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/346244ff-98c1-4f12-9a87-d0832e8c04cf.jpg)
### ??????????????
???????????????????? cwnd=1????????????? 1 ??????Σ??????????? cwnd ?????????????????????????????2??4??8 ...
?????????????ζ??? cwnd ????????????? cwnd ????????????????÷????????????????????????????????????????????????????????? ssthresh???? cwnd >= ssthresh ??????????????????????? cwnd ?? 1??
????????????????? ssthresh = cwnd / 2???????????????????
### ??????????
?????????????ν????????ζ???÷???????????????ε????????????????? M<sub>1</sub> ?? M<sub>2</sub>???????? M<sub>4</sub>?????????? M<sub>2</sub> ??????
????????????????????????????????????????????ζ??????????????? M<sub>2</sub> ???? M<sub>3</sub> ??????????п??????????????????????Ρ?
???????????????????????Σ?????????????????????п??????? ssthresh = cwnd / 2 ??cwnd = ssthresh?????????????????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/b18d679b-c8e2-4564-88ee-7600090e46da.jpg)
# ?????? ??ò?*
## ?????? DNS
????????????? IP ?????
?????????????
### 1. ??ν?
?????????????ι?????????????????????????????????????????????????????????????????????????????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/c2117f61-1177-4768-bf33-cf4f950d911c.png)
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/a4b162e5-db2a-4a27-b213-1fe481c5a06a.png)
????????????????????????
**(1) ????????????**????????????????
**(2) ??????????????**????????????????
**(3) ?????????????**?????????????????
?????????????????????????л?????????? b ???? abc.com ?л?????????????abc.com ?? y.abc.com
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/fc0c6b2d-68c7-4de8-aaaa-97355a4f0472.jpg)
??????????????????????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/8b335d94-c1ca-42e1-ad48-bb179d28a4f1.jpg)
**(4) ??????????????**????????????????????????????????????????档
### 2. ????????
??????????????????????????????飬?????????????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/6bc61bb8-3b1c-4dc8-ac25-cef925ace0eb.jpg)
## ???????Э?? FTP
FTP ?????????? TCP????????????????????е? TCP ????????????????????????????????????????????????????????????????????????????????????????????? 21???????????????? 20??
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/58633775-8584-4a01-ad3f-eee4d9a466e1.jpg)
## ??????Э?? TELNET
TELNET ?????????????????????????????????????????
TELNET ?????????????????????????????粻?????????????з????塣
## ????? WWW
?? HTTP ????
## ???????Э??
??????????????????????????????????????????????????Э?????Э?顣???з???Э?鳣?? SMTP?????Э?鳣?? POP3 ?? IMAP??
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/de1e46d2-748f-4da3-a29e-7de7bc840366.jpg)
### POP3
POP3 ??????????????????????????????????????????
### IMAP
IMAP Э???п???????????????????????????????????????????????????????????????????IMAP ?????????????????????????????????????????IMAP Э???????????????????С?
### SMTP
SMTP ?????? ASCII ????????????????? MIME ?????????????????MIME ????и????????? SMTP???????????????????????????? ASCII ?????????
![](https://github.com/CyC2018/InterviewNotes/blob/master/pics/ed5522bb-3a60-481c-8654-43e7195a48fe.png)
## ???????????Э?? DHCP
DHCP ??????弴?????????????????????????????? IP ??????????
DHCP ?????????????? IP ??????????????????????·???? IP ????????????????? IP ?????
??????????????? IP ??????????????? DHCP ??????????????????? 1???? 255.255.255.255:67???????????? 0???? 0.0.0.0:68????DHCP ??????????????????????? IP ???????????????????? DHCP ???????????????
## ?????? P2P
????????????????ж??????????????????????????????????飬?????С??????????????????????????????????????????飬????????????????????????????Щ????飬?????????????????????Щ????顣
?????????????????????????????????????????????????????????????????????????????????????????????С????????κ????????????????????
???????????????????????????????????????????????????????????????Щ?????????????????Щ????????????????????????????鶼????????????н??С?
???????????????????????????????????????????????????飬???????????????????????и????????????????????????????顣
????????????????????????????????????????????????????????????????????
P2P ??????????????κ?????ж?????????????????÷?????б? DHT?????????????е?????? IP ??????
## Web ??????????
1. ?? DNS ?????????? DNS ???????????????????
2. ??????? HTTP ???????????? TCP ?????
3. ???????????????У?HTTP ?????????? TCP ?С?HTTP ???????????? 80??????????????????? 80 ?????????????????????????????????????????????????? TCP ????????????????????
4. ???????????????У?TCP ????λ?????? IP ?????У?IP ??????·??????????????
5. ????·??IP ?????????? MAC ??У?IP ????????? MAC ????????? ARP??
6. ???????? HTTP ???????????????档
7. ?????????? HTTP ??????????????????????档
8. ?????????????????????????????????????档
## ??????
| ??ò?Э?? | ???? | ?????Э?? |
| -- | -- | -- |
| DNS | 53 | UDP |
| FTP | ???????? 21?????????? 20 | TCP |
| TELNET | 23 | TCP |
| DHCP | 67 68 | UDP |
| HTTP | 80 | TCP |
| SMTP | 25 | TCP |
| POP3 | 110 | TCP |
| IMAP | 143 | TCP |
# ?ο?????
- ????????? ?????
- ???????????????