Short version
I know this question is very similar to others and I did really search the Internet for answers, but it seems that no approach is working or the solutions seem to be "to complicated to be best practice" (I'll try to explain). I'm looking for a safe way on how to disable DHCP from command line (to use in scripts).
Background
I'm trying to create a "Live-Cd" with Ubuntu Server 12.04 and remastersys (works well). The system is, by default, configured to get the IP with DHCP while booting.
That's ok - the important thing is that a script (which runs after booting) is able (in some specific cases) to set a static IP using ifconfig
(not /etc/network/interfaces ):
ifconfig eth0 192.168.0.1
Actually this is also working, but the IP only persists until the DHCP lease time of the previously obtained lease is over. A new IP will be assigned to eth0, which (in short) breaks the system. I thought "no big deal, there will be surely something like: "
ifconfig eth0
dhcpdisabled
But I ended up recognizing, it doesn't work that easy. Editing the /etc/network/interfaces
is a bit tricky, because it is generated by remastersys (actually the 23networking script of casper).
I could rewrite it and restart networking, but what will happen to active dhclient.leases? Will be DHClient still be running in the background (it shouldn't but some posts suggest it will be my tests showed it is restarted “randomly“, if dhclient is killed), do I have to remove or empty dhclient.leases files, what about resolv.conf?
Despair
To sum it up - In my opinion it's not really that "straightforward" and somewhat doesn't "feel stable". This question (156183) suggested to remove the dhclient package, but: Will this solve the problem? Will this break other stuff?
Is there really no command for this? I hope I just overlooked it.