I already have a loopback address at 127.0.0.1, which corresponds to a host in the local loopback network 127.0.0.0/8. How could I create a second local loopback host with an address of 127.0.0.2? Does anyone knows the exact command?
14 Answers
1) Can add it temporary using below command
ifconfig lo:40 192.168.40.1 netmask 255.255.255.0 up2) Add them permanently to /etc/network/interfaces
auto lo lo:10 lo:20
iface lo inet loopback
iface lo:10 inet static address 192.168.10.1 netmask 255.255.255.0 network 192.168.10.0
iface lo:20 inet static address 192.168.20.1 netmask 255.255.255.0 network 192.168.20.0 5 Though it's probably not actually leaving us soon, ifconfig is the "old" way of doing things, and is being replaced with the ip command. The way to do this with ip is:
ip addr add 192.168.40.1/32 dev loThere's no need for virtual interfaces any more (i.e., the lo:10 and so forth Mukesh used), but you can still have them if you want like
ip addr add 192.168.40.1/32 dev lo label lo:40note that I'm using /32 netmasks because lo is special in that it will answer for an address belonging to a network configured on it. So if you add 192.168.40.1/24 it will actually respond to any 192.168.40.* address, not just .1
To that end, for your original example of 127.0.0.2, it will actually already respond to that, because it falls in 127.0.0.0/8 so you don't have to do anything at all to get that particular address.
Also, be careful with addresses on loopback, because the kernel will know that address is on the host and will reply to requests for that address on physical interfaces as well.
3Tested on my Raspberry Pi which is Raspbian, Debian based, so this should work as well on Debian. I created /etc/network/interfaces.d/lo with the following contents:
auto lo
iface lo inet loopback
iface lo inet static address 127.0.0.2/24 broadcast 0.0.0.0On Debian you should already have the first two lines in /etc/network/interfaces, so you can add the remaining lines there. On Raspbian it seemed the first two lines were implicit and not needed, but it worked with them too.
NB: To use the interfaces.d directory you will have to add the following to /etc/network/interfaces if not already there:
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d For me lo: didn't worked but lo worked in Ubuntu. What I did was
sudo ifconfig lo 127.0.0.2 netmask 255.0.0.0 up
sudo ifconfig lo 127.0.0.3 netmask 255.0.0.0 upAnd then hitting ifconfig -a will fetch the details.