iftop 高级使用场景
在这一步骤中,我们将探索 iftop 命令的一些高级使用场景。
- 监控特定网络接口:
sudo iftop -i eth0
这将仅显示 eth0 接口上的网络流量。
- 按主机或端口过滤流量:
sudo iftop -F 192.168.1.100
这将显示与 IP 地址为 192.168.1.100 的主机之间的网络流量。
sudo iftop -p 80
这将显示端口 80(HTTP)上的网络流量。
- 将输出保存到文件:
sudo iftop -B -f iftop.txt
这将把 iftop 的输出保存到当前目录下的 iftop.txt 文件中。
- 以特定格式显示输出:
sudo iftop -o "%-18s %-18s %10.2f %10.2f %10.2f"
这将以自定义格式显示输出,展示源地址、目标地址、传入、传出和总带宽使用情况。
- 在浏览器中显示输出:
sudo iftop -w
这将启动 iftop 的 Web 服务器,并在浏览器中显示网络流量信息。
示例输出:
@@@@ IFTOP 1.0~pre4 @@@@
192.168.1.100 : 192.168.1.101
192.168.1.102
192.168.1.103
192.168.1.104
192.168.1.105
192.168.1.106
192.168.1.107
192.168.1.108
192.168.1.109
192.168.1.110
In: 0.00 Kb/s 0.00 Kb/s 0.00 Kb/s
Out: 0.00 Kb/s 0.00 Kb/s 0.00 Kb/s
Total: 0.00 Kb/s 0.00 Kb/s 0.00 Kb/s