netstat命令详解

<body> <a name="top"></a>
    <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"参数相同。

例子

  1. 列出所有端口情况
[root@xiesshavip002 ~]# netstat -a      # 列出所有端口
[root@xiesshavip002 ~]# netstat -at     # 列出所有TCP端口
[root@xiesshavip002 ~]# netstat -au     # 列出所有UDP端口
  1. 列出所有处于监听状态的 Sockets
[root@xiesshavip002 ~]# netstat -l   # 只显示监听端口
[root@xiesshavip002 ~]# netstat -lt  # 显示监听TCP端口
[root@xiesshavip002 ~]# netstat -lu  # 显示监听UDP端口
[root@xiesshavip002 ~]# netstat -lx  # 显示监听UNIX端口
  1. 显示每个协议的统计信息
[root@xiesshavip002 ~]# netstat -s     # 显示所有端口的统计信息
[root@xiesshavip002 ~]# netstat -st    # 显示所有TCP的统计信息
[root@xiesshavip002 ~]# netstat -su    # 显示所有UDP的统计信息
  1. 显示 PID 和进程名称
[root@xiesshavip002 ~]# netstat -p
  1. 显示核心路由信息
[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 ~]#
  1. 查看端口和服务
[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=&lt;</span><span class="hljs-constant"><span class="hljs-comment">Iface&gt; display interface table </span><span class="hljs-keyword"><span class="hljs-comment">for &lt;</span><span class="hljs-constant"><span class="hljs-comment">Iface&gt;</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 ~]#

分类: linux
1
0
« 上一篇:free 命令详解
» 下一篇:numpy 数组对象
	</div>
	<div class="postDesc">posted @ <span id="post-date">2017-03-25 23:26</span> <a href="https://www.cnblogs.com/xieshengsen/">xie仗剑天涯</a> 阅读(<span id="post_view_count">83168</span>) 评论(<span id="post_comment_count">0</span>)  <a href="https://i.cnblogs.com/EditPosts.aspx?postid=6618993" rel="nofollow">编辑</a> <a href="#" onclick="AddToWz(6618993);return false;">收藏</a></div>
</div>
<script type="text/javascript">var allowComments=true,cb_blogId=303867,cb_entryId=6618993,cb_blogApp=currentBlogApp,cb_blogUserGuid='ed291897-7830-e611-9fc1-ac853d9f53cc',cb_entryCreatedDate='2017/3/25 23:26:00';loadViewCount(cb_entryId);var cb_postType=1;var isMarkdown=false;</script>
</div><!--end: forFlow -->
</div><!--end: mainContent 主体内容容器-->

<div id="sideBar">
	<div id="sideBarMain">

公告

昵称:xie仗剑天涯
园龄:2年10个月
粉丝:16
关注:0
		<div id="blog-calendar" style=""><table id="blogCalendar" class="Cal" cellspacing="0" cellpadding="0" title="Calendar">
<tbody><tr><td colspan="7"><table class="CalTitle" cellspacing="0">
	<tbody><tr><td class="CalNextPrev"><a href="javascript:void(0);" onclick="loadBlogCalendar('2019/03/01');return false;">&lt;</a></td><td align="center">2019年4月</td><td class="CalNextPrev" align="right"><a href="javascript:void(0);" onclick="loadBlogCalendar('2019/05/01');return false;">&gt;</a></td></tr>
</tbody></table></td></tr><tr><th class="CalDayHeader" align="center" abbr="日" scope="col">日</th><th class="CalDayHeader" align="center" abbr="一" scope="col">一</th><th class="CalDayHeader" align="center" abbr="二" scope="col">二</th><th class="CalDayHeader" align="center" abbr="三" scope="col">三</th><th class="CalDayHeader" align="center" abbr="四" scope="col">四</th><th class="CalDayHeader" align="center" abbr="五" scope="col">五</th><th class="CalDayHeader" align="center" abbr="六" scope="col">六</th></tr><tr><td class="CalOtherMonthDay" align="center">31</td><td align="center">1</td><td align="center">2</td><td align="center">3</td><td align="center">4</td><td align="center">5</td><td class="CalWeekendDay" align="center">6</td></tr><tr><td class="CalWeekendDay" align="center">7</td><td align="center">8</td><td align="center">9</td><td align="center">10</td><td align="center">11</td><td align="center">12</td><td class="CalWeekendDay" align="center">13</td></tr><tr><td class="CalWeekendDay" align="center">14</td><td align="center">15</td><td align="center">16</td><td align="center">17</td><td align="center">18</td><td align="center">19</td><td class="CalWeekendDay" align="center">20</td></tr><tr><td class="CalWeekendDay" align="center">21</td><td align="center">22</td><td align="center">23</td><td align="center">24</td><td align="center">25</td><td class="CalTodayDay" align="center">26</td><td class="CalWeekendDay" align="center">27</td></tr><tr><td class="CalWeekendDay" align="center">28</td><td align="center">29</td><td align="center">30</td><td class="CalOtherMonthDay" align="center">1</td><td class="CalOtherMonthDay" align="center">2</td><td class="CalOtherMonthDay" align="center">3</td><td class="CalOtherMonthDay" align="center">4</td></tr><tr><td class="CalOtherMonthDay" align="center">5</td><td class="CalOtherMonthDay" align="center">6</td><td class="CalOtherMonthDay" align="center">7</td><td class="CalOtherMonthDay" align="center">8</td><td class="CalOtherMonthDay" align="center">9</td><td class="CalOtherMonthDay" align="center">10</td><td class="CalOtherMonthDay" align="center">11</td></tr>
		<div id="leftcontentcontainer">
			<div id="blog-sidecolumn"><div id="sidebar_search" class="sidebar-block">
	</div><!--end: sideBarMain -->
</div><!--end: sideBar 侧边栏容器 -->
<div class="clear"></div>
</div><!--end: main -->
<div class="clear"></div>
<div id="footer">

Copyright ©2019 xie仗剑天涯

</body>
posted @ 2019-04-26 16:03  张建路  阅读(339)  评论(0编辑  收藏  举报