linuxÔõôÉó²éÀú³Ì¶Ë¿Ú
ÔÚ linux ϵͳÖУ¬Éó²éÀú³Ì¶Ë¿Ú¿Éͨ¹ýÒÔÏÂÒªÁ죺netstat ÏÂÁnetstat -apn£ºÏÔʾËùÓÐÀú³ÌµÄ¶Ë¿Ú°ó¶¨¡£netstat -tulpn£ºÏÔʾ½ö tcp ºÍ udp ¶Ë¿Ú¡£netstat -lntp£ºÏÔʾ½öÕìÌý¶Ë¿Ú¡£lsof ÏÂÁlsof -i -p£ºÏÔʾʹÓÃÍøÂçÅþÁ¬µÄÀú³ÌºÍ¶Ë¿ÚºÅ¡£lsof -i4tcp:port£ºÏÔʾ¼àÌýÌض¨ tcp ¶Ë¿ÚµÄÅþÁ¬¡£lsof -i4udp:port£ºÏÔʾ¼àÌýÌض¨ udp ¶Ë¿ÚµÄÅþÁ¬¡£ss ÏÂÁss -tulpn£ºÏÔʾËùÓÐ tcp ºÍ udp
ÔõÑùÉó²é Linux Àú³Ì¶Ë¿Ú
ÔÚ Linux ϵͳÖУ¬¿ÉÒÔÇáËÉÉó²éÀú³ÌÕýÔÚ¼àÌýÄÄЩ¶Ë¿Ú¡£Õâ¹ØÓÚ¹ÊÕÏɨ³ý¡¢ÍøÂçÖÎÀíºÍÇå¾²ÐÔÖÁ¹ØÖ÷Òª¡£
ÒªÁì 1£ºÊ¹Óà netstat ÏÂÁî
netstat ÏÂÁîÊÇ×î³£ÓõÄÒªÁ죺
netstat -apn ÁгöËùÓÐÀú³ÌµÄ¶Ë¿Ú°ó¶¨£¬°üÀ¨Àú³Ì ID (PID) ºÍÏÂÁîÃû³Æ¡£
netstat -tulpn ½öÁгö TCP ºÍ UDP ¶Ë¿Ú¡£
netstat -lntp ½öÁгöÕìÌý¶Ë¿Ú¡£
ÒªÁì 2£ºÊ¹Óà lsof ÏÂÁî
lsof ÏÂÁî¿ÉÒÔÁгöËùÓз¿ªµÄÎļþºÍÍøÂçÅþÁ¬£º
lsof -i -P ÁгöËùÓÐÕýÔÚʹÓÃÍøÂçÅþÁ¬µÄÀú³Ì£¬°üÀ¨¶Ë¿ÚºÅºÍÀú³Ì ID¡£
lsof -i4TCP:port ½öÁгöÕìÌýÌض¨¶Ë¿ÚµÄ TCP ÅþÁ¬¡£
lsof -i4UDP:port ½öÁгöÕìÌýÌض¨¶Ë¿ÚµÄ UDP ÅþÁ¬¡£
ÒªÁì 3£ºÊ¹Óà ss ÏÂÁî
ss ÏÂÁîÊǽÏеÄÏÂÁÌṩÁ˸ü¸ß¼¶µÄ¹¦Ð§£º
ss -tulpn ÁгöËùÓÐ TCP ºÍ UDP ¶Ë¿Ú£¬°üÀ¨Àú³Ì ID ºÍ״̬¡£
ss -s ÏÔʾÿ¸öÐÒéµÄͳ¼ÆÐÅÏ¢¡£
ss -lntp ½öÁгöÕìÌý¶Ë¿Ú¡£
ʾÀý£ºÊ¹Óà netstat
ÒÔÏÂÏÂÁÁгöϵͳÉÏËùÓÐÕýÔÚÕìÌý¶Ë¿ÚµÄÀú³Ì£º
netstat -lntp
µÇ¼ºó¸´ÖÆ
Êä³öÀàËÆÓÚ£º
Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6725/sshd tcp6 0 0 :::22 :::* LISTEN 6725/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 2393/cupsd tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 646/systemd-resolved tcp 0 0 127.0.0.1:80 0.0.0.0:* LISTEN 24552/apache2
µÇ¼ºó¸´ÖÆ
´ËÊä³öÏÔʾÁËÎå¸öÀú³ÌÕýÔÚÕìÌý¶Ë¿Ú£¬°üÀ¨ sshd¡¢cupsd¡¢systemd-resolved ºÍ apache2¡£
ÒÔÉϾÍÊÇlinuxÔõôÉó²éÀú³Ì¶Ë¿ÚµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡