
難道是:
ethtool ethx | grep detected
如果作業系統(linux)端尚未配置 bond0,則顯示「未偵測到連結」?
ethtool不是顯示物理狀態嗎?
答案1
Ethtool 僅適用於實體乙太網路適配器。這意味著 bond0、tun0 和任何其他非實體網路設備的網路設備將無法與 ethtool 一起使用。
$ ethtool <eth?>
例如:
$ ethtool eth0
提供:
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
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: 1
Transceiver: internal
Auto-negotiation: on
MDI-X: on
Supports Wake-on: pumbg
Wake-on: g
Current message level: 0x00000001 (1)
Link detected: yes
答案2
我假設您想要查找 NIC 的連結狀態,而不是電纜插入插座的物理狀況。 (這可能是不可能找到的。)
透過快速搜索,我想您已經有了答案。打開介面,等待它找到一個鏈接,如果有的話(可能需要幾秒鐘),然後檢查ethtool
, orcarrier
和/或operstate
in的輸出/sys/class/net/$NIC/
。
ifconfig somenic up
似乎打了這兩ioctl
通電話:
ioctl(4, SIOCGIFFLAGS, {ifr_name="somenic", ifr_flags=IFF_BROADCAST|IFF_MULTICAST}) = 0
ioctl(4, SIOCSIFFLAGS, {ifr_name="somenic", ifr_flags=IFF_UP|IFF_BROADCAST|IFF_RUNNING|IFF_MULTICAST}) = 0
也就是說,它設定IFF_UP
.基於這裡,這實際上是導致設備初始化的設定:
然後,它透過(套接字 I/O 控制設定介面標誌)設定該
IFF_UP
位元以開啟介面。dev->flag
ioctl(SIOCSIFFLAGS)
不過,後一個指令 (
ioctl(SIOCSIFFLAGS)
) 會呼叫裝置的 open 方法。就實際程式碼而言,驅動程式必須執行許多與字元和區塊驅動程式相同的任務。 open 請求它需要的任何系統資源並告訴介面出現;
有類似效果的評論e1000e
驅動源:
/**
* e1000e_open - Called when a network interface is made active
* @netdev: network interface device structure
*
* Returns 0 on success, negative value on failure
* * The open entry point is called when a network interface is made
* active by the system (IFF_UP). At this point all resources needed
* for transmit and receive operations are allocated, the interrupt
* handler is registered with the OS, the watchdog timer is started,
* and the stack is notified that the interface is ready.
**/
int e1000e_open(struct net_device *netdev)
這意味著沒有辦法有意義地找到不存在的 NIC 的連結狀態。向上,因為硬體甚至不會被初始化。
當然,至少在理論上,某些驅動程式的行為可能有所不同,並在任何人設置之前初始化硬件IFF_UP
,但這在一般情況下仍然沒有幫助。