ºìÁªLinuxÃÅ»§
Linux°ïÖú

LinuxÏ netstatµÄʹÓÃ

·¢²¼Ê±¼ä:2017-12-22 17:10:40À´Ô´:ºìÁª×÷Õß:Ronny
µ¼¶Á netstat ÊÇÒ»¸ö¸æËßÎÒÃÇϵͳÖÐËùÓÐ tcp/udp/unix socket Á¬½Ó״̬µÄÃüÁîÐй¤¾ß¡£Ëü»áÁгöËùÓÐÒѾ­Á¬½Ó»òÕߵȴýÁ¬½Ó״̬µÄÁ¬½Ó¡£ ¸Ã¹¤¾ßÔÚʶ±ðij¸öÓ¦ÓüàÌýÄĸö¶Ë¿ÚʱÌرðÓÐÓã¬ÎÒÃÇÒ²ÄÜÓÃËüÀ´ÅжÏij¸öÓ¦ÓÃÊÇ·ñÕý³£µÄÔÚ¼àÌýij¸ö¶Ë¿Ú¡£
LinuxÏ netstatµÄʹÓÃLinuxÏ netstatµÄʹÓÃ

netstat ÃüÁÄÜÏÔʾÆäËü¸÷ÖÖ¸÷ÑùµÄÍøÂçÏà¹ØÐÅÏ¢£¬ÀýÈç·ÓÉ±í£¬ Íø¿¨Í³¼ÆÐÅÏ¢£¬ Ðé¼ÙÁ¬½ÓÒÔ¼°¶à²¥³ÉÔ±µÈ¡£

±¾ÎÄÖУ¬ÎÒÃÇ»áͨ¹ý¼¸¸öÀý×ÓÀ´Ñ§Ï° netstat¡£

1 - ¼ì²éËùÓеÄÁ¬½Ó
ʹÓÃa Ñ¡Ïî¿ÉÒÔÁгöϵͳÖеÄËùÓÐÁ¬½Ó£¬

$ netstat -a
Õâ»áÏÔʾϵͳËùÓÐµÄ tcp¡¢udp ÒÔ¼° unix Á¬½Ó¡£

2 - ¼ì²éËùÓÐµÄ tcp/udp/unix socket Á¬½Ó
ʹÓà tÑ¡ÏîÖ»Áгö tcp Á¬½Ó£¬

$ netstat -at
ÀàËƵģ¬Ê¹ÓÃu Ñ¡ÏîÖ»Áгöudp Á¬½Ó£¬

$ netstat -au
ʹÓà x Ñ¡ÏîÖ»Áгö Unix socket Á¬½Ó£¬

$ netstat -ax
3 - ͬʱÁгö½ø³Ì ID/½ø³ÌÃû³Æ
ʹÓà pÑ¡Ïî¿ÉÒÔÔÚÁгöÁ¬½ÓµÄͬʱҲÏÔʾ PID »òÕß½ø³ÌÃû³Æ£¬¶øÇÒËü»¹ÄÜÓëÆäËûÑ¡ÏîÁ¬Óã¬

$ netstat -ap
4 - Áгö¶Ë¿ÚºÅ¶ø²»ÊÇ·þÎñÃû
ʹÓà n Ñ¡Ïî¿ÉÒÔ¼Ó¿ìÊä³ö£¬Ëü²»»áÖ´ÐÐÈκη´Ïò²éѯ£¨LCTT Òë×¢£ºÕâÀïÔ­ÎÄÓÐÎ󣩣¬¶øÊÇÖ±½ÓÊä³öÊý×Ö¡£ ÓÉÓÚÎÞÐè²éѯ£¬Òò´Ë½á¹ûÊä³ö»á¿ìºÜ¶à¡£

$ netstat -an
5 - Ö»Êä³ö¼àÌý¶Ë¿Ú
ʹÓÃl Ñ¡ÏîÖ»Êä³ö¼àÌý¶Ë¿Ú¡£Ëü²»ÄÜÓë a Ñ¡ÏîÁ¬Óã¬ÒòΪ a »áÊä³öËùÓж˿ڣ¬

$ netstat -l
6 - Êä³öÍøÂç״̬
ʹÓà s Ñ¡ÏîÊä³öÿ¸öЭÒéµÄͳ¼ÆÐÅÏ¢£¬°üÀ¨½ÓÊÕ/·¢Ë͵İüÊýÁ¿£¬

$ netstat -s
7 - Êä³öÍø¿¨×´Ì¬
ʹÓà I Ñ¡ÏîÖ»ÏÔʾÍø¿¨µÄͳ¼ÆÐÅÏ¢£¬

$ netstat -i
8 - ÏÔʾ¶à²¥×émulticast groupÐÅÏ¢
ʹÓÃg Ñ¡ÏîÊä³ö IPV4ÒÔ¼°IPV6 µÄ¶à²¥×éÐÅÏ¢£¬

$ netstat -g
9 - ÏÔʾÍøÂç·ÓÉÐÅÏ¢
ʹÓà r Êä³öÍøÂç·ÓÉÐÅÏ¢£¬

$ netstat -r
10 - ³ÖÐøÊä³ö
ʹÓà c Ñ¡Ïî³ÖÐøÊä³ö½á¹û

$ netstat -c
11 - ¹ýÂ˳öij¸ö¶Ë¿Ú
Óëgrep Á¬ÓÃÀ´¹ýÂ˳öij¸ö¶Ë¿ÚµÄÁ¬½Ó£¬

$ netstat -anp | grep 3306
12 - ͳ¼ÆÁ¬½Ó¸öÊý
ͨ¹ýÓëwc ºÍ grep ÃüÁîÁ¬Ó㬿ÉÒÔͳ¼ÆÖ¸¶¨¶Ë¿ÚµÄÁ¬½ÓÊýÁ¿

$ netstat -anp | grep 3306 | wc -l
Õâ»áÊä³ö mysql ·þÎñ¶Ë¿Ú£¨¼´ 3306£©µÄÁ¬½ÓÊý¡£

Õâ¾ÍÊÇÎÒÃǼò¶ÌµÄ°¸ÀýÖ¸ÄÏÁË£¬Ï£ÍûËü´ø¸øÄãµÄÐÅÏ¢Á¿×ã¹»¡£ ÓÐÈκÎÒÉÎÊ»¶Ó­Ìá³ö¡£
±¾ÎÄתÔØ×Ô£ºhttp://www.linuxprobe.com/linux-netstat.html

Ãâ·ÑÌṩ×îÐÂLinux¼¼Êõ½Ì³ÌÊé¼®£¬Îª¿ªÔ´¼¼Êõ°®ºÃÕßŬÁ¦×öµÃ¸ü¶à¸üºÃ£¬¿ªÔ´Õ¾µã£ºhttp://www.linuxprobe.com/
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 1 ÌõÆÀÂÛ

  1. Ronny ÓÚ 2017-12-22 17:10:52·¢±í:

    LinuxÏ netstatµÄʹÓÃ