Create a localhost alias

It is often helpful to be able associate a private IP address with the local loopback. This may be required to allow references to host services from within the private network space of a Docker container for example.

Configure a Local Network Interface in Mac OSX

We will associate a private IP address 10.10.10.100 with the lo0 (127.0.0.1) network interface of our Mac. Create /Library/LaunchDaemons/ca.epbc.loopback-dev.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>ca.epbc.loopback-dev</string>
    <key>ProgramArguments</key>
    <array>
        <string>/sbin/ifconfig</string>
        <string>lo0</string>
        <string>alias</string>
        <string>10.10.10.100</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
  </dict>
</plist>

Note you will have to reboot your Mac for the alias to take effect. Modify /etc/hosts Then add the following local hostnames to /etc/hosts:

$ echo "10.10.10.100 dev myapp" >> /etc/hosts

On Windows (in PowerShell?):

$ netsh interface ip add address "Local Dev Connection" 10.10.10.100 255.255.255.255
$ echo "10.10.10.100 dev myapp" >> C:\Windows\System32\Drivers\etc\hosts

Note: I’m on a Mac so Windows users please apply the required edits to make the above work - apparently you can accomplish the same thing using the advanced network interface properties screen. Also, I’m not sure if the above setting for Windows will survive logout or reboot.

When you are done confirm that you can ping the above local host names.