netstatlsof都是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 查看网络状态的更多相关文章

  1. 在Linux下用netstat查看网络状态、端口状态

    在Linux下用netstat查看网络状态.端口状态 在linux一般使用netstat 来查看系统端口使用情况步. netstat命令是一个监控TCP/IP网络的非常有用的工具,它可以显示路由表.实 ...

  2. Linux下用netstat查看网络状态、端口状态(转)

    转:http://blog.csdn.net/guodongdongnumber1/article/details/11383019 在linux一般使用netstat 来查看系统端口使用情况步.  ...

  3. 用netstat查看网络状态详解

    --用netstat查看网络状态详解 -----------------------------2014/06/11 一.Linux服务器上11种网络连接状态:                     ...

  4. Linux下用netstat查看网络状态、端口状态

    在linux一般使用netstat 来查看系统端口使用情况步. netstat命令是一个监控TCP/IP网络的非常有用的工具,它可以显示路由表.实际的网络连接以及每一个网络接口设备的 netstat命 ...

  5. Linux使用netstat查看网络状态

    查看本机的网络状态.使用netstat查看网络状态.显示系统端口使用情况.UDP类型的端口.TCP类型的端口.只显示所有监听端口.只显示所有监听tcp端口. 命令使用举例 命令 说明 netstat ...

  6. centos7如何查看网络状态?

    参考https://www.jb51.net/os/RedHat/520187.html 查看网络状态: lsof -Pnl +M -i4 显示ipv4服务及监听端情况 netstat -anp 所有 ...

  7. CentOS下查看网络状态

    查看网络状态:lsof -Pnl +M -i4 显示ipv4服务及监听端情况netstat -anp 所有监听端口及对应的进程netstat -tlnp 功能同上 网络基本命令 (1)network ...

  8. 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. ...

  9. 监控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 ...

随机推荐

  1. [水题AC乐] - 贪心

    HDU - 1009 https://paste.ubuntu.com/p/rgSYpSKkwW/ POJ - 1017 麻烦的模拟 贪心 题意就是用尽量少的66h箱子装nnh的物品,贪心策略很明显, ...

  2. [转] Kubernetes K8S 简介

    [From] https://blog.csdn.net/zhangxxxww/article/details/73547251 Kubernetes(k8s)是自动化容器操作的开源平台,这些操作包括 ...

  3. 完美的js继承

    //完美的js继承 少了类管理器 Object.extend=function(){ var fnTest = /\b_super\b/; //继承父类 var _super = arguments[ ...

  4. async中series的实现 javascript构件

    //同步流程 var series=function(arr){ function async(i){ arr[i](function(){ if(1+i<arr.length){ async( ...

  5. python 爬虫系列01-连接mysql

    爬虫学习中......................................... import pymysql conn = pymysql.connect(host=',database ...

  6. RabbitMQ基础知识篇

    1.Linux安装RabbitMQ. 参考网址:RPM安装RabbitMQ   仔细阅读. 先安装erlang: su -c 'rpm -Uvh http://mirrors.neusoft.edu. ...

  7. Windows 下推荐软件

    神器 Dism++ Quicker(效率工具) Bandizip 火绒安全软件 Everyting(搜索神器并支持http远程连接) Xmanager VMware Workstation IDMan ...

  8. HTML的注释方式对JSP的JSTL不管用

    <fmt:parseNumber var="y" integerOnly="true" type="number" value=&qu ...

  9. (六-1)Firefox插件安装

    1.安装火狐插件 ①旧版本firefox 火狐浏览器右上角-->附件-->获取更多附件-->搜索-->Firebug 安装 Firebug 扩展:https://addons. ...

  10. [转]jQuery Validate使用说明

    本文转自:http://www.cnblogs.com/gimin/p/4757064.html jQuery Validate 导入 js 库 <script src="./jque ...