Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 4 down vote accepted

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

share|improve this answer
    
Works. Thanks! But what is the difference between lo and lo: and how to remove an interface from lo:? –  Leviathan Apr 6 at 20:01
1  
never saw lo: before. Remove with ifconfig lo: down –  user224465 Apr 6 at 20:46
    
Alright, thank you! –  Leviathan Apr 6 at 20:49
    
Thanks for accepting! –  user224465 Apr 6 at 20:51
    
What is the difference between ifconfig lo: and route add -host ? Are they doing the same thing? –  hengxin Jul 30 at 8:00

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..."

share|improve this answer
    
Looks great thanks! Would like to upvote this but i have too less reputation. –  Leviathan Apr 6 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 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. –  darent Oct 7 at 17:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.