How to use loopback addresses other than with OSX

Strange little thing I encountered a while back. Basically, I use ssh tunnels to a number of remote hosts and to organize it a bit easier, I tend to use 127.0.0.X and assign each server a different number. However, under OSX you cannot use any others except for

The fix isn’t too bad though, you basically need to add the interfaces either manually or at startup.

To add just a few, you can do:

sudo ifconfig lo0 alias up

and change 2 to whatever ip you need. However, if you want to add a large number or all of the possible ones, this will take a long time. So, a quick little script to do it would be something like:

for ((i=2;i<256;i++))
   sudo ifconfig lo0 alias 127.0.0.$i up

You could also change the 256 to something else like 50 if you don’t want the full list added.