Posted 娣卞叆鍘熺悊
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了相关的知识,希望对你有一定的参考价值。
鐐瑰嚮馃憜钃濊壊鈥?nbsp;娣卞叆鍘熺悊鈥濓紝鍏虫敞骞垛€?/span>璁句负鏄熸爣鈥?/span>
鎶€鏈共璐э紝绗竴鏃堕棿鎺ㄩ€?/span>
1 姒傝堪
TCP鎻愪緵鍙潬鐨勮繍杈撳眰銆?/p>
鍙潬鎬т繚璇佷箣涓€锛氱‘璁や粠鍙︿竴绔敹鍒扮殑鏁版嵁銆?/p>
浣嗘暟鎹拰纭閮芥湁鍙兘浼氫涪澶便€俆CP閫氳繃鍦ㄥ彂閫佹椂璁剧疆涓€涓畾鏃跺櫒鏉ヨВ鍐宠繖绉嶉棶棰樸€?/p>
濡傛灉褰撳畾鏃跺櫒婧㈠嚭鏃惰繕娌℃湁鏀跺埌纭锛屽畠灏遍噸浼犺鏁版嵁銆?/p>
TCP瀵逛簬姣忎釜杩炴帴TCP绠$悊4涓笉鍚岀殑瀹氭椂鍣細
閲嶄紶瀹氭椂鍣?/strong>锛氫娇鐢ㄤ簬褰撳笇鏈涙敹鍒板彟涓€绔殑纭銆?/p>
2MSL瀹氭椂鍣?/strong>锛氭祴閲忎竴涓繛鎺ュ浜嶵IME_WAIT鐘舵€佺殑鏃堕棿銆?/p>
鍧氭寔(persist)瀹氭椂鍣?/strong>锛氫娇绐楀彛澶у皬淇℃伅淇濇寔涓嶆柇娴佸姩锛屽嵆浣垮彟涓€绔叧闂簡鍏舵帴鏀剁獥鍙?/p>
淇濇椿(keepalive)瀹氭椂鍣?/strong>锛氱敤浜庢娴嬩竴涓┖闂茶繛鎺ョ殑鍙︿竴绔綍鏃跺穿婧冩垨閲嶅惎銆?/p>
2 TCP鐨勭姸鎬佹満
瓒呮椂鎯呭喌锛?/h4>
寤虹珛杩炴帴鏃禨YN瓒呮椂锛?/p>
client涓诲姩鎵撳紑杩炴帴锛屽彂閫丼YN鎶ユ枃缁檚erver
server鏀跺埌鍚庤鍔ㄦ墦寮€锛屽彂閫丼YN+ACK鎶ユ枃缁檆lient锛屾鏃禼lient鐩存帴涓嬬嚎
瀵艰嚧server鏃犳硶鏀跺埌client鐨凙CK鎶ユ枃锛屽嵆璇CP杩炴帴鏃㈡病鏈夊缓绔嬩篃娌℃湁鏂紑锛屾墍浠erver鍙堜細閲嶄紶SYN+ACK鎶ユ枃
鍦↙inux涓嬶紝榛樿閲嶈瘯娆℃暟涓?娆★紝閲嶈瘯鐨勯棿闅旀椂闂翠粠1s寮€濮嬫瘡娆¢兘缈诲€嶏紝5娆$殑閲嶈瘯鏃堕棿闂撮殧涓?s, 2s, 4s, 8s, 16s锛屾€诲叡31s锛岀5娆″彂鍑哄悗杩樿绛?2s閮界煡閬撶5娆′篃瓒呮椂浜嗭紝鎵€浠ワ紝鎬诲叡闇€瑕?1s + 2s + 4s+ 8s+ 16s + 32s = 2^6 -1 = 63s锛孴CP鎵嶄細鎶婃柇寮€杩欎釜杩炴帴銆?/p>
SYN Flood锛?/p>
鍑忓皯Server鐨勯噸璇曟鏁?/p>
澧炲ぇSYN鐨勮繛鎺ユ暟
澶勭悊涓嶈繃鏉ョ殑杩炴帴鐩存帴涓㈠純
鎭舵剰浼€犲ぇ閲忕殑TCP杩炴帴骞舵柇寮€Client锛屽鑷碨erver缁存寔浜嗗ぇ閲忕殑TCP杩炴帴锛屼笖闇€瑕?3绉掑悗鎵嶄細鏂紑锛屽嵆63绉掑唴鐨凾CP杩炴帴鏁拌冻澶熷鏃讹紝Server灏嗘壙鍙椾笉浣忥紝瀵艰嚧姝e父鐨勮繛鎺ヤ笉鑳藉鐞嗐€?/p>
澶勭悊鏂规锛?/p>
ISN鐨勫垵濮嬪寲锛?/p>
ISN涓嶆槸姣忔寤虹珛寤虹珛杩炴帴鏃堕兘浠?寮€濮?/p>
闂锛氬洜涓哄鏋滀粠1寮€濮嬶紝client鍙戦€佷簡30涓猻egment缁檚erver锛屾鏃剁綉缁滄柇寮€锛岃繃浼歝lient閲嶈繛锛屽張浣跨敤ISN=1鏉ュ彂閫佹姤鏂囷紝浣嗕箣鍓嶇殑鎶ユ枃宸茬粡閫佸埌浜嗭紝鍗硈erver璁や负client鐨処SN锛堝垵濮嬪寲搴忓垪鍙凤級涓?0锛屼絾鏄疄闄呬笂涓?銆?/p>
瑙e喅鏂规硶锛欼SN浼氬拰涓€涓亣鐨勬椂閽熺粦鍦ㄤ竴璧凤紝杩欎釜鏃堕挓浼氬湪姣?寰瀵笽SN鍋氬姞涓€鎿嶄綔锛岀洿鍒拌秴杩?^32锛屽張浠?寮€濮嬨€?/p>
MSL锛圡aximum Segment Lifetime锛夛細TCP娈电殑鏈€澶у瓨娲绘椂闂达紝4ms*2^32=4.55灏忔椂锛屽嵆TCP娈靛瓨娲绘椂闂翠笉瓒呰繃4.55灏忔椂灏变笉浼氶噸鐢↖SN銆?/p>
MSL 鍜?TIME_WAIT锛?/strong>
鍦═CP鐨勭姸鎬佸浘涓紝浠?span>TIME_WAIT鐘舵€佸埌CLOSED鐘舵€侊紝鏈変竴涓秴鏃惰缃紝杩欎釜瓒呮椂璁剧疆鏄?2 * MSL銆?/p>
TIME_WAIT锛? * MSL锛夛細纭繚鏈夎冻澶熺殑鏃堕棿璁╁绔敹鍒颁簡ACK锛屽鏋滆鍔ㄥ叧闂殑閭f柟娌℃湁鏀跺埌Ack锛屽氨浼氳Е鍙戣鍔ㄧ閲嶅彂FIN锛屼竴鏉ヤ竴鍘绘濂戒笉瓒呰繃2 * MSL銆?/p>
鏈夎冻澶熺殑鏃堕棿璁╄繖涓繛鎺ヤ笉浼氳窡鍚庨潰鐨勮繛鎺ユ贩鍦ㄤ竴璧凤紙鏈変簺璺敱鍣ㄤ細缂撳瓨IP鏁版嵁鍖咃紝瀵艰嚧杩炴帴琚噸鐢級銆?/p>
3 TCP閲嶈瘯鏈哄埗锛堝彂閫佹柟锛?/h3>
锛?锛夋杩?/h4>
TCP瑕佷繚璇佹墍鏈夌殑鏁版嵁鍖呴兘鍒拌揪锛屽繀闇€鏈夐噸浼犳満鍒躲€?/p>
鍙戦€佺鍙戜簡1,2,3,4,5涓€鍏变簲浠芥暟鎹紝鎺ユ敹绔敹鍒颁簡1锛?锛屼簬鏄洖ack 3锛岀劧鍚庢敹鍒颁簡4锛堟敞鎰忔鏃?娌℃敹鍒帮級锛屾鏃剁殑TCP浼氭€庝箞鍔烇紵
锛?锛夎秴鏃堕噸浼犳満鍒?/h4>
涓嶅洖ACK锛屼竴鐩寸瓑寰匰N=3鐨勫埌鏉ワ紝鑰屽彂閫佹柟涓€鐩存敹涓嶅埌3鐨凙CK锛屽氨浼氳秴鏃堕噸浼?.
杩欑鏂瑰紡浼氭湁涓ラ噸鐨勯棶棰橈紝閭e氨鏄绛?锛屾墍浠ュ鑷?鍜?宸茬粡琚敹鍒颁簡锛岃€屽彂閫佹柟涔熷畬鍏ㄤ笉鐭ラ亾锛堟病鏈夋敹鍒癆CK锛夛紝鎵€浠ュ彂閫佹柟鍙兘浼氭偛瑙傚湴璁や负涔熶涪浜嗭紙鍗虫湁鍙兘瀵艰嚧4鍜?鐨勯噸浼狅級銆?/p>
鍙戦€佹柟鐨勪袱绉嶉€夋嫨锛?/p>
浠呬粎閲嶄紶timeout鐨勫寘锛岃妭绾﹀甯︼紝浣嗘槸闇€瑕佺户缁瓑寰呭悗缁姤鏂嘇CK鎴栬€卼imeout閲嶄紶锛堟晥鐜囦綆锛夈€?/p>
閲嶄紶timeout鍚庣殑鎵€鏈夊寘锛屾氮璐瑰甯︼紝鑰屼笖鍙兘鍋氫簡鏃犵敤鍔熴€?/p>
锛?锛夊揩閫熼噸浼犳満鍒?/h4>
濡傛灉鍙戦€佹柟鍙戝嚭浜?锛?锛?锛?锛?浠芥暟鎹紝1鍏堝埌浜嗭紝浜庢槸灏盿ck鍥?锛岀粨鏋?鍥犱负鏌愪簺鍘熷洜娌℃敹鍒般€?鍒拌揪浜嗭紝ack涔熷洖2锛屽悗闈㈢殑4鍜?閮藉埌浜嗭紝ack涔熷洖2锛?娌℃湁鏀跺埌锛夈€?/p>
浜庢槸鍙戦€佺鏀跺埌浜嗕笁涓猘ck=2鐨勭‘璁わ紝鐭ラ亾浜?杩樻病鏈夐€佽揪锛屼簬鏄噸浼?锛堟垨鑰?涔嬪悗鐨勬墍鏈夊寘锛夈€傜劧鍚庢帴鏀剁鏀跺埌浜?锛屾鏃?锛?锛?閮芥敹鍒颁簡锛屼簬鏄痑ck鍥?銆?/p>
浼樼偣锛?span>涓嶉渶瑕佺瓑寰匒CK瓒呮椂锛屼絾鏄粛鐒舵病鏈夎В鍐虫槸閲嶄紶2杩樻槸閲嶄紶2涓庝箣鍚庣殑鎵€鏈夊寘銆?/p>
锛?锛塖ACK 鏂规硶
SACK鍥炲鍙互鍛婄煡鍙戦€佺闇€瑕?span>鎺掗櫎鍝簺鎶ユ枃杩涜鍙戦€?/p>
璇ュ崗璁渶瑕佷袱杈归兘鏀寔銆?/p>
寮虹儓寤鸿鐪嬬湅鍙旂殑鏂囩珷
鍙傝€冿細https://coolshell.cn/articles/11564.html
https://www.cnblogs.com/linzhanfly/p/9968172.html
-娣卞叆鍘熺悊-
鐭ュ叾鐒跺苟鐭ュ叾鎵€浠ョ劧
以上是关于的主要内容,如果未能解决你的问题,请参考以下文章
寤虹珛杩炴帴鏃禨YN瓒呮椂锛?/p>
client涓诲姩鎵撳紑杩炴帴锛屽彂閫丼YN鎶ユ枃缁檚erver
server鏀跺埌鍚庤鍔ㄦ墦寮€锛屽彂閫丼YN+ACK鎶ユ枃缁檆lient锛屾鏃禼lient鐩存帴涓嬬嚎
瀵艰嚧server鏃犳硶鏀跺埌client鐨凙CK鎶ユ枃锛屽嵆璇CP杩炴帴鏃㈡病鏈夊缓绔嬩篃娌℃湁鏂紑锛屾墍浠erver鍙堜細閲嶄紶SYN+ACK鎶ユ枃
鍦↙inux涓嬶紝榛樿閲嶈瘯娆℃暟涓?娆★紝閲嶈瘯鐨勯棿闅旀椂闂翠粠1s寮€濮嬫瘡娆¢兘缈诲€嶏紝5娆$殑閲嶈瘯鏃堕棿闂撮殧涓?s, 2s, 4s, 8s, 16s锛屾€诲叡31s锛岀5娆″彂鍑哄悗杩樿绛?2s閮界煡閬撶5娆′篃瓒呮椂浜嗭紝鎵€浠ワ紝鎬诲叡闇€瑕?1s + 2s + 4s+ 8s+ 16s + 32s = 2^6 -1 = 63s锛孴CP鎵嶄細鎶婃柇寮€杩欎釜杩炴帴銆?/p>
SYN Flood锛?/p>
鍑忓皯Server鐨勯噸璇曟鏁?/p>
澧炲ぇSYN鐨勮繛鎺ユ暟
澶勭悊涓嶈繃鏉ョ殑杩炴帴鐩存帴涓㈠純
鎭舵剰浼€犲ぇ閲忕殑TCP杩炴帴骞舵柇寮€Client锛屽鑷碨erver缁存寔浜嗗ぇ閲忕殑TCP杩炴帴锛屼笖闇€瑕?3绉掑悗鎵嶄細鏂紑锛屽嵆63绉掑唴鐨凾CP杩炴帴鏁拌冻澶熷鏃讹紝Server灏嗘壙鍙椾笉浣忥紝瀵艰嚧姝e父鐨勮繛鎺ヤ笉鑳藉鐞嗐€?/p>
澶勭悊鏂规锛?/p>
ISN鐨勫垵濮嬪寲锛?/p>
ISN涓嶆槸姣忔寤虹珛寤虹珛杩炴帴鏃堕兘浠?寮€濮?/p>
闂锛氬洜涓哄鏋滀粠1寮€濮嬶紝client鍙戦€佷簡30涓猻egment缁檚erver锛屾鏃剁綉缁滄柇寮€锛岃繃浼歝lient閲嶈繛锛屽張浣跨敤ISN=1鏉ュ彂閫佹姤鏂囷紝浣嗕箣鍓嶇殑鎶ユ枃宸茬粡閫佸埌浜嗭紝鍗硈erver璁や负client鐨処SN锛堝垵濮嬪寲搴忓垪鍙凤級涓?0锛屼絾鏄疄闄呬笂涓?銆?/p>
瑙e喅鏂规硶锛欼SN浼氬拰涓€涓亣鐨勬椂閽熺粦鍦ㄤ竴璧凤紝杩欎釜鏃堕挓浼氬湪姣?寰瀵笽SN鍋氬姞涓€鎿嶄綔锛岀洿鍒拌秴杩?^32锛屽張浠?寮€濮嬨€?/p>
MSL锛圡aximum Segment Lifetime锛夛細TCP娈电殑鏈€澶у瓨娲绘椂闂达紝4ms*2^32=4.55灏忔椂锛屽嵆TCP娈靛瓨娲绘椂闂翠笉瓒呰繃4.55灏忔椂灏变笉浼氶噸鐢↖SN銆?/p>
MSL 鍜?TIME_WAIT锛?/strong>
鍦═CP鐨勭姸鎬佸浘涓紝浠?span>TIME_WAIT鐘舵€佸埌CLOSED鐘舵€侊紝鏈変竴涓秴鏃惰缃紝杩欎釜瓒呮椂璁剧疆鏄?2 * MSL銆?/p>
TIME_WAIT锛? * MSL锛夛細纭繚鏈夎冻澶熺殑鏃堕棿璁╁绔敹鍒颁簡ACK锛屽鏋滆鍔ㄥ叧闂殑閭f柟娌℃湁鏀跺埌Ack锛屽氨浼氳Е鍙戣鍔ㄧ閲嶅彂FIN锛屼竴鏉ヤ竴鍘绘濂戒笉瓒呰繃2 * MSL銆?/p>
鏈夎冻澶熺殑鏃堕棿璁╄繖涓繛鎺ヤ笉浼氳窡鍚庨潰鐨勮繛鎺ユ贩鍦ㄤ竴璧凤紙鏈変簺璺敱鍣ㄤ細缂撳瓨IP鏁版嵁鍖咃紝瀵艰嚧杩炴帴琚噸鐢級銆?/p>
锛?锛夋杩?/h4>
涓嶅洖ACK锛屼竴鐩寸瓑寰匰N=3鐨勫埌鏉ワ紝鑰屽彂閫佹柟涓€鐩存敹涓嶅埌3鐨凙CK锛屽氨浼氳秴鏃堕噸浼?.
杩欑鏂瑰紡浼氭湁涓ラ噸鐨勯棶棰橈紝閭e氨鏄绛?锛屾墍浠ュ鑷?鍜?宸茬粡琚敹鍒颁簡锛岃€屽彂閫佹柟涔熷畬鍏ㄤ笉鐭ラ亾锛堟病鏈夋敹鍒癆CK锛夛紝鎵€浠ュ彂閫佹柟鍙兘浼氭偛瑙傚湴璁や负涔熶涪浜嗭紙鍗虫湁鍙兘瀵艰嚧4鍜?鐨勯噸浼狅級銆?/p>
鍙戦€佹柟鐨勪袱绉嶉€夋嫨锛?/p>
浠呬粎閲嶄紶timeout鐨勫寘锛岃妭绾﹀甯︼紝浣嗘槸闇€瑕佺户缁瓑寰呭悗缁姤鏂嘇CK鎴栬€卼imeout閲嶄紶锛堟晥鐜囦綆锛夈€?/p>
閲嶄紶timeout鍚庣殑鎵€鏈夊寘锛屾氮璐瑰甯︼紝鑰屼笖鍙兘鍋氫簡鏃犵敤鍔熴€?/p>
锛?锛夊揩閫熼噸浼犳満鍒?/h4>
濡傛灉鍙戦€佹柟鍙戝嚭浜?锛?锛?锛?锛?浠芥暟鎹紝1鍏堝埌浜嗭紝浜庢槸灏盿ck鍥?锛岀粨鏋?鍥犱负鏌愪簺鍘熷洜娌℃敹鍒般€?鍒拌揪浜嗭紝ack涔熷洖2锛屽悗闈㈢殑4鍜?閮藉埌浜嗭紝ack涔熷洖2锛?娌℃湁鏀跺埌锛夈€?/p>
浜庢槸鍙戦€佺鏀跺埌浜嗕笁涓猘ck=2鐨勭‘璁わ紝鐭ラ亾浜?杩樻病鏈夐€佽揪锛屼簬鏄噸浼?锛堟垨鑰?涔嬪悗鐨勬墍鏈夊寘锛夈€傜劧鍚庢帴鏀剁鏀跺埌浜?锛屾鏃?锛?锛?閮芥敹鍒颁簡锛屼簬鏄痑ck鍥?銆?/p>
浼樼偣锛?span>涓嶉渶瑕佺瓑寰匒CK瓒呮椂锛屼絾鏄粛鐒舵病鏈夎В鍐虫槸閲嶄紶2杩樻槸閲嶄紶2涓庝箣鍚庣殑鎵€鏈夊寘銆?/p>
锛?锛塖ACK 鏂规硶
濡傛灉鍙戦€佹柟鍙戝嚭浜?锛?锛?锛?锛?浠芥暟鎹紝1鍏堝埌浜嗭紝浜庢槸灏盿ck鍥?锛岀粨鏋?鍥犱负鏌愪簺鍘熷洜娌℃敹鍒般€?鍒拌揪浜嗭紝ack涔熷洖2锛屽悗闈㈢殑4鍜?閮藉埌浜嗭紝ack涔熷洖2锛?娌℃湁鏀跺埌锛夈€?/p>
浜庢槸鍙戦€佺鏀跺埌浜嗕笁涓猘ck=2鐨勭‘璁わ紝鐭ラ亾浜?杩樻病鏈夐€佽揪锛屼簬鏄噸浼?锛堟垨鑰?涔嬪悗鐨勬墍鏈夊寘锛夈€傜劧鍚庢帴鏀剁鏀跺埌浜?锛屾鏃?锛?锛?閮芥敹鍒颁簡锛屼簬鏄痑ck鍥?銆?/p>
浼樼偣锛?span>涓嶉渶瑕佺瓑寰匒CK瓒呮椂锛屼絾鏄粛鐒舵病鏈夎В鍐虫槸閲嶄紶2杩樻槸閲嶄紶2涓庝箣鍚庣殑鎵€鏈夊寘銆?/p>
SACK鍥炲鍙互鍛婄煡鍙戦€佺闇€瑕?span>鎺掗櫎鍝簺鎶ユ枃杩涜鍙戦€?/p>
璇ュ崗璁渶瑕佷袱杈归兘鏀寔銆?/p>
https://www.cnblogs.com/linzhanfly/p/9968172.html
-娣卞叆鍘熺悊-
鐭ュ叾鐒跺苟鐭ュ叾鎵€浠ョ劧