From cdavid68 at gmail.com Wed Sep 30 16:25:51 2020 From: cdavid68 at gmail.com (David Cohen) Date: Wed, 30 Sep 2020 16:25:51 +0300 Subject: Create a static network configuration from a DHCP lease` Message-ID: Hi, I'm looking for an automated way to convert the DHCP address a server gets during installation to a static IP configuration. I have fixed leases so no future conflict is expected. Is there a ready to use cli tool/script for CentOS 7 ? Best, David -------------- next part -------------- An HTML attachment was scrubbed... URL: From linux-il at shimi.net Wed Sep 30 20:01:55 2020 From: linux-il at shimi.net (shimi) Date: Wed, 30 Sep 2020 20:01:55 +0300 Subject: Create a static network configuration from a DHCP lease` In-Reply-To: References: Message-ID: On Wed, Sep 30, 2020 at 4:26 PM David Cohen wrote: > Hi, > I'm looking for an automated way to convert the DHCP address a server gets > during installation to a static IP configuration. > I have fixed leases so no future conflict is expected. > Is there a ready to use cli tool/script for CentOS 7 ? > > 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: $interface $new_ip_address $new_subnet_mask $new_routers $new_dhcp_lease_time $new_domain_name_servers 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: nmcli con mod "$connection" ipv4.addresses $new_ip_address/$new_subnet_mask(may need to convert to CIDR?) gw4 $new_routers nmcli con mod "$connection" ipv4.method manual nmcli dev disconnect "$connection" nmcli -w 10 dev connect "$connection" HTH, -- Shimi -------------- next part -------------- An HTML attachment was scrubbed... URL: From eden.adogla at gmail.com Wed Sep 30 21:37:01 2020 From: eden.adogla at gmail.com (Eden Adogla) Date: Wed, 30 Sep 2020 11:37:01 -0700 Subject: Create a static network configuration from a DHCP lease` In-Reply-To: References: Message-ID: Another approach would be to update hook into the dhclient.d system like Shimi suggested and then edit the appropriate ifcfg- 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. Cheers, Eden. On Wed, Sep 30, 2020 at 10:03 AM shimi wrote: > > On Wed, Sep 30, 2020 at 4:26 PM David Cohen wrote: > >> Hi, >> I'm looking for an automated way to convert the DHCP address a >> server gets during installation to a static IP configuration. >> I have fixed leases so no future conflict is expected. >> Is there a ready to use cli tool/script for CentOS 7 ? >> >> > 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: > $interface $new_ip_address $new_subnet_mask $new_routers > $new_dhcp_lease_time $new_domain_name_servers > > 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: > > nmcli con mod "$connection" ipv4.addresses > $new_ip_address/$new_subnet_mask(may need to convert to CIDR?) gw4 > $new_routers > nmcli con mod "$connection" ipv4.method manual > nmcli dev disconnect "$connection" > nmcli -w 10 dev connect "$connection" > > HTH, > > -- Shimi > > _______________________________________________ > Linux-il mailing list > Linux-il at cs.huji.ac.il > http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il > -------------- next part -------------- An HTML attachment was scrubbed... URL: