以前一直拿ethtool来判断网络的物理连接是否正常,其他功能都没仔细看过,但是ethtool绝不是单单看网卡是否linked这么简单的,今天来分享一下ethtool工具的简单用法。
首先看一下命令帮助:
Usage: ethtool DEVNAME Display standard information about device ethtool -s|--change DEVNAME Change generic options [ speed 10|100|1000|2500|10000 ] [ duplex half|full ] [ port tp|aui|bnc|mii|fibre ] [ autoneg on|off ] [ advertise %%x ] [ phyad %%d ] [ xcvr internal|external ] [ wol p|u|m|b|a|g|s|d... ] [ sopass %%x:%%x:%%x:%%x:%%x:%%x ] [ msglvl %%d ] ethtool -a|--show-pause DEVNAME Show pause options ethtool -A|--pause DEVNAME Set pause options [ autoneg on|off ] [ rx on|off ] [ tx on|off ] ethtool -c|--show-coalesce DEVNAME Show coalesce options ethtool -C|--coalesce DEVNAME Set coalesce options [adaptive-rx on|off] [adaptive-tx on|off] [rx-usecs N] [rx-frames N] [rx-usecs-irq N] [rx-frames-irq N] [tx-usecs N] [tx-frames N] [tx-usecs-irq N] [tx-frames-irq N] [stats-block-usecs N] [pkt-rate-low N] [rx-usecs-low N] [rx-frames-low N] [tx-usecs-low N] [tx-frames-low N] [pkt-rate-high N] [rx-usecs-high N] [rx-frames-high N] [tx-usecs-high N] [tx-frames-high N] [sample-interval N] ethtool -g|--show-ring DEVNAME Query RX/TX ring parameters ethtool -G|--set-ring DEVNAME Set RX/TX ring parameters [ rx N ] [ rx-mini N ] [ rx-jumbo N ] [ tx N ] ethtool -k|--show-offload DEVNAME Get protocol offload information ethtool -K|--offload DEVNAME Set protocol offload [ rx on|off ] [ tx on|off ] [ sg on|off ] [ tso on|off ] [ ufo on|off ] [ gso on|off ] ethtool -i|--driver DEVNAME Show driver information ethtool -d|--register-dump DEVNAME Do a register dump [ raw on|off ] [ file FILENAME ] ethtool -e|--eeprom-dump DEVNAME Do a EEPROM dump [ raw on|off ] [ offset N ] [ length N ] ethtool -E|--change-eeprom DEVNAME Change bytes in device EEPROM [ magic N ] [ offset N ] [ value N ] ethtool -r|--negotiate DEVNAME Restart N-WAY negotation ethtool -p|--identify DEVNAME Show visible port identification (e.g. blinking) [ TIME-IN-SECONDS ] ethtool -t|--test DEVNAME Execute adapter self test [ online | offline ] ethtool -S|--statistics DEVNAME Show adapter statistics ethtool -h|--help DEVNAME Show this help
ethtool 直接跟网卡名称,可以查看网卡的所有信息:
Settings for eth0: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supported pause frame use: No Supports auto-negotiation: Yes Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Advertised pause frame use: No Advertised auto-negotiation: Yes Speed: 1000Mb/s Duplex: Full Port: Twisted Pair PHYAD: 0 Transceiver: internal Auto-negotiation: on MDI-X: off (auto) Supports Wake-on: d Wake-on: d Current message level: 0x00000007 (7) drv probe link Link detected: yes
可以看到eth0这块网卡是自动协商的,全双工,速率是1000Mb/s,最后一行就是显示你的网卡是否有连接网线的。
ethtool -a eth0:查看eth0网卡的中断设置情况:
Pause parameters for eth0: Autonegotiate:on RX:off TX:off
ethtol -i eth0 :查看网卡的drive name and info:
driver: e1000 version: 7.3.21-k8-NAPI firmware-version: bus-info: 0000:02:01.0 supports-statistics: yes supports-test: yes supports-eeprom-access: yes supports-register-dump: yes supports-priv-flags: no
ethtool -S|--statistics eth0:查看网卡的统计信息(包括received and transferred packets):
NIC statistics: rx_packets: 45326 tx_packets: 17215 rx_bytes: 53883145 tx_bytes: 1510536 rx_broadcast: 0 tx_broadcast: 0 rx_multicast: 0 tx_multicast: 0 rx_errors: 0 tx_errors: 0 tx_dropped: 0 multicast: 0 collisions: 0 rx_length_errors: 0 rx_over_errors: 0 rx_crc_errors: 0 rx_frame_errors: 0 rx_no_buffer_count: 0 rx_missed_errors: 0 tx_aborted_errors: 0 tx_carrier_errors: 0 tx_fifo_errors: 0 tx_heartbeat_errors: 0 tx_window_errors: 0 tx_abort_late_coll: 0 tx_deferred_ok: 0 tx_single_coll_ok: 0 tx_multi_coll_ok: 0 tx_timeout_count: 0 tx_restart_queue: 0 rx_long_length_errors: 0 rx_short_length_errors: 0 rx_align_errors: 0 tx_tcp_seg_good: 24 tx_tcp_seg_failed: 0 rx_flow_control_xon: 0 rx_flow_control_xoff: 0 tx_flow_control_xon: 0 tx_flow_control_xoff: 0 rx_long_byte_count: 53883145 rx_csum_offload_good: 45078 rx_csum_offload_errors: 0 alloc_rx_buff_failed: 0 tx_smbus: 0 rx_smbus: 0 dropped_smbus: 0
ethtool -s 可以更改网卡的速率和自动协商等参数:
# ethtool -s eth0 speed 100 autoneg off # root at vm3 in ~ [14:50:52] # ethtool eth0 Settings for eth0: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supported pause frame use: No Supports auto-negotiation: Yes Advertised link modes: Not reported Advertised pause frame use: No Advertised auto-negotiation: No Speed: 100Mb/s Duplex: Full Port: Twisted Pair PHYAD: 0 Transceiver: internal Auto-negotiation: off MDI-X: off (auto) Supports Wake-on: d Wake-on: d Current message level: 0x00000007 (7) drv probe link Link detected: yes
不过没什么特殊需求还是不要改网卡速率,谁都想越快越好。
最常用的就是下面的用法了,我之前工作上有在生产环境上调节网卡的rs 和tx的值。
ethtool -k eth0, 显示网卡的TCP 协议的offload值,-K 可以针对某个参数做调节:
# ethtool -k eth0 Features for eth0: rx-checksumming: off tx-checksumming: on tx-checksum-ipv4: off [fixed] tx-checksum-ip-generic: on tx-checksum-ipv6: off [fixed] tx-checksum-fcoe-crc: off [fixed] tx-checksum-sctp: off [fixed] scatter-gather: on tx-scatter-gather: on tx-scatter-gather-fraglist: off [fixed] tcp-segmentation-offload: on tx-tcp-segmentation: on tx-tcp-ecn-segmentation: off [fixed] tx-tcp6-segmentation: off [fixed] udp-fragmentation-offload: off [fixed] generic-segmentation-offload: on generic-receive-offload: on large-receive-offload: off [fixed] rx-vlan-offload: on tx-vlan-offload: on [fixed] ntuple-filters: off [fixed] receive-hashing: off [fixed] highdma: off [fixed] rx-vlan-filter: on [fixed] vlan-challenged: off [fixed] tx-lockless: off [fixed] netns-local: off [fixed] tx-gso-robust: off [fixed] tx-fcoe-segmentation: off [fixed] tx-gre-segmentation: off [fixed] tx-ipip-segmentation: off [fixed] tx-sit-segmentation: off [fixed] tx-udp_tnl-segmentation: off [fixed] fcoe-mtu: off [fixed] tx-nocache-copy: off loopback: off [fixed] rx-fcs: off rx-all: off tx-vlan-stag-hw-insert: off [fixed] rx-vlan-stag-hw-parse: off [fixed] rx-vlan-stag-filter: off [fixed] l2-fwd-offload: off [fixed] busy-poll: off [fixed]
tcp-segmentation-offload:on 是指大于系统MTU设定的包的tcp 分片工作会交由网卡来处理而不是cpu。
generic-segmentation-offload: on 跟TSO类似,除了TCP的包,其他协议的包也可以用网卡来分片。
rx-checksumming: off 是指禁用received的 checksum。
tx-checksumming: on 是开启transfer的checksum。
生产环境的服务器是都是2个万兆网卡绑定用来接受电信SIG数据的,所以我的调整如下:
for i in 1 2 3 4;do for j in rx tx;do ethtool -K eth$i $j off;done;done for i in 1 2 3 4;do for j in tso gso;do ethtool -K eth$i $j on;done;done
将所有网卡的rx, tx禁用,并开启所有网卡的tso和gso,以提高网络性能。
欢迎补充!