OS X: Add a loopback alias

To add then delete a loopback IP addresse (like 127.0.0.1) on OS X:

sudo ifconfig lo0 alias 127.0.0.2
sudo ifconfig lo0 -alias 127.0.0.2

Useful when you wish to map multiple local domain names in /etc/hosts to various virtual local hosts.

The changes will vanish after a restart, but a comment on the source article describes how to keep the changes permanently.

Source: Aaron Douglas

References about loopback addresses: