I'd want an equivalent of the following /etc/network/interfaces config, but done via NetworkManager (or at least giving me chance to control eth0 connections via nm-applet and possibly choose a different one):

allow-hotplug eth0
iface eth0 inet dhcp

auto eth0:1
iface eth0:1 inet static

The static address is from a different subnet than the one from DHCP.

The closest I could get with NetworkManager was to create a connection on eth0 with "Auto" type, and added an additional IPv4 address (either via nmcli or nm-connection-editor).

The problem is that until the interface gets a DHCP lease, the static address is not available. That's a big problem in my setup - there are cases where the DHCP server will never be available and I need to have at least the static address.

Even setting may-fail doesn't help, since it skips the whole IPv4 configuration if no lease is available.

I also tried to put just the subinterface eth0:1 in /etc/network/interfaces, but as soon as I connect and disconnect the NetworkManager-managed DHCP connection, the subinterface gets lost. So I tried creating post-up and down scripts which bring eth0:1 up/down. But that results in weird behavior - NetworkManager then automatically creates a new connection called eth0 with just a static address and "Manual" setting. It's not set to autoconnect, though the system connects to it as soon as it figures out that the DHCP lease won't come. And once the system is connected to this "surprise" connection, it will never try to reconnect to the one with DHCP.


RTFM dude.... on my Debian:

  1. man 8 NetworkManager
       NetworkManager will execute scripts in the
       /etc/NetworkManager/dispatcher.d directory or subdirectories in
       alphabetical order in response to network events. Each script should be
       a regular executable file owned by root. Furthermore, it must not be
       writable by group or other, and not setuid.

       Each script receives two arguments, the first being the interface name
       of the device an operation just happened on, and second the action. For
       device actions, the interface is the name of the kernel interface
       suitable for IP configuration. Thus it is either VPN_IP_IFACE,
       DEVICE_IP_IFACE, or DEVICE_IFACE, as applicable. For the hostname and
       connectivity-change actions it is always "none".

       The actions are:

           The interface is connected to the network but is not yet fully
           activated. Scripts acting on this event must be placed or symlinked
           into the /etc/NetworkManager/dispatcher.d/pre-up.d directory, and
           NetworkManager will wait for script execution to complete before
           indicating to applications that the interface is fully activated.

           The interface has been activated.

  1. Create a script in /etc/NetworkManager/dispatcher.d that will:
    • Check if $1 == "eth0"
    • Check if $2 == "up"
    • If so, call ifconfig eth0 add <your second IP>
| improve this answer | |
  • I'm not sure you got what the problem is. I need the static address to be present even in case th DHCP server doesn't respond. But the up event is only generated when the DHCP connection succeeds... – Martin Pecka Jan 22 at 18:05
  • Then try the pre-up step. – binarym Jan 23 at 8:52
  • pre-up resulted in the same behavior (it might seem odd, but that's the reality) – Martin Pecka Jan 23 at 11:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.