Correct way to have 2 IP addresses on a given interface

Hey there.

I thing there was a time when your setting used to work, but I'm unsure if that broke by accident or was just removing unnecessary magigc.

Imho your setting creates a single interface eth0 which then gets configured according to your settings. Then this interface is referred to as lan, but it still is only eth0.

Your second setting tries to overwrite the configuration for eth0 and call the result lan2. It does not create a second interface but tries to apply the second network setting as well to the very same existing interface.

One way of dealing with it: An alias

You can create a new interface lan2 that doesn't use the physical ifname eth0 but just hooks onto the original lede interface lan and reuses the physical ifnames, no matter which interfaces are actually in use.

config interface 'lan'
    option ifname 'eth0'
    option proto 'static'
    option ipaddr '10.20.10.20'
    option netmask '255.255.255.0'

config interface 'lan2'
    option ifname '@lan'
    option proto 'static'
    option ipaddr '10.20.10.20'
    option netmask '255.255.255.0'

So the second interface lan2 is really a new interface that just happens to reuse the exact same ifname configuration as lan.

Another way of dealing with it: Bridges

config interface 'lan'
    option type 'bridge'
    option ifname 'eth0'
    option proto 'static'
    option ipaddr '10.20.10.20'
    option netmask '255.255.255.0'

config interface 'lan2'
    option type 'bridge'
    option ifname 'eth0'
    option proto 'static'
    option ipaddr '10.20.10.20'
    option netmask '255.255.255.0'

Those should create two different networks br-lan and br-lan2, both of type bridge, and both bridges should have a single member eth0. Here the network settings are not applied to eth0 directly but to br-lan and br-lan2.

Regards,
Stephan.

1 Like