❶ 鎬庝箞鏌ョ湅鏈鏈哄紑鏀劇殑絝鍙
鍝涓絝鍙h鍝涓鏈嶅姟鍗犵敤錛熸湁澶氬皯涓寮鏀劇鍙o紵鏈鏂囦粙緇嶅備綍鎵鎻 Linux 緋葷粺鎴栦換浣曡繙紼嬬郴緇熶笂寮鏀劇殑絝鍙c
鏃犺烘偍鏄浣跨敤 Linux 浣滀負鏈嶅姟鍣ㄨ繕鏄妗岄潰鐜澧冿紝浜嗚В寮鏀劇殑絝鍙f垨姝e湪浣跨敤鐨勭鍙e湪鍚勭嶆儏鍐典笅閮戒細鏈夋墍甯鍔┿
渚嬪傦紝濡傛灉鎮ㄦe湪榪愯屽熀浜 Apache 鎴 Ngnix 鐨 Web 鏈嶅姟鍣錛屽垯浣跨敤鐨勭鍙e簲璇ユ槸 80 鎴 443銆傛鏌ョ鍙e皢紜璁よ繖涓鐐廣傚悓鏍鳳紝鎮ㄥ彲浠ユ鏌 SMTP 鎴 SSH 鎴栧叾浠栦竴浜涙湇鍔℃e湪浣跨敤鍝涓絝鍙c傚湪灝嗙鍙e垎閰嶇粰鏂版湇鍔℃椂錛屼簡瑙e摢浜涚鍙fe湪浣跨敤鏄寰堟湁蹇呰佺殑銆
鎮ㄨ繕鍙浠ユ鏌ユ槸鍚︽湁絝鍙h鐢ㄤ簬瀹夊叏鍏ヤ鏡銆
鍦 Linux 涓鏈夊氱嶆鏌ョ鍙g殑鏂規硶銆傛垜灝嗗湪鏈鏂囦腑鍒嗕韓鎴戞渶鍠滄㈢殑涓ょ嶆柟娉曘
鏂規硶涓錛氫嬌鐢 lsof 鍛戒護鏌ョ湅褰撳墠鐧誨綍鐨 Linux 緋葷粺涓鎵撳紑鐨勭鍙
濡傛灉鎮ㄧ洿鎺ユ垨閫氳繃 SSH 鐧誨綍鍒扮郴緇燂紝鍒欏彲浠ヤ嬌鐢 lsof 鍛戒護媯鏌ュ叾絝鍙c
sudo lsof -i -P -n
lsof 鍛戒護鐢ㄤ簬鏌ユ壘鐢ㄦ埛浣跨敤鐨勬枃浠跺拰榪涚▼銆傝繖閲岀敤鍒扮殑閫夐」鏄錛
-i錛氬傛灉娌℃湁鎸囧畾IP鍦板潃錛岃繖涓閫夐」閫夋嫨鍒楀嚭鎵鏈夌綉緇滄枃浠-P錛氱佹㈠皢絝鍙e彿杞鎹涓虹鍙e悕縐, 濡 3306 杞涓 MySQL-n錛氱佹IP杞鎹涓篽ostname錛岀己鐪佹槸涓嶅姞涓-n鍙傛暟
鐒惰岋紝涓婇潰鍛戒護涔熷悜鎴戜滑灞曠ず浜嗚稿氳$畻鏈哄疄闄呬笂騫舵湭鐩戝惉鐨勯濆栫鍙c
鎮ㄥ彲浠ュ皢姝ゅ懡浠ょ殑杈撳嚭閫氳繃綆¢亾浼犺緭鍒 grep 鍛戒護騫跺尮閰嶆ā寮忊淟ISTEN鈥濓紝濡備笅鎵紺猴細
sudo lsof -i -P -n | grep LISTEN
榪欐牱鍙浼氭樉紺烘垜浠鐨勮$畻鏈烘e湪鐩戝惉鐨勭鍙d互鍙婂摢涓鏈嶅姟姝e湪浣跨敤鎵榪板紑鏀劇鍙c
鏂規硶浜岋細浣跨敤 netcat 鍛戒護媯鏌ヤ換浣曟湇鍔″櫒涓婄殑絝鍙
nc (Netcat) 鏄涓涓鍛戒護琛屽疄鐢ㄧ▼搴忥紝瀹冧嬌鐢 TCP 鍜 UDP 鍗忚閫氳繃緗戠粶鍦ㄨ$畻鏈轟箣闂磋誨彇鍜屽啓鍏ユ暟鎹銆
涓嬮潰緇欏嚭浜 nc 鍛戒護鐨勮娉曪細
nc
host port
榪欎釜瀹炵敤紼嬪簭鏈変竴涓 -z 鏍囧織銆備嬌鐢ㄦ椂錛屽畠灝嗕嬌 nc 鎵鎻忎睛鍚瀹堟姢紼嬪簭鑰屼笉瀹為檯鍚戠鍙e彂閫佷換浣曟暟鎹銆
灝嗘や笌 -v 鏍囧織緇撳悎浣跨敤錛屽惎鐢ㄨ︾粏妯″紡錛屾偍鍙浠ヨ幏寰楄︾粏鐨勮緭鍑恆
浠ヤ笅鏄浣跨敤 nc 鍛戒護鎵鎻忕郴緇熷紑鏀劇鍙g殑鍛戒護錛
nc -z -v IP-ADDRESS 1-65535 21 | grep -v 'Connection refused'
灝 IP-ADDRESS 鏇挎崲涓烘偍姝e湪媯鏌ョ鍙g殑 Linux 緋葷粺鐨 IP 鍦板潃銆傚彲浠ユ槸鏈鏈篿p 127.0.0.1錛屼篃鍙浠ユ槸榪滅▼鏈哄櫒鐨剗p鍦板潃銆
鑷充簬鎴戜負浠涔堥夋嫨鍊 1 鍒 65535錛岄偅鏄鍥犱負絝鍙h寖鍥翠粠 1 寮濮嬶紝鍒 65535 緇撴潫銆
鏈鍚庯紝灝嗚緭鍑洪氳繃綆¢亾浼犻掔粰 grep 鍛戒護銆備嬌鐢 -v 閫夐」錛屽畠浼氭帓闄や換浣曡繑鍥炲寘鎷 鈥淐onnection refused鈥 鐨勮屻
榪欏皢鏄劇ず璁$畻鏈轟笂鎵撳紑鐨勬墍鏈夌鍙o紝榪欎簺絝鍙e彲鐢辯綉緇滀笂鐨勫彟涓鍙拌$畻鏈鴻塊棶(鍦ㄩ槻鐏澧欏厑璁哥殑鎯呭喌涓)銆
緇撹
鍦ㄨ繖涓ょ嶆柟娉曚腑錛屾垜鏇村枩嬈 lsof 鍛戒護銆傚畠姣 nc 鍛戒護鏇村揩銆備絾鏄錛屾偍闇瑕佺櫥褰曠郴緇熷苟鎷ユ湁 sudo 璁塊棶鏉冮檺銆傛崲鍙ヨ瘽璇達紝濡傛灉鎮ㄦe湪綆$悊緋葷粺錛屽垯 lsof 鏄鏇村悎閫傜殑閫夋嫨銆
nc 鍛戒護鍏鋒湁鏃犻渶鐧誨綍鍗沖彲鎵鎻忕鍙g殑鐏墊椿鎬э紝浣嗗綋鎵鎻忚繙紼嬩富鏈烘椂鍥犱負闇瑕佺綉緇滀氦浜掍細寰堟參, 鐗瑰埆鏄闈涓磋秴鏃惰鋒眰鏃訛紝鍙浣跨敤 -q secs 鍙傛暟璁劇疆瓚呮椂鏃墮棿銆