尽管“ethtool eth0”显示信息,但接口 eth0 未知

Bla*_*ack 5 linux networking kali-linux

我在虚拟机(VM)上运行kali linux。我今天启动机器,发现缺少 eth0 接口。

所以我尝试ifup eth0启动它,但得到输出:unknown interface eth0

但如果我执行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
    Supported FEC modes: Not reported
    Advertised link modes:  10baseT/Half 10baseT/Full 
                            100baseT/Half 100baseT/Full 
                            1000baseT/Full 
    Advertised pause frame use: No
    Advertised auto-negotiation: Yes
    Advertised FEC modes: Not reported
    Speed: 1000Mb/s
    Duplex: Full
    Port: Twisted Pair
    PHYAD: 0
    Transceiver: internal
    Auto-negotiation: on
    MDI-X: Unknown (auto)
    Supports Wake-on: d
    Wake-on: d
    Current message level: 0x00000007 (7)
                   drv probe link
    Link detected: no
Run Code Online (Sandbox Code Playgroud)

A.B*_*A.B 9

这个错误的原因是,在这里,eth0意味着两个不同的事情:

  • 内核、iproute2工具、ethtooldhclient等确实存在的实际接口名称,

  • 或者ifupdown工具中的接口配置,指向实际的接口名称。在这里,如果从未在配置中定义过,则ifup不知道:这就是错误消息。eth0

    重现此错误的简单方法:

    # ip link add name veth5 type veth peer name veth6
    # ethtool veth5
    Settings for veth5:
        Supported ports: [ ]
    [...]
        Link detected: no
    # ifup veth5
    ifup: unknown interface veth5
    
    Run Code Online (Sandbox Code Playgroud)

所以接口是不会丢失的。ifupdown工具尚未配置为使用它。

对于您的情况,您可以在末尾添加/etc/network/interfaces(或在单独的文件中添加,例如/etc/network/interfaces.d/eth0,如果文件在其配置中interfaces包含目录)以下两行:interfaces.d

auto eth0
iface eth0 inet dhcp
Run Code Online (Sandbox Code Playgroud)

ifupdown工具和命令ifup了解它并在启动时使用 DHCP 配置它。我不知道为什么以前没有这样做。

在我之前的假示例中,我添加了同样的veth5定义(在 Debian 9 上):

# ifup -a
Internet Systems Consortium DHCP Client 4.3.5
Copyright 2004-2016 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/veth5/1e:96:59:c3:e4:0c
Sending on   LPF/veth5/1e:96:59:c3:e4:0c
Sending on   Socket/fallback
DHCPDISCOVER on veth5 to 255.255.255.255 port 67 interval 8
Run Code Online (Sandbox Code Playgroud)