Correct way to have 2 IP addresses on a given interface

Using the latest LEDE stable build Reboot (17.01.4...)

The config 'network' shows

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

So I added another block to have a secondary IP on that interface

config interface 'lan2'
	option ifname 'eth0'
	option proto 'static'
	option ipaddr '192.168.192.168'
	option netmask '255.255.255.0'

But that doesn't work (neither IP), have to enter the Failsafe mode and remove the 2nd one (fortunately the Failsafe mode works on LEDE!).

Tried also list ipaddr ... x 2, but only one IP is visible.

What is the recommended way to have 2 IPs on the same interface?

Thank you

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.

2 Likes

I have a second ip on one router I'm running like you want. it's running a snapshot from back in Dec because it needed some hardware support not in trunk. I'm using it to access an ATT supplied vdsl modem...

config interface 'wan'
	option ifname 'eth0.2'
	option proto 'dhcp'


config interface 'ATT'
	option proto 'static'
	option ifname 'eth0.2'
	option ipaddr '192.168.1.2'
	option netmask '255.255.255.0'
	option broadcast '192.168.1.255'
	option delegate '0'

it works. fine. perhaps try renaming "lan2" to something like "secondlan" ?

@dlakelan, thanks - but are you sure that still works under LEDE? Tried that successfully (virtual iface) with Chaos Calmer, but didn't work under LEDE (not saying that has to work, since LEDE seems to clean the settings, I'd prefer it works only in one good way :slight_smile:

@golialive Thank you. Will try that later this week end.

It is working right now under LEDE on the device I mentioned. It's a LEDE snapshot so it's possible that the stable version broke this and later the snapshot restored it... but I doubt it.

1 Like

Ok thanks! Will try that also, and show the results here.

@golialive it seems the IP address in my case in properly received from the DHCP server (as shown in logread) but it is not shown by ifconfig. Funny thing is, it sort of works: I can ping the modem and access its gui from the lan.

Context: I have a DSL modem connected on the wan port, defined as such:

config interface 'wan'
        option ifname 'eth1'
        option proto 'pppoe'
        option username 'username'
        option password 'password'
        option peerdns '0'
        option dns '8.8.8.8 8.8.4.4'
        option ipv6 '0'
        option keepalive '6 5'

The modem interface definition is:

config interface 'modem'
        option proto 'dhcp'
        option ifname 'eth1'
        option delegate '0'
        option defaultroute '0'
        option peerdns '0'
        option auto '1'

I have tried also using '@wan' but the result seems to be the same. In my previous router, with proper VLAN on WAN support, I had probably used 'eth0.2' for both "wan" and "modem" but other than that there is no other difference I can see. In that case, the IP for the modem interface would remain visible.
(previous: GL.inet MT750; current: Fritzbox 4040)

Is this to be expected? It's more a curiosity at this point than a real issue, of course.

The legacy ifconfig program will only show the first IPv4 address of an interface. You can use ip -4 addr show dev eth1 instead to show all IPv4 addresses on the eth1 interface.

2 Likes

Thanks, @jow

Rechecked, new info:

  • with "@wan" in the modem interface, both "ifconfig" and "ip" show no address.
  • with "eth1", both show the correct address.
  • the older router had indeed WAN as a switch port and I used "eth0.2" for both the PPP wan and the modem link.

TLDR never mind, operator error :stuck_out_tongue: