<div dir="ltr"><div>Another approach would be to update hook into the dhclient.d system like Shimi suggested and then edit the appropriate ifcfg-<interface-name> scripts found at /etc/sysconfig/network-scripts to hardcode the configs and then restart the interface. Such a change will guarantee that the config persists after boot.<br></div><div><br></div><div>Cheers,<br></div><div>Eden.<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Sep 30, 2020 at 10:03 AM shimi <<a href="mailto:linux-il@shimi.net">linux-il@shimi.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Sep 30, 2020 at 4:26 PM David Cohen <<a href="mailto:cdavid68@gmail.com" target="_blank">cdavid68@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi,<div>I'm looking for an automated way to convert the DHCP address a server gets during installation to a static IP configuration.</div><div>I have fixed leases so no future conflict is expected.</div><div>Is there a ready to use cli tool/script for CentOS 7 ?</div><div></div></div><br></blockquote><div><br></div><div>I don't know of an existing solution, however, you can probably throw a bash script to /etc/dhcp/dhclient.d/whatever.sh, and in it take the DHCP data stored in the variables:</div><div>$interface $new_ip_address $new_subnet_mask $new_routers $new_dhcp_lease_time $new_domain_name_servers</div><div><br></div><div>and use them in nmcli commands to alter the existing connection to a static one with those settings, e.g. something along the lines of:</div><div><br></div><div>nmcli con mod "$connection" ipv4.addresses $new_ip_address/$new_subnet_mask(may need to convert to CIDR?) gw4 $new_routers<br>nmcli con mod "$connection" ipv4.method manual<br>nmcli dev disconnect "$connection"<br>nmcli -w 10 dev connect "$connection"</div><div><br></div><div>HTH,</div><div><br></div><div>-- Shimi<br></div><div><br> </div></div></div>
_______________________________________________<br>
Linux-il mailing list<br>
<a href="mailto:Linux-il@cs.huji.ac.il" target="_blank">Linux-il@cs.huji.ac.il</a><br>
<a href="http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il" rel="noreferrer" target="_blank">http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il</a><br>
</blockquote></div>