I am developing a web app that has to produce different output based on ip. For testing and during development it would help a lot if I could have more loopback ip addresses besides 127.0.0.1. Is there a way to create (and latter destroy) these?
Asked
Active
Viewed 5,916 times
2 Answers
3
Edit /etc/network/interfaces
add the following at the bottom of the file
auto lo:0
iface lo:0 inet static
address 127.0.0.2
netmask 255.0.0.0
Documentation on interfaces file can be found here : http://manpages.ubuntu.com/manpages/lucid/man5/interfaces.5.html
The definition above firstly tells the system to automatically bring the new lo:0 virtual interface (alias) up when the system starts. Then it sets interface lo:0 (bound to the loopback interface) to be a static address. The last two lines set the address and the netmask.
After you have added the above you will need to restart networking
sudo /etc/init.d/networking restart
or reboot the computer.
![](../../users/profiles/399607.webp)
bitmaster2000
- 3
- 2
![](../../users/profiles/192039.webp)
Sam
- 617
- 1
- 5
- 14
1
The whole 127.0.0.1/8
address space is reserved for loopback addresses. So you can use any address from 127.0.0.1
up to 127.255.255.254
.
![](../../users/profiles/121920.webp)
scai
- 2,199
- 1
- 12
- 16
-
1+1, good to know fact. However, I tried http://127.0.0.5/ with my browser and I get *(111) Connection refused* error. So, I guess I should try the method @Sam [suggests](http://serverfault.com/a/579443/25163). – Majid Fouladpour Mar 03 '14 at 10:34
-
2They're reserved, but not available for applications unless the interface(s) are added. see http://askubuntu.com/questions/444124/how-to-add-a-loopback-interface/444128#444128. For contrast, on Windows, the full range is bindable without manually adding more interfaces. – Kind Contributor Feb 25 '17 at 01:36