方法一:nmcli
输出中参数wired-properties.carrier为on即为接网线网卡
#nmcli device show |grep -i -e "device|carrier"
general.device: ens224
wired-properties.carrier: on
如下命令将输出内容合并为一行,只看{banned}{banned}{banned}{banned}{banned}最佳佳佳佳佳后一列为on即可
#nmcli device show |awk '/device/{t=$0}/carrier/{print t,$0}'
general.device: ens224 wired-properties.carrier: on
方法二:ifconfig
输出中状态为running的接口卡即为接网线网卡
# ifconfig |grep running
ens224: flags=4163running,multicast> mtu 1500
方法三:ethtool来检查,主要关注的字段为"link detected",注意如下的输出,其中em4实际物理上并未插上网线,而em1是插上网线的:
# ethtool ens224
settings for ens224:
supported ports: [ tp ]
supported link modes: 1000baset/full
10000baset/full
supported pause frame use: no
supports auto-negotiation: no
advertised link modes: not reported
advertised pause frame use: no
advertised auto-negotiation: no
speed: 10000mb/s
duplex: full
port: twisted pair
phyad: 0
transceiver: internal
auto-negotiation: off
mdi-x: unknown
supports wake-on: uag
wake-on: d
link detected: yes