24

I want to add two more loopback interfaces.

I used the following command:

ifconfig lo: 127.0.0.2 netmask 255.0.0.0 up

and type in ifconfig, i can see the loopback address was added.

But if i want to add one more interface... (for example 127.0.0.3) the previous interface (127.0.0.2) was overwritten.

Also when i look in /etc/network/interfaces i see no entry.

How can i add multiple loopback interfaces permanently?

30

It depends what you want lo or lo: which is an interface alias.

ifconfig lo:0 127.0.0.2 netmask 255.0.0.0 up
ifconfig lo:1 127.0.0.3 netmask 255.0.0.0 up
ifconfig lo:2 127.0.0.4 netmask 255.0.0.0 up

works. If you want to have more IP's on lo use

route add -host 127.0.0.3 dev lo
route add -host 127.0.0.4 dev lo
route add -host 127.0.0.5 dev lo

works too. If you want to remove it, use:

route del -host 127.0.0.3
route del -host 127.0.0.4
route del -host 127.0.0.5

See also IP-Aliasing Linux Networking-HOWTO

  • Works. Thanks! But what is the difference between lo and lo: and how to remove an interface from lo:? – Leviathan Apr 6 '14 at 20:01
  • 1
    never saw lo: before. Remove with ifconfig lo: down – user224465 Apr 6 '14 at 20:46
  • What is the difference between ifconfig lo: and route add -host ? Are they doing the same thing? – hengxin Jul 30 '14 at 8:00
  • 1
    lo:<foo> is a new interface that use lo as a base, its called a alias and you can operate it as a normal interface: set it up, down, etc. It creates a separation between just adding more ips to a interface or creating a new interface. It is useful when you dont want actions applied on one ip to be done also to the rest of the ips in one interface – Bruno Pereira Jun 3 '15 at 14:09
  • Used route add -host [dest] dev lo, and it caused some really unexpected behavior. It doesn't work on its own, without creating the interface alias route add doesn't work - not sure what it does. Does lo then forward the packages to the default gateway, or what happens? Get ping timeouts with route add. Seems like it might be dangerous. – John Doe May 22 '17 at 14:50
7

If you keep using "ifconfig lo..." you're not creating a new interface, you're overwritting the previous one. You could try editing your interfaces file:

sudo vim /etc/network/interfaces

Mine looks like this:

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback

So, you could try and modifying it to create new interfaces:

# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
auto lo2
iface lo2 inet loopback
auto lo3

Then, restart the network, or the whole system, and try to interact with the new interfaces with "sudo ifconfig lo2/lo3 etc..."

  • Looks great thanks! Would like to upvote this but i have too less reputation. – Leviathan Apr 6 '14 at 19:54
  • What are the ips for the new created lo2 and lo3? By the way, what do the numbers (interfaces(5), ifup(8), and ifdown(8)) mean? Thanks. – hengxin Jul 30 '14 at 8:05
  • Those numbers are references to the man pages, but don't know exactly how they work. The lines are comented anyway. About the IP, you'll need to set them with ifconfig or with address 127.0.0.2 etc under each interface. – animaletdesequia Oct 7 '14 at 17:25
  • If you're curious what the numbers mean, run man man; the numbers indicate what section of the manual each manpage is in. Section 5 is for file formats and conventions, for example, and section 8 is for system administration commands (that usually are only expected to be run by root). – Parthian Shot Jul 6 '15 at 23:36
  • 4
    I don't think that this actually works. You can only have on "lo" device per namespace according to driver/net/loopback.c. The "dummy" device may do everything you need, "sudo ip link add name loop1 type dummy" – mcr Sep 25 '15 at 13:42
3

To add multiple loopback interfaces permanently, must do an additional check for dummy driver.

Dummy driver is used for the making of multiple loopbacks device instead of
creating multiple aliases to one device, with an attachment of different IP.

This lines add another loopback named loop1, loop2, loop3:

sudo ip link add name loop1 type dummy
sudo ip link add name loop2 type dummy
sudo ip link add name loop3 type dummy

Please check that dummy kernel module is loaded before running the above command:

sudo lsmod | grep dummy
  • Hello and welcome to Ask Ubuntu! Can you please edit your answer to include more information about how this command will solve the OP's problem? Please see How to Answer for additional tips. – Kaz Wolfe Jun 22 '17 at 19:42
  • this adds a dummy interface which works similar but lacks flags the lo interface has – sjas Jul 7 '18 at 18:27
  • Kaz Wolfe - edit - solve. For now, to have an independent device it's the good solution. – Adam Ł. Sep 6 '18 at 10:29

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.