Debian Buster - 我的网络配置为静态,但我仍然收到 DHCP 地址

Debian Buster - 我的网络配置为静态,但我仍然收到 DHCP 地址

我有一个非常简单的 /etc/network/interfaces 文件:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
    address 192.168.5.5
    netmask 255.255.255.0
    network 192.168.5.0
    gateway 192.168.5.100

iface usb0 inet static
    address 192.168.7.2
    netmask 255.255.255.252
    network 192.168.7.0
    gateway 192.168.7.1

我为 eth0 分配了一个静态 IP 地址 5.5。但是,启动时,ifconfig 显示已分配了 DHCP 地址 5.21。我可以 ping 这两个地址(5.5 和 5.21),但是我不希望授予 DHCP 地址。

eth0: flags=-28605<UP,BROADCAST,RUNNING,MULTICAST,DYNAMIC>  mtu 1500
        inet 192.168.5.21  netmask 255.255.255.0  broadcast 192.168.5.255
        inet6 fe80::fe69:47ff:fe3a:f3f2  prefixlen 64  scopeid 0x20<link>
        ether fc:69:47:3a:f3:f2  txqueuelen 1000  (Ethernet)
        RX packets 10177  bytes 2731689 (2.6 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 10242  bytes 1042043 (1017.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 55

我正在寻找动态地址的定义位置,以便可以阻止它被分配。

更新:我注意到当我尝试重新启动网络服务器时它会引发错误:

Apr 23 18:04:06 radius systemd[1]: Starting Raise network interfaces...
Apr 23 18:04:06 radius ifup[2887]: RTNETLINK answers: File exists
Apr 23 18:04:06 radius ifup[2887]: ifup: failed to bring up eth0
Apr 23 18:04:06 radius systemd[1]: networking.service: Main process exited, code=exited, status=1/FAILURE
Apr 23 18:04:06 radius systemd[1]: networking.service: Failed with result 'exit-code'.
Apr 23 18:04:06 radius systemd[1]: Failed to start Raise network interfaces.

ip addr show为 eth0 产生多个地址:

2: eth0: <BROADCAST,MULTICAST,DYNAMIC,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether fc:69:47:3a:f3:f2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.5.20/24 brd 192.168.5.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 192.168.5.5/24 brd 192.168.5.255 scope global secondary eth0
       valid_lft forever preferred_lft forever
    inet 192.168.5.6/24 brd 192.168.5.255 scope global secondary eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::fe69:47ff:fe3a:f3f2/64 scope link
       valid_lft forever preferred_lft forever

答案1

事实证明,安装了 connman,因此它会覆盖 resolv.conf 并忽略 /etc/network/interfaces 的内容。

答案是卸载 connman:

sudo apt remove connman --purge

并使用 /etc/network/interfaces。或者,使用 connmanctl 设置静态 IP 地址:

connmanctl config ethernet_fc69473af3f2_cable --ipv4 manual 192.168.5.5 255.255.255.0 192.168.5.100

相关内容