iptstate 是一个在Ubuntu等Linux系统上运行的开源工具,全称是 IP Tables State。它设计用于实时显示Linux内核中Netfilter框架的连接跟踪表(state table),以类似于 top 命令的界面呈现。Netfilter是Linux内核中用于处理网络数据包的框架,而iptstate的主要作用是帮助用户监控和管理通过iptables(Netfilter的用户空间工具)建立的网络连接状态。
root@vgt-ubuntu-10:~# iptstate --help
loop: 104
IPTables State Top Version 2.2.6
Usage: iptstate [<options>]
-c, --no-color
Toggle color-code by protocol
-C, --counters
Toggle display of bytes/packets counters
-d, --dst-filter <IP>
Only show states with a destination of <IP>
Note, that this must be an IP, hostname matching is not yet supported.
-D --dstpt-filter <port>
Only show states with a destination port of <port>
-h, --help
This help message
-l, --lookup
Show hostnames instead of IP addresses. Enabling this will also enable
-L to prevent an ever-growing number of DNS requests.
-m, --mark-truncated
Mark truncated hostnames with a '+'
-o, --no-dynamic
Toggle dynamic formatting
-L, --no-dns
Skip outgoing DNS lookup states
-f, --no-loopback
Filter states on loopback
-p, --no-scroll
No scrolling (don't use a "pad")
-r, --reverse
Reverse sort order
-R, --rate <seconds>
Refresh rate, followed by rate in seconds
Note: For statetop, not applicable for -s
-1, --single
Single run (no curses)
-b, --sort <column>
This determines what column to sort by. Options:
d: Destination IP (or Name)
p: Protocol
s: State
t: TTL
b: Bytes
P: Packets
To sort by Source IP (or Name), don't use -b.
Note that bytes/packets are only available when supported in the kernel,
and enabled with -C
-s, --src-filter <IP>
Only show states with a source of <IP>
Note, that this must be an IP, hostname matching is not yet supported.
-S, --srcpt-filter <port>
Only show states with a source port of <port>
-t, --totals
Toggle display of totals
See man iptstate(8) or the interactive help for more information.
使用示例
1. 基本实时监控
1
sudo iptstate
说明:启动iptstate,进入实时监控模式,默认按源IP排序。
界面说明:
显示源IP、目标IP、协议、端口、状态等。
使用 h 查看帮助,q 退出。
2. 单次输出状态表
1
sudo iptstate -1
说明:仅输出当前连接状态表一次,然后退出。
输出示例: Source Destination Proto State TTL 192.168.1.100:22 10.0.0.1:54321 tcp ESTABLISHED 43199 192.168.1.101:80 172.16.0.2:12345 tcp TIME_WAIT 119