netstat命令使用

匿名 (未验证) 提交于 2019-12-03 00:14:01

Ŀ¼

Netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接,多播成员 (Multicast Memberships) 等等。

CentOS7:

yum install net-tools -y
usage: netstat [-vWeenNcCF] [<Af>] -r         netstat {-V|--version|-h|--help}        netstat [-vWnNcaeol] [<Socket> ...]        netstat { [-vWeenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s [-6tuw] } [delay]          -r, --route              display routing table         -I, --interfaces=<Iface> display interface table for <Iface>         -i, --interfaces         display interface table         -g, --groups             display multicast group memberships         -s, --statistics         display networking statistics (like SNMP)         -M, --masquerade         display masqueraded connections          -v, --verbose            be verbose         -W, --wide               don't truncate IP addresses         -n, --numeric            don't resolve names         --numeric-hosts          don't resolve host names         --numeric-ports          don't resolve port names         --numeric-users          don't resolve user names         -N, --symbolic           resolve hardware names         -e, --extend             display other/more information         -p, --programs           display PID/Program name for sockets         -o, --timers             display timers         -c, --continuous         continuous listing          -l, --listening          display listening server sockets         -a, --all                display all sockets (default: connected)         -F, --fib                display Forwarding Information Base (default)         -C, --cache              display routing cache instead of FIB         -Z, --context            display SELinux security context for sockets    <Socket>={-t|--tcp} {-u|--udp} {-U|--udplite} {-S|--sctp} {-w|--raw}            {-x|--unix} --ax25 --ipx --netrom   <AF>=Use '-6|-4' or '-A <af>' or '--<af>'; default: inet   List of possible address families (which support routing):     inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25)     netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP)     x25 (CCITT X.25)
# netstat -a | more
# netstat -at
# netstat -au
 netstat -l
# netstat -lt
# netstat -lx
# netstat -s
# netstat -st  # netstat -su

netstat -p 可以与其它开关一起使用,就可以添加 “PID/进程名称” 到 netstat 输出中,这样 debugging 的时候可以很方便的发现特定端口运行的程序。

# netstat -pt
# 当你不想让主机,端口和用户名显示,使用 netstat -n。将会使用数字代替那些名称。 #同样可以加速输出,因为不用进行比对查询。 # netstat -an  # 如果只是不想让这三个名称中的一个被显示,使用以下命令 # netsat -a --numeric-ports # netsat -a --numeric-hosts # netsat -a --numeric-users
#netstat 将每隔一秒输出网络信息。 # netstat -c
netstat --verbose  #在输出的末尾,会有如下的信息 netstat: no support for `AF IPX' on this system. netstat: no support for `AF AX25' on this system. netstat: no support for `AF X25' on this system. netstat: no support for `AF NETROM' on this system.
# netstat -r # netstat -rn  不显示主机名称
#并不是所有的进程都能找到,没有权限的会不显示,使用 root 权限查看所有的信息。 # netstat -ap | grep ssh  #找出运行在指定端口的进程 # netstat -an | grep ':80'
# netstat -i #  netstat -ie  //显示详细信息
# netstat -nat | grep "192.168.1.15:22" |awk '{print $5}'|awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -20
# netstat -nat |awk '{print $6}' |sort|uniq -c
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!