netstat是控制台命令,是一个监控TCP/IP网络的非常有用的工具,它可以显示路由表、实际的网络连接以及每一个网络接口设备的状态信息。Netstat用于显示与IP、TCP、UDP和ICMP协议相关的统计数据,一般用于检验本机各端口的网络连接情况。
常用选项
-a
(all)显示所有选项,默认不显示LISTEN相关-t
(tcp)仅显示tcp相关选项-u
(udp)仅显示udp相关选项-n
拒绝显示别名,能显示数字的全部转化成数字。-l
仅列出有在 Listen (监听) 的服務状态-p
显示建立相关链接的程序名-r
显示路由信息,路由表-e
显示扩展信息,例如uid等-s
按各个协议进行统计-c
每隔一个固定时间,执行该netstat命令。
示例
列出所有的网络连接。
ma@ma:~$ netstat -a | tail -10 unix 3 [ ] STREAM CONNECTED 19834 unix 3 [ ] STREAM CONNECTED 29730 @/tmp/dbus-ZuLcXGJsqx unix 3 [ ] STREAM CONNECTED 28459 unix 3 [ ] STREAM CONNECTED 28134 unix 3 [ ] STREAM CONNECTED 85061 @/tmp/dbus-ZuLcXGJsqx unix 3 [ ] STREAM CONNECTED 28631 @/tmp/dbus-x79US7IeiT unix 3 [ ] STREAM CONNECTED 28484 unix 3 [ ] STREAM CONNECTED 25628 /var/run/dbus/system_bus_socket unix 3 [ ] STREAM CONNECTED 30171 @/tmp/.X11-unix/X0 unix 3 [ ] STREAM CONNECTED 28364
列出监听中的连接。
ma@ma:~$ netstat -l | tail -10 unix 2 [ ACC ] STREAM LISTENING 19537 /run/acpid.socket unix 2 [ ACC ] STREAM LISTENING 19538 /var/run/avahi-daemon/socket unix 2 [ ACC ] STREAM LISTENING 19539 /var/run/dbus/system_bus_socket unix 2 [ ACC ] STREAM LISTENING 19540 /var/run/cups/cups.sock unix 2 [ ACC ] STREAM LISTENING 22992 /var/run/NetworkManager/private-dhcp unix 2 [ ACC ] STREAM LISTENING 22842 /tmp/.X11-unix/X0 unix 2 [ ACC ] STREAM LISTENING 29201 /tmp/.ICE-unix/2496 unix 2 [ ACC ] STREAM LISTENING 27712 @/tmp/dbus-ZuLcXGJsqx unix 2 [ ACC ] STREAM LISTENING 27642 @/com/ubuntu/upstart-session/1000/2243 unix 2 [ ACC ] STREAM LISTENING 123399 /var/run/pcscd/pcscd.comm
以IP地址列出所有的连接,并且显示连接的进程。
ma@ma:~$ netstat -apn | tail -10 (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) unix 3 [ ] STREAM CONNECTED 19834 - unix 3 [ ] STREAM CONNECTED 29730 2354/dbus-daemon @/tmp/dbus-ZuLcXGJsqx unix 3 [ ] STREAM CONNECTED 28459 2564/indicator-sess unix 3 [ ] STREAM CONNECTED 28134 2433/ibus-ui-gtk3 unix 3 [ ] STREAM CONNECTED 85061 2354/dbus-daemon @/tmp/dbus-ZuLcXGJsqx unix 3 [ ] STREAM CONNECTED 28631 2467/dbus-daemon @/tmp/dbus-x79US7IeiT unix 3 [ ] STREAM CONNECTED 28484 2571/dconf-service unix 3 [ ] STREAM CONNECTED 25628 - /var/run/dbus/system_bus_socket unix 3 [ ] STREAM CONNECTED 30171 - @/tmp/.X11-unix/X0 unix 3 [ ] STREAM CONNECTED 28364 2509/unity-panel-se
列出所有的udp连接。
ma@ma:~$ netstat -aupn | tail -10 (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name udp 0 0 0.0.0.0:5353 0.0.0.0:* - udp 0 0 0.0.0.0:55611 0.0.0.0:* - udp 0 0 0.0.0.0:631 0.0.0.0:* - udp 0 0 0.0.0.0:53301 0.0.0.0:* - udp 0 0 127.0.1.1:53 0.0.0.0:* - udp 0 0 0.0.0.0:68 0.0.0.0:* - udp6 0 0 :::5353 :::* - udp6 0 0 :::43439 :::* -
此处评论已关闭