- 使用 dhcpcd 获取 IP 地址(
dhcpcd -p eth0
) - 手动更改 IP 地址 (
ifconfig eth0 x.x.x.x
) - 终止 dhcpcd (
dhcpcd -k eth0
) - 重新启动 dhcpcd(
dhcpcd -p eth0
)
在这种情况下,dhcpcd 将不会设置接口的 IP 地址,接口将使用手动设置的 IP 地址。为什么不配置接口?
dhcpcd -d eth0
显示:
eth0: dhcpcd 4.0.0-beta6 starting
eth0: hardware address = ##:##:##:##:##:##
eth0: broadcasting for a lease
eth0: sending DHCP_DISCOVER with xid 0x25fc838b
eth0: waiting for 3.241 seconds
eth0: offered 192.168.228.180 from 192.168.50.10
eth0: sending DHCP_REQUEST with xid 0x25fc838b
eth0: waiting for 7.224 seconds
eth0: lease of 192.168.228.180 acknowledged
eth0: sending ARP probe #1
eth0: waiting for 1.563 seconds
eth0: sending ARP probe #2
eth0: waiting for 1.442 seconds
eth0: sending ARP probe #3
eth0: waiting for 2.000 seconds
eth0: leased 192.168.228.180 for 691200 seconds
eth0: renew in 345600 seconds
eth0: rebind in 604800 seconds
eth0: adding IP address 192.168.228.180/23
eth0: adding route to 0.0.0.0/0 via 192.168.228.1
eth0: exec `/libexec/dhcpcd-run-hooks'
eth0: forking to background
答案1
事实证明,如果接口已分配有效的静态 IP 地址,则 dhcpcd 将不会配置该接口。
通过添加步骤:3b.将 eth0 IP 更改为无效值(ifconfig eth0 0.0.0.0)
该接口配置为 dhcpcd 重新启动时 DHCP 分配的 IP 地址。