DHCP and static IP on a single interface: static IP disappears
I recently migrated my Ubuntu Server to an OpenStack environment. I needed two different IP-addresses, and it seemed me wise to keep the first (primary) IP-address assigned by DHCP, and then the second one static.
Due to apparent OpenStack restrictions at my current provider, the easiest way was to assign both IP-addresses to the same adapter. As such, I configured them as follows (/etc/network/interfaces):
auto eth0 iface eth0 inet dhcp iface eth0 inet static address <IP-address> netmask 255.255.255.0 broadcast <broadcast address>
That seemed to work all fine, and ip address show properly displayed both addresses. Both could be used by Apache, Postfix,…
However, after irregular intervals, my webserver seemed to get disconnected. Rebooting the machine solved the issue until the next occurence. Restarting Apache, MySQL,… didn’t seem to help however, so they weren’t the culprit. Restarting only the network interface(s) however did the trick, so it had to do with the network setup. The static IP address seemed to disappear from the adapter, it wasn’t showing up anymore at all.
The problem was lying with the DHCP Client, who seemed to reconfigure the interface at certain times, getting rid of the static IP address.
As suggested by some forums, I added an alias section to my dhclient.conf (in /etc/dhcp/). This however produced issues upon restarting the network interfaces: ifup: RTNETLINK answers: File exists
The solution was to configure my setup as follows (note the things in bold):
auto eth0 eth0:0 iface eth0 inet dhcp iface eth0:0 inet static address <IP-address> netmask 255.255.255.0 broadcast <broadcast address>
This actually solved the problem, without struggling with OpenStack, the DHCP client or having to reconfigure my Apache, Postfix, etc.