<div id="post_detail">
netstat 命令详解
netstat命令是一个监控TCP/IP网络的非常有用的工具,它可以显示路由表、实际的网络连接以及每一个网络接口设备的状态信息。
语法选项
netstat [选项]
-a或--all:显示所有连线中的Socket;
-A<网络类型>或--<网络类型>:列出该网络类型连线中的相关地址;
-c或--continuous:持续列出网络状态;
-C或--cache:显示路由器配置的快取信息;
-e或--extend:显示网络其他相关信息;
-F或--fib:显示FIB;
-g或--groups:显示多重广播功能群组组员名单;
-h或--help:在线帮助;
-i或--interfaces:显示网络界面信息表单;
-l或--listening:显示监控中的服务器的Socket;
-M或--masquerade:显示伪装的网络连线;
-n或--numeric:直接使用ip地址,而不通过域名服务器;
-N或--netlink或--symbolic:显示网络硬件外围设备的符号连接名称;
-o或--timers:显示计时器;
-p或--programs:显示正在使用Socket的程序识别码和程序名称;
-r或--route:显示Routing Table;
-s或--statistice:显示网络工作信息统计表;
-t或--tcp:显示TCP传输协议的连线状况;
-u或--udp:显示UDP传输协议的连线状况;
-v或--verbose:显示指令执行过程;
-V或--version:显示版本信息;
-w或--raw:显示RAW传输协议的连线状况;
-x或--unix:此参数的效果和指定"-A unix"参数相同;
--ip或--inet:此参数的效果和指定"-A inet"参数相同。
例子
- 列出所有端口情况
[root@xiesshavip002 ~]# netstat -a # 列出所有端口
[root@xiesshavip002 ~]# netstat -at # 列出所有TCP端口
[root@xiesshavip002 ~]# netstat -au # 列出所有UDP端口
- 列出所有处于监听状态的 Sockets
[root@xiesshavip002 ~]# netstat -l # 只显示监听端口
[root@xiesshavip002 ~]# netstat -lt # 显示监听TCP端口
[root@xiesshavip002 ~]# netstat -lu # 显示监听UDP端口
[root@xiesshavip002 ~]# netstat -lx # 显示监听UNIX端口
- 显示每个协议的统计信息
[root@xiesshavip002 ~]# netstat -s # 显示所有端口的统计信息
[root@xiesshavip002 ~]# netstat -st # 显示所有TCP的统计信息
[root@xiesshavip002 ~]# netstat -su # 显示所有UDP的统计信息
- 显示 PID 和进程名称
[root@xiesshavip002 ~]# netstat -p
- 显示核心路由信息
[root@xiesshavip002 ~]# netstat -r
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
default gateway 0.0.0.0 UG 0 0 0 eth0
192.168.130.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
[root@xiesshavip002 ~]# netstat -rn # 显示数字格式,不查询主机名称
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.130.1 0.0.0.0 UG 0 0 0 eth0
192.168.130.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
[root@xiesshavip002 ~]#
- 查看端口和服务
[root@xiesshavip002 ~]# netstat -antp | grep ssh
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 734/sshd
tcp 0 52 192.168.130.20:22 119.129.118.189:58737 ESTABLISHED 1846/sshd: root@pts
tcp6 0 0 :::22 :::* LISTEN 734/sshd
[root@xiesshavip002 ~]# netstat -antp | grep 22
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 734/sshd
tcp 0 52 192.168.130.20:22 119.129.118.189:58737 ESTABLISHED 1846/sshd: root@pts
tcp6 0 0 :::22 :::* LISTEN 734/sshd
[root@xiesshavip002 ~]#
netstat --help
[root@xiesshavip002 ~]# netstat --help
usage: netstat [-vWeenNcCF] [<Af>] -r netstat {-V|--version|-h|--help}
netstat [-vWnNcaeol] [<Socket> ...]
netstat { [-vWeenNac] -I[<Iface>] | [-veenNac] -i | [-cnNe] -M | -s [-6tuw] } [delay]
-<span class="ruby">r, <span class="hljs-comment">--route display routing table</span>
-<span class="ruby"><span class="hljs-constant">I, <span class="hljs-comment">--interfaces=<</span><span class="hljs-constant"><span class="hljs-comment">Iface> display interface table </span><span class="hljs-keyword"><span class="hljs-comment">for <</span><span class="hljs-constant"><span class="hljs-comment">Iface></span>
-<span class="ruby">i, <span class="hljs-comment">--interfaces display interface table</span>
-<span class="ruby">g, <span class="hljs-comment">--groups display multicast group memberships</span>
-<span class="ruby">s, <span class="hljs-comment">--statistics display networking statistics (like </span><span class="hljs-constant"><span class="hljs-comment">SNMP)</span>
-<span class="ruby"><span class="hljs-constant">M, <span class="hljs-comment">--masquerade display masqueraded connections</span>
-<span class="ruby">v, <span class="hljs-comment">--verbose be verbose</span>
-<span class="ruby"><span class="hljs-constant">W, <span class="hljs-comment">--wide don</span><span class="hljs-string"><span class="hljs-comment">'t truncate IP addresses</span>
-<span class="ruby"><span class="hljs-string">n, <span class="hljs-comment">--numeric don't resolve names</span>
<span class="hljs-comment">-</span><span class="ruby"><span class="hljs-comment">-numeric-hosts don</span><span class="hljs-string"><span class="hljs-comment">'t resolve host names</span>
<span class="hljs-comment">-</span><span class="ruby"><span class="hljs-string"><span class="hljs-comment">-numeric-ports don't resolve port names</span>
<span class="hljs-comment">-</span><span class="ruby"><span class="hljs-comment">-numeric-users don</span><span class="hljs-string"><span class="hljs-comment">'t resolve user names</span>
-<span class="ruby"><span class="hljs-string">N, <span class="hljs-comment">--symbolic resolve hardware names</span>
-<span class="ruby"><span class="hljs-string">e, <span class="hljs-comment">--extend display other/more information</span>
-<span class="ruby"><span class="hljs-string">p, <span class="hljs-comment">--programs display PID/Program name for sockets</span>
-<span class="ruby"><span class="hljs-string">o, <span class="hljs-comment">--timers display timers</span>
-<span class="ruby"><span class="hljs-string">c, <span class="hljs-comment">--continuous continuous listing</span>
-<span class="ruby"><span class="hljs-string">l, <span class="hljs-comment">--listening display listening server sockets</span>
-<span class="ruby"><span class="hljs-string">a, <span class="hljs-comment">--all display all sockets (default: connected)</span>
-<span class="ruby"><span class="hljs-string">F, <span class="hljs-comment">--fib display Forwarding Information Base (default)</span>
-<span class="ruby"><span class="hljs-string">C, <span class="hljs-comment">--cache display routing cache instead of FIB</span>
-<span class="ruby"><span class="hljs-string">Z, <span class="hljs-comment">--context display SELinux security context for sockets</span>
<Socket>={-t|--tcp} {-u|--udp} {-U|--udplite} {-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)
[root@xiesshavip002 ~]#
Java源码学习:HashMap实现原理
mac 如何显示隐藏文件和.点开头文件?
mac 下 安装 mongodb 数据库
WPF 自定义TextBox
Appium+Python 安卓APP自动化测试:安装app和卸载app
Appium+Python 安卓APP自动化测试:环境搭建与基础操作
DataFrame利用函数或映射进行数据转换map
TypeError: drop_duplicates() got an unexpected keyword argument 'take_last'
DataFrame合并:合并重叠数据combine_first
Copyright © 2011-2022 走看看