我在嵌入式设备上工作,上面有linux。我想首先使用DHCP客户端,但是如果DHCP服务器没有响应,我希望设置静态-默认IP。我想这不应该很复杂,但我还没有找到严格的答案。
我正在考虑两个解决方案(不幸的是,我可以在几天内测试它们):
布尔巴特克
我使用udhcpc -类似于:
udhcpc -n -f -i eth0
if ifconfig | grep -A1 eth0 | grep inet
then 发布于 2012-10-04 13:28:22
dhclient应该通过租约声明支持回退,查看一下dhclient.conf手册页面。
将类似的内容添加到dhclient.conf中
timeout 10;
lease {
interface "eth0";
fixed-address 10.0.0.10;
option subnet-mask 255.255.255.0;
renew 2 2022/1/1 00:00:01;
rebind 2 2022/1/1 00:00:01;
expire 2 2022/1/1 0:00:01;
}或者,您可以向接口分配第二个IP,比如/etc/network/interfaces。
auto lo
iface lo inet loopback
iface eth0 inet dhcp
auto eth0:1
iface eth0:1 inet static
address 10.10.10.2
netmask 255.255.255.0发布于 2020-01-26 03:29:18
尽管这是一个老问题,但这里可能值得注意的是,Gentoo Linux已经使用了很长时间(我从2004年起就开始使用它)。Gentoo的网络配置文件(/etc/conf.d.d/net)允许在DHCP失败时为任何接口轻松指定后备IP地址,例如:
modules="dhclient"
config_eth0="dhcp"
config_eth1="dhcp"
dhclient_eth1="nogateway"
fallback_eth0="apipa"
fallback_eth1="192.168.10.10/24"
fallback_routes_eth1="default via 192.168.10.1"Maurizio提供的使用像eth0:0这样的别名的解决方案在许多情况下(可能大多数情况下)都很好,但不是全部。我遇到了一个软件,它不认为eth0:0是eth0的合适替代品,尽管它是同一个端口,但由于DHCP没有给出答案而没有定义它。因此,静态回退地址略优于别名解决方案。
https://stackoverflow.com/questions/12727175
复制相似问题