How to configure multiple loop back interface

Hello i wonder how can be possible to configure multiply loop-back interfaces in OpenWrt?

I tryed the following:

config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.255.255.0'

config interface 'loopback1'
        option ifname 'lo1'
        option proto 'static'
        option ipaddr '127.1.0.1'
        option netmask '255.255.255.0'

config interface 'loopback2'
        option ifname 'lo2'
        option proto 'static'
        option ipaddr '127.1.1.1'
        option netmask '255.255.255.0'

config interface 'loopback3'
        option ifname 'lo3'
        option proto 'static'
        option ipaddr '127.1.2.1'
        option netmask '255.255.255.0'

but no luck:

....
gre4-gre1 Link encap:UNSPEC  HWaddr C0-A8-38-02-00-00-00-00-00-00-00-00-00-00-00-00
          inet addr:172.16.12.1  P-t-P:172.16.12.1  Mask:255.255.255.252
          inet6 addr: fe80::5efe:c0a8:3802/64 Scope:Link
          UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1280  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:20 errors:0 dropped:0 overruns:0 frame:0
          TX packets:20 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1893 (1.8 KiB)  TX bytes:1893 (1.8 KiB)

root@OWRT-V-01:~#

thank you

I would not wonder if openwrt is not designed to manage those devices. What happen if you issue sth. like:

ifup lo3

uci set network.loopback1.ifname="@loopback"
uci set network.loopback2.ifname="@loopback"
uci set network.loopback3.ifname="@loopback"
uci commit network
/etc/init.d/network restart

See also: https://openwrt.org/docs/guide-user/network/network_interface_alias

If you need different L2 devices, then:

cat << EOF > /etc/modules.d/00-custom
dummy numdummies=3
EOF
opkg update
opkg install kmod-dummy
uci set network.loopback1.ifname="dummy0"
uci set network.loopback2.ifname="dummy1"
uci set network.loopback3.ifname="dummy2"
uci commit network
/etc/init.d/network restart
2 Likes

Ah, simple syntax problem. :smiley:

1 Like

Thank you vgaetera.

uci set network.loopback1.ifname="@loopback"
uci set network.loopback2.ifname="@loopback"
uci set network.loopback3.ifname="@loopback"
uci commit network
/etc/init.d/network restart

that is not really helped.
I even try to change the ip netmask just for the lo interface but no effect like it hard coded.

>  config interface 'loopback'
>         option ifname 'lo'
>         option proto 'static'
>         option ipaddr '121.0.0.1'
>         option netmask '255.255.255.0'

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:20 errors:0 dropped:0 overruns:0 frame:0
TX packets:20 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1893 (1.8 KiB) TX bytes:1893 (1.8 KiB)

Any how i think dummy interface would be perfect for my purpose :slight_smile:

Thank you

Hmm... If I issue:

uci set network.loopback1.ifname="@loopback"

I get:

uci: Invalid argument

Same for dummy line (kmod installed).

Screenshot_20200817_222314

i added by hand to network config. and it is worked :slight_smile:

config interface 'loopback1'
        option proto 'static'
        option ipaddr '10.1.0.1'
        option netmask '255.255.255.0'
        option ifname 'dummy0'

config interface 'loopback2'
        option proto 'static'
        option ipaddr '10.1.1.1'
        option netmask '255.255.255.0'
        option ifname 'dummy1'

config interface 'loopback3'
        option proto 'static'
        option ipaddr '10.1.2.1'
        option netmask '255.255.255.0'
        option ifname 'dummy2'

2 Likes

This is a working method for OpenWrt to create a separate network/interface.
It is an abstraction level above the L3 device that you can rely on in other configs.
Although, a separate network/interface does not mean a separate L2/L3 device.
If it does not match your final goal, use the second method.

I posted only the changes relative to the OP config.
You need to define the interfaces beforehand.

1 Like

Ah, forgot about that. Dummy in front of the screen. oO

1 Like