1、检查sys系统文件
1 2 |
cat /sys/class/net/eth0/carrier #0代表未插入网线,1代表插入网线 |
2、ifconfig检索RUNNING字段
如下结果,UP BROADCAST RUNNING MULTICAST其中的RUNNING代表已插入网线
1 2 3 4 5 6 7 8 9 |
z@zlf:/sys/class/net/ens33$ ifconfig ens33 Link encap:Ethernet HWaddr 00:0c:29:b8:dd:d3 inet addr:192.168.5.87 Bcast:192.168.5.255 Mask:255.255.255.0 inet6 addr: fe80::a7a1:7023:d4f6:21a/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:2184341 errors:0 dropped:5654 overruns:0 frame:0 TX packets:2041258 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:391099791 (391.0 MB) TX bytes:1683781935 (1.6 GB) |
3、ethtool检查link detected字段
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
z@zlf:/sys/class/net/ens33$ ethtool ens33 Settings for ens33: 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) Cannot get wake-on-lan settings: Operation not permitted Current message level: 0x00000007 (7) drv probe link Link detected: yes |
可以看到最后一行是link detected为yes