对我来说,我可以直接使用netstat -rn或route -n命令来查看我的接口情况。
cyrex@cyrex:~$ netstat -nr
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.48.0.1 0.0.0.0 UG 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
192.48.0.0 0.0.0.0 255.255.224.0 U 0 0 0 eth0
或者使用 netstat -r 命令。
cyrex@cyrex:~$ netstat -r
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
default 192-48-0-1.dyn. 0.0.0.0 UG 0 0 0 eth0
link-local * 255.255.0.0 U 0 0 0 eth0
192.48.0.0 * 255.255.224.0 U 0 0 0 eth0
在这两种情况下,我都可以看到接口的名称,本例中是eth0。
这些命令提供的信息如下(源链接在这里找到):
目标 - 目标网络或目标主机。
网关 - 网关地址,如果没有设置则为*。
掩码 - 目标网络的子网掩码。
255.255.255.255 for the host destination.
0.0.0.0 for the default route.
旗帜 - 可能的旗帜包括:
U (route is up)
H (target is a host)
G (using gateway)
R (reinstate route for dynamic routing)
D (dynamically installed by daemon or redirect)
M (modified from routing daemon or redirect)
A (installed by addrconf)
C (cache entry)
! (reject route)
MSS - TCP连接在此路由上的默认最大分段大小。
Window - TCP连接在此路由上的默认窗口大小。
irtt - 初始往返时间(RTT)。内核使用此参数猜测最佳TCP协议参数,而不必等待(可能较慢的)答复。
Iface - 发送到此路由的数据包所使用的接口。
其他字段可能包括:
Metric - 到目标的距离(通常以跳数计算)。近期内核不使用此字段,但路由守护程序可能需要它。
Ref - 对此路由的引用次数(Linux内核不使用)。
Use - 路由查找的次数。根据是否使用了-F和-C选项,这将是路由缓存未命中(-F)或命中(-C)的计数。
HH(仅缓存)- 与缓存路由相关联的ARP条目和缓存路由的硬件头缓存的数量。如果缓存路由的接口不需要硬件地址(例如lo),则为-1。
Arp(仅缓存)- 缓存路由的硬件地址是否是最新的。
现在来谈谈问题。我现在能想到最简单的方法(当然,有几种方法可以做同样的事情),就是使用iptraf。只需安装它:
sudo apt-get install iptraf
然后以root权限运行它:sudo iptraf
在iptraf的菜单中选择IP Traffic Monitor,然后选择All Interfaces。这将显示所有TCP连接及其相关的接口。它是基于终端的,非常适合监控目的。