linux静态ip调整为dhcp指令 最后更新时间:2026年04月30日 ## ✅ 解决方案 执行以下命令将 eth0 的连接配置从静态改为 DHCP: ```bash # 1. 修改方法为自动(DHCP) nmcli connection modify eth0 ipv4.method auto # 2. 清除之前设置的静态地址 nmcli connection modify eth0 ipv4.addresses "" # 3. (可选)增加 DHCP 超时时间,避免因网络慢导致获取失败 nmcli connection modify eth0 ipv4.dhcp-timeout 30 # 4. (可选)禁止 DHCP 失败后回退到其他地址 nmcli connection modify eth0 ipv4.may-fail no # 5. 确保开机自动连接 nmcli connection modify eth0 connection.autoconnect yes # 6. 重新激活连接以立即生效 nmcli connection down eth0 && nmcli connection up eth0 ``` 修改完成后,检查是否成功获取到 DHCP 分配的 IP: ```bash ip addr show eth0 ``` 如果没有立即获得,可以手动请求: ```bash sudo dhclient -v eth0 ``` 最后重启测试: ```bash sudo reboot ``` 重启后用 `ip addr show eth0` 确认是否自动获得了正确的 DHCP 地址(不再是 192.168.100.100)。
Comments | NOTHING