jus*_*nas 80 networking linux ifconfig
由于ifconfig在主要 Linux 发行版中显然已被弃用,我想我会了解一些ip应该使用的工具而不是ifconfig.
在这里我遇到了一个问题:当单独运行时,ifconfig除了其他信息外,还显示每个接口上接收/传输的字节数。我找不到从ip. 这个工具没有这个功能吗?我可以使用哪些其他内置工具来获取这些统计信息?
Zor*_*che 72
ipiproute2 包中的命令是新工具。该link子命令用于管理设备/接口。
如果您可以使用 ip -s link
root:~# ip -s link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
RX: bytes packets errors dropped overrun mcast
50679705 529967 0 0 0 0
TX: bytes packets errors dropped carrier collsns
50679705 529967 0 0 0 0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:1d:7d:aa:e3:4e brd ff:ff:ff:ff:ff:ff
RX: bytes packets errors dropped overrun mcast
187663757 308710386 0 0 0 0
TX: bytes packets errors dropped carrier collsns
4051284587 532435117 0 0 0 0
Run Code Online (Sandbox Code Playgroud)
dsm*_*k80 67
另一种选择是使用 /proc 文件系统。在的/ proc /净/ dev的文件包含有关配置的网络接口的统计信息。每条线路专用于一个网络接口,它包含接收和传输的统计信息。统计信息包括诸如接收/发送的字节总数、数据包、丢弃、错误等指标。
cat /proc/net/dev
Inter-| Receive | Transmit
face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
lo: 29846937 129576 0 0 0 0 0 0 29846937 129576 0 0 0 0 0 0
wlan0: 9467393340 8027251 0 0 0 0 0 0 2559312961 5896509 0 0 0 0 0 0
Run Code Online (Sandbox Code Playgroud)
或者您可以尝试使用netstat命令,它可以显示所有网络接口和相关统计信息:
netstat -i
Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR TX-OK TX-ERR TX-DRP TX-OVR Flg
lo 65536 0 130435 0 0 0 130435 0 0 0 LRU
wlan0 1492 0 8028018 0 0 0 5897361 0 0 0 BMRU
Run Code Online (Sandbox Code Playgroud)
ALe*_*hha 54
您可以通过 proc 获取所有必要的信息
# cat /sys/class/net/eth0/statistics/rx_bytes
# cat /sys/class/net/eth0/statistics/rx_packets
# cat /sys/class/net/eth0/statistics/tx_packets
# cat /sys/class/net/eth0/statistics/tx_bytes
Run Code Online (Sandbox Code Playgroud)
您也可以使用 iptables 并解析输出。
对于接收到的数据包
# iptables -L INPUT -n -v
Run Code Online (Sandbox Code Playgroud)
对于传输的数据包
# iptables -L OUTPUT -n -v
Run Code Online (Sandbox Code Playgroud)
如果服务器是网关,那么你还应该解析FORWARD链
| 归档时间: |
|
| 查看次数: |
91874 次 |
| 最近记录: |