Ubuntu – How to add a loopback interface

12.04networking

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?

Best Answer

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