用 ifconfig 查網路卡的代號 (如下 ens18)
$ ifconfig
ens18: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.213 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::805d:2cff:fe83:be86 prefixlen 64 scopeid 0x20<link>
ether 82:5d:2c:83:be:86 txqueuelen 1000 (Ethernet)
RX packets 180421 bytes 28681530 (27.3 MiB)
RX errors 0 dropped 9 overruns 0 frame 0
TX packets 102287 bytes 156632224 (149.3 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
$ cat /sys/class/net/ens18/speed
1000 <!--1000MB/s 的速度
若系統中有安裝 ethtool 時:
$ ethtool ens18
Settings for ens18:
Supported ports: [ ]
Supported link modes: Not reported
Supported pause frame use: No
Supports auto-negotiation: No
Supported FEC modes: Not reported
Advertised link modes: Not reported
Advertised pause frame use: No
Advertised auto-negotiation: No
Advertised FEC modes: Not reported
Speed: 1000Mb/s
Duplex: Full
Auto-negotiation: off
Port: Other
PHYAD: 0
Transceiver: internal
netlink error: Operation not permitted
Link detected: yes
另外,在 /sys/class/net/ens18/statistics/ 目錄底下,也有該網卡的各項流量資料;
$ ls /sys/class/net/ens18/statistics/
collisions rx_crc_errors rx_frame_errors rx_over_errors tx_carrier_errors tx_fifo_errors
multicast rx_dropped rx_length_errors rx_packets tx_compressed tx_heartbeat_errors
rx_bytes rx_errors rx_missed_errors tx_aborted_errors tx_dropped tx_packets
rx_compressed rx_fifo_errors rx_nohandler tx_bytes tx_errors tx_window_errors
網卡傳出的 bytes 數量
$ cat /sys/class/net/ens18/statistics/tx_bytes
156676775
網卡接收的 bytes 數量
$ cat /sys/class/net/ens18/statistics/rx_bytes
28836537