【发布时间】:2016-01-05 22:59:22
【问题描述】:
当没有通过DHCP获取IP地址时,我想设置一个静态IP,我之前写在一个文本文件中。
我的 staticIP.txt 的内容:
10.10.0.254
到目前为止,当 DHCP 不起作用时,我得到了一个静态 IP。我为此编辑了/etc/dhcp/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;
}
(来源:Set static ip if not obtained from DHCP (script))
现在我想覆盖“fixed-address 10.0.0.10;”在我的 staticIP.txt 中使用静态 IP“10.10.0.254”,当没有获得 DHCP 时。
到目前为止,我所能做的就是替换“固定地址;”用 sed 阻塞并将其写入文件:
sed -i 's/fixed-address [0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}/<MANUAL ENTERED IP>/g' /etc/dhcp/dhclient.conf
现在缺少两件事:
从 staticIP.txt 中提取 IP 并覆盖“fixed-address [IP];”
检查是否没有通过 DHCP 获取 IP 并运行 sed 命令
如果有人可以帮助我,我会很高兴。
非常感谢。
【问题讨论】:
标签: linux sed ip dhcp ifconfig