I want to add two more loopback interfaces.
I used the following command:
ifconfig lo: 127.0.0.2 netmask 255.0.0.0 upand 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?
5 Answers
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 upworks. 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 loworks 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.5See also IP-Aliasing Linux Networking-HOWTO
7If you keep using ifconfig lo... you're not creating a new interface, you're overwriting the previous one. You could try editing your interfaces file:
sudo vim /etc/network/interfacesMine looks like this:
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopbackSo, you could try and modifyi 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 lo3Then, restart the network, or the whole system, and try to interact with the new interfaces with:
sudo ifconfig lo2/lo3 etc... 6 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 dummyPlease check that dummy kernel module is loaded before running the above command:
sudo lsmod | grep dummy 1 When using the newer iproute2 tool you can also do what user224465 suggests:
ip addr add 127.0.0.2 dev lo
route add -host 127.0.0.2 dev loI've used this to create a fake ip address for aws on docker, nl. 169.254.169.254 Combine this with ectou_metadata and you have aws from the cloud on your docker image.
I've notice that I'm not the only one looking for a solution for multiple loopback interfaces. In the last period I was playing a lot with FRRouting and route-leak between VRF and I notice a strange problem with dummy interfaces: are not responding to ping if the dummy interface is under a VRF (more explantions in README.md on the github). For this reason I was writing a new driver based on dummy, VRF interface and loopback and I was able to make it to responds to ping.
Maybe there is somebody else intereseted to test it and see if it's suitable as a multi loopback interface.
Here are the sources:
Also I opened a ticket to Linux Kernel mentioning this misbehavior of the dummy driver and about this new driver:
Hope it helps.
0