Netstat 命令用于显示各种网络相关信息,如网络连接,路由表,接口状态 (Interface Statistics),masquerade 连接,多播成员 (Multicast Memberships) 等等。本文提供 10 个非常实用的 Netstat 命令实例。
1. 列出所有端口 (包括监听和未监听的)
列出所有端口 netstat -a
netstat -a | more [root@diancai1 ~]# netstat -a | more Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 *:5666 *:* LISTEN tcp 0 0 *:rsync *:* LISTEN tcp 0 0 diancai1.com:47537 115.239.224.60:60000 ESTABLISHED tcp 0 0 *:6080 *:* LISTEN tcp 0 0 localhost.localdomain:8035 *:* LISTEN tcp 0 0 *:8039 *:* LISTEN tcp 0 0 *:7080 *:* LISTEN tcp 0 0 *:rsync *:* LISTEN tcp 0 0 localhost.localdomain:8015 *:* LISTEN tcp 0 0 *:webcache *:* LISTEN tcp 0 0 *:personal-agent *:* LISTEN tcp 0 0 *:8019 *:* LISTEN tcp 0 0 *:ssh *:* LISTEN tcp 0 0 *:glrpc *:* LISTEN tcp 0 0 localhost.localdomain:8025 *:* LISTEN tcp 0 0 *:8029 *:* LISTEN tcp 0 0 *:esri_sde *:* LISTEN tcp 0 48 diancai1.com:ssh localhost:57648 ESTABLISHED tcp 0 0 diancai1.com:55624 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:53528 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:53529 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:53484 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:53483 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:53482 localhost:mysql ESTABLISHED
列出所有 tcp 端口 netstat -at
[root@diancai1 ~]# netstat -at Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 *:5666 *:* LISTEN tcp 0 0 *:rsync *:* LISTEN tcp 0 0 diancai1.com:47537 115.239.224.60:60000 ESTABLISHED tcp 0 0 *:6080 *:* LISTEN tcp 0 0 localhost.localdomain:8035 *:* LISTEN tcp 0 0 *:8039 *:* LISTEN tcp 0 0 *:7080 *:* LISTEN tcp 0 0 *:rsync *:* LISTEN tcp 0 0 localhost.localdomain:8015 *:* LISTEN tcp 0 0 *:webcache *:* LISTEN tcp 0 0 *:personal-agent *:* LISTEN tcp 0 0 *:8019 *:* LISTEN tcp 0 0 *:ssh *:* LISTEN tcp 0 0 *:glrpc *:* LISTEN tcp 0 0 localhost.localdomain:8025 *:* LISTEN tcp 0 0 *:8029 *:* LISTEN tcp 0 0 *:esri_sde *:* LISTEN tcp 0 512 diancai1.com:ssh localhost:57648 ESTABLISHED tcp 0 0 diancai1.com:6080 localhost:14048 TIME_WAIT tcp 0 0 diancai1.com:55624 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:53528 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:53529 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:53484 localhost:mysql ESTABLISHED
列出所有 udp 端口 netstat -au
[root@diancai1 ~]# netstat -au Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State udp 0 0 *:bootpc *:*
2.列出所有处于监听状态的 Sockets
只显示监听端口 netstat -l
[root@diancai1 ~]# netstat -l Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 *:5666 *:* LISTEN tcp 0 0 *:rsync *:* LISTEN tcp 0 0 *:6080 *:* LISTEN tcp 0 0 localhost.localdomain:8035 *:* LISTEN tcp 0 0 *:8039 *:* LISTEN tcp 0 0 *:7080 *:* LISTEN tcp 0 0 *:rsync *:* LISTEN tcp 0 0 localhost.localdomain:8015 *:* LISTEN tcp 0 0 *:webcache *:* LISTEN tcp 0 0 *:personal-agent *:* LISTEN tcp 0 0 *:8019 *:* LISTEN tcp 0 0 *:ssh *:* LISTEN tcp 0 0 *:glrpc *:* LISTEN tcp 0 0 localhost.localdomain:8025 *:* LISTEN tcp 0 0 *:8029 *:* LISTEN tcp 0 0 *:esri_sde *:* LISTEN udp 0 0 *:bootpc *:* Active UNIX domain sockets (only servers) Proto RefCnt Flags Type State I-Node Path unix 2 [ ACC ] STREAM LISTENING 8560 /tmp/.gdm_socket unix 2 [ ACC ] STREAM LISTENING 8589 /tmp/.X11-unix/X0
只列出所有监听 tcp 端口 netstat -lt
[root@diancai1 ~]# netstat -lt Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 *:5666 *:* LISTEN tcp 0 0 *:rsync *:* LISTEN tcp 0 0 *:6080 *:* LISTEN tcp 0 0 localhost.localdomain:8035 *:* LISTEN tcp 0 0 *:8039 *:* LISTEN tcp 0 0 *:7080 *:* LISTEN tcp 0 0 *:rsync *:* LISTEN tcp 0 0 localhost.localdomain:8015 *:* LISTEN tcp 0 0 *:webcache *:* LISTEN tcp 0 0 *:personal-agent *:* LISTEN tcp 0 0 *:8019 *:* LISTEN tcp 0 0 *:ssh *:* LISTEN tcp 0 0 *:glrpc *:* LISTEN tcp 0 0 localhost.localdomain:8025 *:* LISTEN tcp 0 0 *:8029 *:* LISTEN tcp 0 0 *:esri_sde *:* LISTEN
只列出所有监听 udp 端口 netstat -lu
[root@diancai1 ~]# netstat -lu Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State udp 0 0 *:bootpc *:*
只列出所有监听 UNIX 端口 netstat -lx
[root@diancai1 ~]# netstat -lx Active UNIX domain sockets (only servers) Proto RefCnt Flags Type State I-Node Path unix 2 [ ACC ] STREAM LISTENING 8560 /tmp/.gdm_socket unix 2 [ ACC ] STREAM LISTENING 8589 /tmp/.X11-unix/X0
3.显示每个协议的统计信息
显示所有端口的统计信息 netstat -s
[root@diancai1 ~]# netstat -s Ip: 1037044938 total packets received 121 with invalid addresses 0 forwarded 0 incoming packets discarded 1036911071 incoming packets delivered 2034453624 requests sent out 35 fragments failed Icmp: 12687916 ICMP messages received 8420682 input ICMP message failed. ICMP input histogram: destination unreachable: 3522 timeout in transit: 9777 echo requests: 12674586 echo replies: 31 4254071 ICMP messages sent 0 ICMP messages failed ICMP output histogram: destination unreachable: 52 echo request: 113 echo replies: 4253904 IcmpMsg: InType0: 31 InType3: 3522 InType8: 12674586 InType11: 9777 OutType0: 4253904 OutType1: 2 OutType3: 52 OutType8: 113 Tcp: 41289248 active connections openings 40566438 passive connection openings 1428278 failed connection attempts 180025 connection resets received 46 connections established 1023982902 segments received 907824976 segments send out 503660 segments retransmited 1 bad segments received. 4290136 resets sent Udp: 509280 packets received 24 packets to unknown port received. 0 packet receive errors 509934 packets sent TcpExt: 365906 invalid SYN cookies received 271 resets received for embryonic SYN_RECV sockets 55 packets pruned from receive queue because of socket buffer overrun 6316 ICMP packets dropped because they were out-of-window 26 ICMP packets dropped because socket was locked 39728257 TCP sockets finished time wait in fast timer 105112 time wait sockets recycled by time stamp 1 TCP sockets finished time wait in slow timer 45200334 delayed acks sent 192823 delayed acks further delayed because of locked socket Quick ack mode was activated 32969 times 1161215 times the listen queue of a socket overflowed 1161215 SYNs to LISTEN sockets ignored 454089419 packets directly queued to recvmsg prequeue. 2713155 packets directly received from backlog 310674262 packets directly received from prequeue 615928746 packets header predicted 235531 packets header predicted and directly queued to user 87820741 acknowledgments not containing data received 312798179 predicted acknowledgments 15896 times recovered from packet loss due to SACK data 5 bad SACKs received Detected reordering 1 times using FACK Detected reordering 1 times using SACK Detected reordering 11 times using time stamp 15 congestion windows fully recovered 29 congestion windows partially recovered using Hoe heuristic TCPDSACKUndo: 5227 7216 congestion windows recovered after partial ack 21724 TCP data loss events 1 timeouts after reno fast retransmit 2728 timeouts after SACK recovery 642 timeouts in loss state 40489 fast retransmits 313 forward retransmits 244256 retransmits in slow start 111404 other TCP timeouts 2596 sack retransmits failed 13159 packets collapsed in receive queue due to low socket buffer 55147 DSACKs sent for old packets 101 DSACKs sent for out of order packets 136949 DSACKs received 8 DSACKs for out of order packets received 2307330 connections reset due to unexpected data 5238 connections reset due to early user close 25640 connections aborted due to timeout IpExt: InMcastPkts: 8420682 InBcastPkts: 149203
显示 TCP 或 UDP 端口的统计信息 netstat -st 或 -su
[root@diancai1 ~]# netstat -st IcmpMsg: InType0: 31 InType3: 3522 InType8: 12674598 InType11: 9777 OutType0: 4253906 OutType1: 2 OutType3: 52 OutType8: 113 Tcp: 41289265 active connections openings 40566490 passive connection openings 1428280 failed connection attempts 180025 connection resets received 46 connections established 1023984103 segments received 907825655 segments send out 503664 segments retransmited 1 bad segments received. 4290138 resets sent TcpExt: 365906 invalid SYN cookies received 271 resets received for embryonic SYN_RECV sockets 55 packets pruned from receive queue because of socket buffer overrun 6316 ICMP packets dropped because they were out-of-window 26 ICMP packets dropped because socket was locked 39728270 TCP sockets finished time wait in fast timer 105112 time wait sockets recycled by time stamp 1 TCP sockets finished time wait in slow timer 45200362 delayed acks sent 192824 delayed acks further delayed because of locked socket Quick ack mode was activated 32970 times 1161215 times the listen queue of a socket overflowed 1161215 SYNs to LISTEN sockets ignored 454089687 packets directly queued to recvmsg prequeue. 2713159 packets directly received from backlog 310674514 packets directly received from prequeue 615929541 packets header predicted 235561 packets header predicted and directly queued to user 87820876 acknowledgments not containing data received 312798309 predicted acknowledgments 15896 times recovered from packet loss due to SACK data 5 bad SACKs received Detected reordering 1 times using FACK Detected reordering 1 times using SACK Detected reordering 11 times using time stamp 15 congestion windows fully recovered 29 congestion windows partially recovered using Hoe heuristic TCPDSACKUndo: 5227 7216 congestion windows recovered after partial ack 21724 TCP data loss events 1 timeouts after reno fast retransmit 2728 timeouts after SACK recovery 642 timeouts in loss state 40489 fast retransmits 313 forward retransmits 244256 retransmits in slow start 111406 other TCP timeouts 2596 sack retransmits failed 13159 packets collapsed in receive queue due to low socket buffer 55148 DSACKs sent for old packets 101 DSACKs sent for out of order packets 136949 DSACKs received 8 DSACKs for out of order packets received 2307330 connections reset due to unexpected data 5238 connections reset due to early user close 25640 connections aborted due to timeout IpExt: InMcastPkts: 8420692 InBcastPkts: 149203
4.在 netstat 输出中显示 PID 和进程名称 netstat -p
netstat -p 可以与其它开关一起使用,就可以添加 “PID/进程名称” 到 netstat 输出中,这样 debugging 的时候可以很方便的发现特定端口运行的程序。
[root@diancai1 ~]# netstat -pt Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 diancai1.com:glrpc localhost:47786 SYN_RECV - tcp 0 0 diancai1.com:47537 115.239.224.60:60000 ESTABLISHED 27294/dns tcp 0 288 diancai1.com:ssh localhost:57648 ESTABLISHED 21360/1 tcp 0 0 diancai1.com:webcache localhost:57867 ESTABLISHED 13212/java tcp 0 0 diancai1.com:55358 localhost:mysql ESTABLISHED 24044/java tcp 0 0 diancai1.com:55357 localhost:mysql ESTABLISHED 24044/java tcp 0 0 diancai1.com:55355 localhost:mysql ESTABLISHED 24356/java tcp 0 0 diancai1.com:55354 localhost:mysql ESTABLISHED 24356/java tcp 0 0 diancai1.com:55353 localhost:mysql ESTABLISHED 24044/java tcp 0 0 diancai1.com:55350 localhost:mysql ESTABLISHED 24044/java tcp 0 0 diancai1.com:55349 localhost:mysql ESTABLISHED 24044/java tcp 0 0 diancai1.com:55347 localhost:mysql ESTABLISHED 24356/java tcp 0 0 diancai1.com:55346 localhost:mysql ESTABLISHED 24356/java tcp 0 0 diancai1.com:55345 localhost:mysql ESTABLISHED 24356/java tcp 0 0 diancai1.com:55344 localhost:mysql ESTABLISHED 24356/java tcp 0 0 diancai1.com:55342 localhost:mysql ESTABLISHED 24356/java tcp 0 0 diancai1.com:55341 localhost:mysql ESTABLISHED 24356/java tcp 0 0 diancai1.com:55340 localhost:mysql ESTABLISHED 24356/java tcp 0 0 diancai1.com:55338 localhost:mysql ESTABLISHED 24044/java tcp 0 0 diancai1.com:55337 localhost:mysql ESTABLISHED 24044/java tcp 0 0 diancai1.com:55336 localhost:mysql ESTABLISHED 24356/java tcp 0 0 diancai1.com:55333 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:55332 localhost:mysql TIME_WAIT - tcp 0 0 diancai1.com:55330 localhost:mysql TIME_WAIT - tcp 0 0 diancai1.com:55329 localhost:mysql TIME_WAIT - tcp 0 0 diancai1.com:55328 localhost:mysql TIME_WAIT - tcp 0 0 diancai1.com:55323 localhost:mysql TIME_WAIT - tcp 0 0 diancai1.com:55322 localhost:mysql TIME_WAIT - tcp 0 0 diancai1.com:55321 localhost:mysql TIME_WAIT - tcp 0 0 diancai1.com:55318 localhost:mysql TIME_WAIT - tcp 0 0 diancai1.com:55317 localhost:mysql TIME_WAIT - tcp 0 0 diancai1.com:55315 localhost:mysql TIME_WAIT - tcp 0 0 diancai1.com:55313 localhost:mysql TIME_WAIT - tcp 0 0 diancai1.com:55312 localhost:mysql TIME_WAIT - tcp 0 0 diancai1.com:55311 localhost:mysql TIME_WAIT - tcp 0 0 diancai1.com:55306 localhost:mysql TIME_WAIT - tcp 0 0 diancai1.com:55361 localhost:mysql ESTABLISHED 24044/java tcp 0 0 diancai1.com:55360 localhost:mysql ESTABLISHED 24044/java tcp 0 0 diancai1.com:53528 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:55289 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:55290 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:55254 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:55255 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:55256 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:55258 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:55259 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:62676 localhost:11211 ESTABLISHED 13212/java tcp 0 0 diancai1.com:62688 localhost:11211 ESTABLISHED 13212/java tcp 0 0 diancai1.com:42154 localhost:mysql ESTABLISHED 13574/java tcp 0 0 diancai1.com:45857 localhost:mysql ESTABLISHED 13574/java tcp 0 0 diancai1.com:40218 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:40217 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:40177 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:40176 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:40175 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:27391 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:apm-link localhost:mysql ESTABLISHED 13574/java tcp 0 0 diancai1.com:32482 localhost:mysql ESTABLISHED 13574/java tcp 0 0 diancai1.com:esri_sde localhost:34142 ESTABLISHED 13574/java tcp 0 0 diancai1.com:32055 localhost:11211 ESTABLISHED 24356/java tcp 0 0 diancai1.com:jerand-lm localhost:mysql ESTABLISHED 13574/java
5. 在 netstat 输出中不显示主机,端口和用户名 (host, port or user)
当你不想让主机,端口和用户名显示,使用 netstat -n。将会使用数字代替那些名称。同样可以加速输出,因为不用进行比对查询。
[root@diancai1 ~]# netstat -an Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN tcp 0 0 172.16.2.2:9080 172.16.1.12:48674 SYN_RECV tcp 0 0 172.16.2.2:47537 115.239.224.60:60000 ESTABLISHED tcp 0 0 :::6080 :::* LISTEN tcp 0 0 ::ffff:127.0.0.1:8035 :::* LISTEN tcp 0 0 :::8039 :::* LISTEN tcp 0 0 :::7080 :::* LISTEN tcp 0 0 :::873 :::* LISTEN tcp 0 0 ::ffff:127.0.0.1:8015 :::* LISTEN tcp 0 0 :::8080 :::* LISTEN tcp 0 0 :::5555 :::* LISTEN tcp 0 0 :::8019 :::* LISTEN tcp 0 0 :::22 :::* LISTEN tcp 0 0 :::9080 :::* LISTEN tcp 0 0 ::ffff:127.0.0.1:8025 :::* LISTEN tcp 0 0 :::8029 :::* LISTEN tcp 0 0 :::5151 :::* LISTEN tcp 0 640 ::ffff:172.16.2.2:22 ::ffff:172.16.17.11:57648 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:55358 ::ffff:172.16.3.2:3306 TIME_WAIT tcp 0 0 ::ffff:172.16.2.2:55355 ::ffff:172.16.3.2:3306 TIME_WAIT tcp 0 0 ::ffff:172.16.2.2:55354 ::ffff:172.16.3.2:3306 TIME_WAIT tcp 0 0 ::ffff:172.16.2.2:55351 ::ffff:172.16.3.2:3306 TIME_WAIT tcp 0 0 ::ffff:172.16.2.2:55349 ::ffff:172.16.3.2:3306 TIME_WAIT tcp 0 0 ::ffff:172.16.2.2:55347 ::ffff:172.16.3.2:3306 TIME_WAIT tcp 0 0 ::ffff:172.16.2.2:55346 ::ffff:172.16.3.2:3306 TIME_WAIT tcp 0 0 ::ffff:172.16.2.2:55345 ::ffff:172.16.3.2:3306 TIME_WAIT tcp 0 0 ::ffff:172.16.2.2:55344 ::ffff:172.16.3.2:3306 TIME_WAIT tcp 0 0 ::ffff:172.16.2.2:55333 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:55366 ::ffff:172.16.3.2:3306 TIME_WAIT tcp 0 0 ::ffff:172.16.2.2:55365 ::ffff:172.16.3.2:3306 TIME_WAIT tcp 0 0 ::ffff:172.16.2.2:55364 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:55361 ::ffff:172.16.3.2:3306 TIME_WAIT tcp 0 0 ::ffff:172.16.2.2:55360 ::ffff:172.16.3.2:3306 TIME_WAIT tcp 0 0 ::ffff:172.16.2.2:56634 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:56632 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:56633 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:56638 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:56636 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:56637 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:56626 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:56627 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:56625 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:56631 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:56619 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:56620 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:56621 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:56648 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:56642 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:56640 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:56641 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:56647 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:56644 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:53528 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:55289 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:55290 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:55254 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:55255 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:55256 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:55258 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:55259 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:62676 ::ffff:172.16.3.2:11211 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:62688 ::ffff:172.16.3.2:11211 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:42154 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:45857 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:40218 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:40217 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:40177 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:40176 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:40175 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:27391 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:32483 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:32482 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:8080 ::ffff:172.16.1.12:52664 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:6080 ::ffff:172.16.1.12:51377 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:5151 ::ffff:172.16.2.253:34142 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:32055 ::ffff:172.16.3.2:11211 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:7080 ::ffff:172.16.1.12:53420 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:1810 ::ffff:172.16.3.2:3306 ESTABLISHED tcp 0 0 ::ffff:172.16.2.2:5151 ::ffff:172.16.1.12:38644 ESTABLISHED udp 0 0 0.0.0.0:68 0.0.0.0:* Active UNIX domain sockets (servers and established) Proto RefCnt Flags Type State I-Node Path unix 2 [ ACC ] STREAM LISTENING 8560 /tmp/.gdm_socket unix 2 [ ] DGRAM 3236 @/org/kernel/udev/udevd unix 2 [ ACC ] STREAM LISTENING 8589 /tmp/.X11-unix/X0 unix 9 [ ] DGRAM 8177 /dev/log unix 2 [ ] DGRAM 263514767 unix 2 [ ] STREAM CONNECTED 260618162 unix 2 [ ] STREAM CONNECTED 253364545 unix 2 [ ] DGRAM 10021 unix 3 [ ] STREAM CONNECTED 8700 /tmp/.X11-unix/X0 unix 3 [ ] STREAM CONNECTED 8699 unix 3 [ ] STREAM CONNECTED 8695 /tmp/.X11-unix/X0 unix 3 [ ] STREAM CONNECTED 8694 unix 3 [ ] STREAM CONNECTED 8674 /tmp/.X11-unix/X0 unix 3 [ ] STREAM CONNECTED 8593 unix 2 [ ] DGRAM 8583 unix 2 [ ] DGRAM 8296 unix 2 [ ] DGRAM 8273 unix 2 [ ] DGRAM 8255 unix 2 [ ] DGRAM 8185
6.持续输出 netstat 信息
netstat 将每隔一秒输出网络信息。
netstat -c
7.显示系统不支持的地址族 (Address Families)
[root@diancai1 ~]# netstat --verbose Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 diancai1.com:47537 115.239.224.60:60000 ESTABLISHED tcp 0 256 diancai1.com:ssh localhost:57648 ESTABLISHED tcp 0 0 diancai1.com:55333 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:56698 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:56696 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:56697 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:56702 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:56703 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:56700 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:56701 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:56690 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:56691 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:56688 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:56689 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:56692 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:56682 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:56683 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:56680 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:56686 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:56687 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:56684 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:56673 localhost:mysql TIME_WAIT tcp 0 0 diancai1.com:56678 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:56679 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:56676 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:56677 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:56666 localhost:mysql TIME_WAIT tcp 0 0 diancai1.com:56667 localhost:mysql TIME_WAIT tcp 0 0 diancai1.com:56670 localhost:mysql TIME_WAIT tcp 0 0 diancai1.com:56671 localhost:mysql TIME_WAIT tcp 0 0 diancai1.com:56668 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:56669 localhost:mysql TIME_WAIT tcp 0 0 diancai1.com:56659 localhost:mysql TIME_WAIT tcp 0 0 diancai1.com:56661 localhost:mysql TIME_WAIT tcp 0 0 diancai1.com:56648 localhost:mysql TIME_WAIT tcp 0 0 diancai1.com:56649 localhost:mysql TIME_WAIT tcp 0 0 diancai1.com:56654 localhost:mysql TIME_WAIT tcp 0 0 diancai1.com:56655 localhost:mysql TIME_WAIT tcp 0 0 diancai1.com:56652 localhost:mysql TIME_WAIT tcp 0 0 diancai1.com:56647 localhost:mysql TIME_WAIT tcp 0 0 diancai1.com:53528 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:55289 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:55290 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:55254 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:55255 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:55256 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:55258 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:55259 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:62676 localhost:11211 ESTABLISHED tcp 0 0 diancai1.com:62688 localhost:11211 ESTABLISHED tcp 0 0 diancai1.com:42154 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:45857 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:40218 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:40217 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:40177 localhost:mysql TIME_WAIT tcp 0 0 diancai1.com:40176 localhost:mysql TIME_WAIT tcp 0 0 diancai1.com:40175 localhost:mysql TIME_WAIT tcp 0 0 diancai1.com:27391 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:apm-link localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:32482 localhost:mysql ESTABLISHED tcp 0 0 diancai1.com:esri_sde localhost:34142 ESTABLISHED tcp 0 0 diancai1.com:32055 localhost:11211 ESTABLISHED tcp 0 0 diancai1.com:jerand-lm localhost:mysql ESTABLISHED netstat: no support for `AF INET (sctp)' on this system. Active UNIX domain sockets (w/o servers) Proto RefCnt Flags Type State I-Node Path unix 2 [ ] DGRAM 3236 @/org/kernel/udev/udevd unix 9 [ ] DGRAM 8177 /dev/log unix 2 [ ] DGRAM 263514767 unix 2 [ ] STREAM CONNECTED 260618162 unix 2 [ ] STREAM CONNECTED 253364545 unix 2 [ ] DGRAM 10021 unix 3 [ ] STREAM CONNECTED 8700 /tmp/.X11-unix/X0 unix 3 [ ] STREAM CONNECTED 8699 unix 3 [ ] STREAM CONNECTED 8695 /tmp/.X11-unix/X0 unix 3 [ ] STREAM CONNECTED 8694 unix 3 [ ] STREAM CONNECTED 8674 /tmp/.X11-unix/X0 unix 3 [ ] STREAM CONNECTED 8593 unix 2 [ ] DGRAM 8583 unix 2 [ ] DGRAM 8296 unix 2 [ ] DGRAM 8273 unix 2 [ ] DGRAM 8255 unix 2 [ ] DGRAM 8185 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.
8.显示核心路由信息 netstat -r
[root@diancai1 ~]# netstat -r Kernel IP routing table Destination Gateway Genmask Flags MSS Window irtt Iface 172.16.2.0 * 255.255.255.128 U 0 0 0 eth0 169.254.95.0 * 255.255.255.0 U 0 0 0 usb0 169.254.0.0 * 255.255.0.0 U 0 0 0 usb0 default localhost 0.0.0.0 UG 0 0 0 eth0
注意:使用 netstat -rn 显示数字格式,不查询主机名称。
9.找出程序运行的端口
并不是所有的进程都能找到,没有权限的会不显示,使用 root 权限查看所有的信息。
[root@diancai1 ~]# netstat -ap | grep java tcp 0 0 *:6080 *:* LISTEN 24356/java tcp 0 0 localhost.localdomain:8035 *:* LISTEN 13212/java tcp 0 0 *:8039 *:* LISTEN 13212/java tcp 0 0 *:7080 *:* LISTEN 24044/java tcp 0 0 localhost.localdomain:8015 *:* LISTEN 24356/java tcp 0 0 *:webcache *:* LISTEN 13212/java tcp 0 0 *:personal-agent *:* LISTEN 13574/java tcp 0 0 *:8019 *:* LISTEN 24356/java tcp 0 0 localhost.localdomain:8025 *:* LISTEN 24044/java tcp 0 0 *:8029 *:* LISTEN 24044/java tcp 0 0 *:esri_sde *:* LISTEN 13574/java tcp 0 0 diancai1.com:55333 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:56682 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:56683 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:56684 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:56760 localhost:mysql ESTABLISHED 24044/java tcp 0 0 diancai1.com:56754 localhost:mysql ESTABLISHED 24356/java tcp 0 0 diancai1.com:56752 localhost:mysql ESTABLISHED 24044/java tcp 0 0 diancai1.com:56753 localhost:mysql ESTABLISHED 24356/java tcp 0 0 diancai1.com:56759 localhost:mysql ESTABLISHED 24044/java tcp 0 0 diancai1.com:56756 localhost:mysql ESTABLISHED 24044/java tcp 0 0 diancai1.com:56757 localhost:mysql ESTABLISHED 24044/java tcp 0 0 diancai1.com:56746 localhost:mysql ESTABLISHED 24356/java tcp 0 0 diancai1.com:56747 localhost:mysql ESTABLISHED 24356/java tcp 0 0 diancai1.com:56744 localhost:mysql ESTABLISHED 24356/java tcp 0 0 diancai1.com:56745 localhost:mysql ESTABLISHED 24356/java tcp 0 0 diancai1.com:56751 localhost:mysql ESTABLISHED 24044/java tcp 0 0 diancai1.com:56748 localhost:mysql ESTABLISHED 24044/java tcp 0 0 diancai1.com:56749 localhost:mysql ESTABLISHED 24044/java tcp 0 0 diancai1.com:56738 localhost:mysql ESTABLISHED 24044/java tcp 0 0 diancai1.com:56737 localhost:mysql ESTABLISHED 24044/java tcp 0 0 diancai1.com:56743 localhost:mysql ESTABLISHED 24356/java tcp 0 0 diancai1.com:56740 localhost:mysql ESTABLISHED 24356/java tcp 0 0 diancai1.com:56741 localhost:mysql ESTABLISHED 24356/java tcp 0 0 diancai1.com:56732 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:56733 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:56725 localhost:mysql ESTABLISHED 24356/java tcp 0 0 diancai1.com:55289 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:55290 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:55254 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:55255 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:55256 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:55258 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:55259 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:62676 localhost:11211 ESTABLISHED 13212/java tcp 0 0 diancai1.com:62688 localhost:11211 ESTABLISHED 13212/java tcp 0 0 diancai1.com:42154 localhost:mysql ESTABLISHED 13574/java tcp 0 0 diancai1.com:45857 localhost:mysql ESTABLISHED 13574/java tcp 0 0 diancai1.com:40218 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:40217 localhost:mysql ESTABLISHED 13212/java tcp 0 0 diancai1.com:apm-link localhost:mysql ESTABLISHED 13574/java tcp 0 0 diancai1.com:32482 localhost:mysql ESTABLISHED 13574/java tcp 0 0 diancai1.com:esri_sde localhost:34142 ESTABLISHED 13574/java tcp 0 0 diancai1.com:32055 localhost:11211 ESTABLISHED 24356/java tcp 0 0 diancai1.com:jerand-lm localhost:mysql ESTABLISHED 13574/java unix 2 [ ] STREAM CONNECTED 260618162 13574/java unix 2 [ ] STREAM CONNECTED 253364545 24356/java
找出运行在指定端口的进程
[root@diancai1 ~]# netstat -an | grep 80 tcp 0 0 :::6080 :::* LISTEN tcp 0 0 ::ffff:127.0.0.1:8035 :::* LISTEN tcp 0 0 :::8039 :::* LISTEN tcp 0 0 :::7080 :::* LISTEN tcp 0 0 ::ffff:127.0.0.1:8015 :::* LISTEN tcp 0 0 :::8080 :::* LISTEN tcp 0 0 :::8019 :::* LISTEN tcp 0 0 :::9080 :::* LISTEN tcp 0 0 ::ffff:127.0.0.1:8025 :::* LISTEN tcp 0 0 :::8029 :::* LISTEN tcp 0 0 ::ffff:172.16.2.2:12180 ::ffff:172.16.3.2:3306 ESTABLISHED
10.显示网络接口列表
[root@diancai1 ~]# netstat -i Kernel Interface table Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg eth0 1500 0 1025699644 0 0 0 2012041617 0 0 0 BMRU lo 16436 0 5058346 0 0 0 5058346 0 0 0 LRU usb0 1500 0 17137488 0 0 0 8583040 0 0 0 BMRU
显示详细信息,类似 ifconfig 使用 netstat -ie:
[root@diancai1 ~]# netstat -ie Kernel Interface table eth0 Link encap:Ethernet HWaddr 5C:F3:FC:B9:84:B0 inet addr:172.16.2.2 Bcast:172.16.2.127 Mask:255.255.255.128 inet6 addr: fe80::5ef3:fcff:feb9:84b0/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1025700373 errors:0 dropped:0 overruns:0 frame:0 TX packets:2012042214 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:561572086964 (523.0 GiB) TX bytes:236444264469 (220.2 GiB) Interrupt:169 Memory:96000000-96012800 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:5058346 errors:0 dropped:0 overruns:0 frame:0 TX packets:5058346 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1615298995 (1.5 GiB) TX bytes:1615298995 (1.5 GiB) usb0 Link encap:Ethernet HWaddr 5E:F3:FC:BF:86:43 inet addr:169.254.95.120 Bcast:169.254.95.255 Mask:255.255.255.0 inet6 addr: fe80::5cf3:fcff:febf:8643/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:17137508 errors:0 dropped:0 overruns:0 frame:0 TX packets:8583050 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1157465313 (1.0 GiB) TX bytes:408367136 (389.4 MiB)
相关推荐
Linux netstat命令详解 Linux netstat命令是一种非常有用的网络命令,用于显示各种网络相关信息,如网络连接、路由表、接口状态、masquerade连接、多播成员等等。本文将详细介绍netstat命令的使用和输出结果的解释...
netstat 命令是 Linux 系统中一个非常有用的网络命令,用于显示与 IP、TCP、UDP 和 ICMP 协议相关的统计数据,一般用于检验本机各端口的网络连接情况。下面是对 netstat 命令的详细使用教程。 netstat 命令格式 ...
在深入探讨Linux中netstat命令的丰富功能与应用之前,我们先简要回顾一下netstat的基本定义:netstat是Linux系统中一个强大的网络诊断工具,主要用于显示与IP、TCP、UDP和ICMP协议相关的统计数据,尤其适用于监测和...
下面列举了一些常用的Netstat命令实例: 1. **列出所有端口(包括监听和未监听的)** ```bash netstat -a ``` 此命令会显示所有TCP和UDP的连接信息,包括监听端口。 2. **列出所有TCP端口** ```bash netstat...
### 实用命令实例 - **列出所有端口**: ```bash netstat -a ``` - **只列出TCP端口**: ```bash netstat -at ``` - **只列出UDP端口**: ```bash netstat -au ``` - **查看监听状态的连接**: ```...
### Linux常用命令加实例大全:深入解析与应用 在IT领域,尤其是系统管理和软件开发中,Linux操作系统以其稳定性、安全性和灵活性而著称。对于初学者乃至经验丰富的工程师而言,熟练掌握一系列基本到高级的Linux...
### 实用命令实例 1. 列出所有端口(包括监听和未监听的): ```bash netstat -a ``` 2. 只显示监听状态的TCP连接: ```bash netstat -lt ``` 3. 显示所有连接并以数字形式显示地址: ```bash netstat -...
"Linux常用命令集详解大全CHM"是一个非常实用的学习资源,旨在帮助用户快速理解和掌握Linux命令行的基本操作。CHM(Compiled HTML Help)文件是一种常见的电子文档格式,通常用于技术文档的存储,方便用户离线查阅。...
Netstat命令是Linux系统中一个非常重要的网络诊断工具,它能够提供关于网络连接、路由表、接口状态等网络相关信息的实时查看。在本文中,我们将深入探讨netstat命令的一些常见用法,帮助用户更好地理解和利用这个...
在这个`Linux命令大全(修改版).chm`文件中,我们可以期待找到关于Linux命令的详细解释和示例。 1. **目录结构**: `chm`文件通常有一个结构化的目录,用户可以通过这个目录快速定位到特定的命令。在Linux命令大全...
以下是对“Linux基本命令及实例”文章中的关键知识点进行的深入解析,旨在帮助读者理解并熟练运用这些命令。 #### 1. 目录操作命令:cd, ls, mkdir, rmdir - **cd (Change Directory)**:用于改变当前工作目录。...
在提供的部分内容中,包含了丰富的Linux命令实例,以下是对应的知识点: 1. 用户管理命令:sudosu用于个人用户切换到root用户,对于需要执行特殊权限操作的用户来说,这是个非常重要的命令。 2. 文件和目录操作...
根据给定的文件信息,以下是对“Linux 60个网络命令”的详细解析与扩展,主要聚焦于ifconfig、iproute2(ip命令)以及ping命令的深入理解与应用。 ### ifconfig:网络接口配置 #### 命令格式: ``` ifconfig ...
本文将深入探讨几个常用且实用的网络命令,通过实例帮助你更好地理解和应用它们。 1. **ping**: `ping` 命令是最基础的网络连通性测试工具,它使用ICMP协议发送回显请求到目标主机,并接收响应。例如,`ping ...
Linux命令是操作系统的核心组成部分,用于执行各种任务,如...每个命令都有其特定的用途和选项,熟练掌握这些命令对于Linux系统的日常管理和维护至关重要。通过实践和不断的练习,你可以更高效地在Linux环境中工作。