netstat 和 lsof 查看网络状态
netstat
和lsof
都是linux下的工具,可以用于查看系统的网络状态。
netstat
netstat可以打印 网络连接,路由表,接口统计数据,还有多播和masquerade连接相关的东西(不熟悉,就不写了)。
大体上的用法如下
$netstat [-o] [-p] [-v] [-c] [-t] [-u] [-w] [-l] [-a] [-n] [-N] [address_family_options]
[--numeric-hosts] [--numeric-ports] [--numeric-users] [--extend|-e[--extend|-e]]
$netstat {-r} [-v] [-n] [-c] [address_family_options]
[--extend|-e[--extend|-e]] [--numeric-hosts] [--numeric-ports] [--numeric-users]
$netstat {-i} [-a] [-v] [-p] [-n] [-c]
[--numeric-hosts] [--numeric-ports] [--numeric-users] [--extend|-e[--extend|-e]]
$netstat {-s} [-t] [-u] [-w]
################### 下面的暂时用不到,暂时不了解 ###################
netstat {-g} [--numeric|-n] [--numeric-hosts] [--numeric-ports] [--numeric-users] [--continuous|-c]
netstat {-M} [--extend|-e] [--numeric|-n] [--numeric-hosts] [--numeric-ports] [--numeric-users] [--continuous|-c]
netstat {--version|-V}
netstat {--help|-h}
首个参数表示功能,比如{-r}
是路由表相关,{-i}
是接口相关(也就是lo,eth0这些),{-s}
是统计数据相关,第一种用法没有指定功能,默认打印出socket列表,如果没有指定协议族,就会都打印。
address_family_options
表示协议族,可以是[-4] [-6] [--protocol={inet,unix,ipx,ax25,netrom,ddp}[,...]] [--unix|-x] [--inet|--ip] [--ax25] [--ipx] [--netrom] [--ddp]中的各种组合。
-v
罗嗦模式
-W
(不了解)
-n
不要解析地址、端口、用户等名称,这样打印会快很多
--numeric-hosts
包含在-n
中
--numeric-ports
包含在-n
中
--numeric-users
包含在-n
中
-A family
指定协议族(也许叫低层协议更合适?),family
可以是 inet, unix, ipx, ax25, netrom, ddp等,组合时用逗号隔开即可,效果同--inet
,--unix(即-x)
,--ipx
,--ax25
,--netrom
,--ddp
一样,其中inet就是raw、tcp、udp的组合。
-c
连续打印
-e
打印更多信息(列)
-ee
打印更更多信息(列)
-o
Include information related to networking timers
-p
显示pid和程序名
-l
只显示listening的socket
-a
显示listening和非listening的socket
-F
Print routing information from the FIB. (这是默认的参数,可不用)
-C
Print routing information from the route cache. (route cache 不了解)
-s
统计数据,用来观察网络情况,主要是IP,ICMP,TCP,UDP的收发情况
举一些例子
$netstat -n -l -4
查看本机在监听哪些端口,指明ipv4协议,不会显示"活跃的UNIX域套接字"$netstat -n -l -x
查看本机有哪些活跃的UNIX域套接字在监听着,也是不解析名字$netstat -n -4 -p
打印连接所属的程序和pid$netstat -ree
详细打印路由表信息$netstat -sw
简单打印IP和ICMP的统计数据
下面是更详细的一些信息
$netstat -r
显示路由表,Flag的意思如下
A Receive all multicast at this interface.
B OK broadcast.
D Debugging ON.
M Promiscuous Mode.
O No ARP at this interface.
P P2P connection at this interface.
R Interface is running.
U Interface is up.
G Not a direct entry.
- Internet连接套接字的两个列的意义
Recv-Q -- The count of bytes not copied by the user program connected to this socket.
Send-Q -- The count of bytes not acknowledged by the remote host.
- Internet连接套接字的
STATE
列是如下之一(也就是tcp的3次握手和4次挥手的状态)
ESTABLISHED
SYN_SENT
SYN_RECV
FIN_WAIT1
FIN_WAIT2
TIME_WAIT
CLOSE
CLOSE_WAIT
LAST_ACK
LISTEN
CLOSING
UNKNOWN
- UNIX域套接字的
STATE
列信息的意义
FREE -- The socket is not allocated
LISTENING -- The socket is listening for a connection request. Such sockets are only included in the output if you specify the --listening (-l) or --all (-a) option.
CONNECTING -- The socket is about to establish a connection.
CONNECTED -- The socket is connected.
DISCONNECTING -- The socket is disconnecting.
(empty) -- The socket is not connected to another one.
UNKNOWN -- This state should never happen.
- UNIX域套接字的
type
列信息的意义
SOCK_DGRAM -- The socket is used in Datagram (connectionless) mode.
SOCK_STREAM -- This is a stream (connection) socket.
SOCK_RAW -- The socket is used as a raw socket.
SOCK_RDM -- This one serves reliably-delivered messages.
SOCK_SEQPACKET -- This is a sequential packet socket.
SOCK_PACKET -- Raw interface access socket.
UNKNOWN -- Who ever knows what the future will bring us - just fill in here :-)
UNIX域套接字的
RefCnt
列信息的意义
RefCnt
-- 引用次数 (如 attached processes via this socket).`netstat
其实就是查看下面这些文件的信息再整理打印出来
/etc/services -- The services translation file
/proc -- Mount point for the proc filesystem, which gives access to kernel status information via the following files.
/proc/net/dev -- device information
/proc/net/raw -- raw socket information
/proc/net/tcp -- TCP socket information
/proc/net/udp -- UDP socket information
/proc/net/igmp -- IGMP multicast information
/proc/net/unix -- Unix domain socket information
/proc/net/ipx -- IPX socket information
/proc/net/ax25 -- AX25 socket information
/proc/net/appletalk -- DDP (appletalk) socket information
/proc/net/nr -- NET/ROM socket information
/proc/net/route -- IP routing information
/proc/net/ax25_route -- AX25 routing information
/proc/net/ipx_route -- IPX routing information
/proc/net/nr_nodes -- NET/ROM nodelist
/proc/net/nr_neigh -- NET/ROM neighbours
/proc/net/ip_masquerade -- masqueraded connections
/proc/net/snmp -- statistics
lsof
没时间了,待续~
netstat 和 lsof 查看网络状态的更多相关文章
- 在Linux下用netstat查看网络状态、端口状态
在Linux下用netstat查看网络状态.端口状态 在linux一般使用netstat 来查看系统端口使用情况步. netstat命令是一个监控TCP/IP网络的非常有用的工具,它可以显示路由表.实 ...
- Linux下用netstat查看网络状态、端口状态(转)
转:http://blog.csdn.net/guodongdongnumber1/article/details/11383019 在linux一般使用netstat 来查看系统端口使用情况步. ...
- 用netstat查看网络状态详解
--用netstat查看网络状态详解 -----------------------------2014/06/11 一.Linux服务器上11种网络连接状态: ...
- Linux下用netstat查看网络状态、端口状态
在linux一般使用netstat 来查看系统端口使用情况步. netstat命令是一个监控TCP/IP网络的非常有用的工具,它可以显示路由表.实际的网络连接以及每一个网络接口设备的 netstat命 ...
- Linux使用netstat查看网络状态
查看本机的网络状态.使用netstat查看网络状态.显示系统端口使用情况.UDP类型的端口.TCP类型的端口.只显示所有监听端口.只显示所有监听tcp端口. 命令使用举例 命令 说明 netstat ...
- centos7如何查看网络状态?
参考https://www.jb51.net/os/RedHat/520187.html 查看网络状态: lsof -Pnl +M -i4 显示ipv4服务及监听端情况 netstat -anp 所有 ...
- CentOS下查看网络状态
查看网络状态:lsof -Pnl +M -i4 显示ipv4服务及监听端情况netstat -anp 所有监听端口及对应的进程netstat -tlnp 功能同上 网络基本命令 (1)network ...
- 10.6 监控io性能 10.7 free命令 10.8 ps命令 10.9 查看网络状态 10.10 linux下抓包
iostat sysstat 包里面包括 sar 和 iostat [root@centos7 ~]# iostat Linux 3.10.0-693.2.2.el7.x86_64 (centos7. ...
- 监控io性能、free、ps命令、查看网络状态、Linux下抓包 使用介绍
第7周第2次课(5月8日) 课程内容: 10.6 监控io性能 10.7 free命令10.8 ps命令10.9 查看网络状态10.10 linux下抓包扩展tcp三次握手四次挥手 http://ww ...
随机推荐
- restFull接口实现web
1. 模板引擎JSP的限制 在开始之前呢,我觉得我们有必要先去了解下 Spring Boot 2.0 官方文档中提到的如下内容: 模板引擎 除了REST Web服务之外,还可以使用Spring MVC ...
- Linux下Tomcat启动报 The BASEDIR environment variable is not defined
今天是2017年2月27.在Linux下部署Tomcat官网下载的Tomcat 8.5,结果启动startup.sh报如下错,即使只是跑version.sh也报同样的错. $ ./version.sh ...
- Q859 亲密字符串
给定两个由小写字母构成的字符串 A 和 B ,只要我们可以通过交换 A 中的两个字母得到与 B 相等的结果,就返回 true :否则返回 false . 示例 1: 输入: A = "ab& ...
- mysql把之前表单进行拆分
今天有个任务是需要把之前的历史数据做一个清理. 原历史数据 很多电话号码是放到了一起.所以需要新建一个联系方式表.然后进行增加 新建表格如下: 然后再进行查询数据. SELECT a.uid,subs ...
- PIE SDK Pansharp融合
1.算法功能简介 Pansharp 融合是基于最小二乘逼近法来计算多光谱影像和全色影像之间灰度值关系,具体过程是利用最小方差技术对参与融合的波段灰度值进行最佳匹配,以减少融合后的颜色偏差.该融合方法不 ...
- Win32 进程间通信的分析与比较
1 进程与进程通信 进程是装入内存并准备执行的程序,每个进程都有私有的虚拟地址空间,由代码.数据以及它可利用的系统资源(如文件.管道等)组成.多进程/多线 程是Windows操作系统的一个基本特征.M ...
- Google Authenticator(谷歌身份验证器)
<!DOCTYPE html>Google Authenticator(谷歌身份验证器) ] Google Authenticator(谷歌身份验证器) Google Authentica ...
- POJ 2570 Fiber Network
Description Several startup companies have decided to build a better Internet, called the "Fibe ...
- Best HTTP
http://blog.csdn.net/u012322710/article/details/52860747 Best HTTP (Pro) 这是一款很多公司都在用的网页插件,感觉确实不错,分P ...
- 8086实时时钟实验(二)——《x86汇编语言:从实模式到保护模式》读书笔记06
上次我们说了代码,这次我们说说怎样看到实验结果. 首先编译源文件(我的源文件就在当前路径下,a盘和c盘在上一级目录下): nasm -f bin c08_mbr.asm -o c08_mbr.bin ...