Mac OS X – Adding a loopback alias

I do a lot of local web development on my MacBook Pro.  Frequently I had multiple tiers of servers running – a Jetty instance running the web tier and a JBoss/EJB server doing the business tier behind it.  The problem is JBoss opens up so many ports on a particular network adapter and trying to get JBoss and Jetty to share a single IP is a nightmare.  So the easier way is to just create a new IP or alias your localhost ( into something like  When you start up Jetty, you pass in the binding IP of .2 and then JBoss and Jetty place nice with each other.

The Mac OS command (at least 10.6) to create an alias is:

ifconfig lo0 alias

and to delete:

ifconfig lo0 -alias

This is not persistent – the alias will not survive a reboot.  I don’t need the alias often even to require it to be permanent.  If you’re curious how to keep it permanent, let me know and I’ll post that.  This is the hacker way to do it on the command line.  There is a much easier way to do it through the GUI but this way doesn’t stick around on the reboot, which is one of my requirements for my project – no retaining traces. 🙂

13 thoughts on “Mac OS X – Adding a loopback alias

  1. MagicMeta

    How do you make this persistent? Is it also possible to create a range of alias IP addresses for the loopback? For example 127.0.x.x, where it may be any of,,,,,,, and so on…


    Liked by 1 person

  2. Astralbodies

    I’ve been investigating this and there is no real easy answer. Mac OS X Server has an IPAliases feature which the desktop version does not have built in. There is an example script that someone built that approximates the feature. BSD Linux, which Mac OS X is based on, would use /etc/rc.conf to set up the interfaces but with the transition to launchd, that configuration is no longer used. My suggestion is to create an Automator action that executes upon login – assuming of course you can wait until login time for the aliases to be created.

    I think you can do a wildcard alias but I don’t know off hand. I’ll verify and do another post.


  3. Jeff

    One answer to the persistence question may be to use a Login Hook:

    I created a script called loopback_alias with the following:

    ifconfig lo0 alias

    (You could add more aliases on additional lines.)

    Then I just followed the directions on the page linked to above (made the script executable and ran the command they show).

    Hope this helps others.


  4. Or in same time if i type not copy
    i get respond this way
    (Mac 10.10.x and same 10.11)
    ipconfig lo0 alias
    usage: ipconfig
    where is one of waitall, getifaddr, ifcount, getoption, getpacket, getv6packet, set, setverbose

    Why I can’t create alias ( I try to setup web design test on ip –
    I edit and update /etc/hosts (with BBEdit)


  5. I needed to add another IPv6 address to the loopback interface, and my guess, based on the instructions in the blog post, seemed to work OK: sudo ifconfig lo0 inet6 alias ::6


  6. Martin Gansler

    As this is the first entry on google, I found a working solution for Sierra which looks very clean:

    Loopback Alias

    Creates an alias on the loopback interface (lo0) with the IP on macOS.


    1. Install the plist to: /Library/LaunchDaemons/com.runlevel1.lo0.
    2. Set mode: sudo chmod 0644 /Library/LaunchDaemons/com.runlevel1.lo0.
    3. Set owner: sudo chown root:wheel /Library/LaunchDaemons/com.runlevel1.lo0.
    4. Load: sudo launchctl load /Library/LaunchDaemons/com.runlevel1.lo0.

    The alias will automatically be created at startup from then on.

    You can confirm the alias was created with ifconfig:

    /tmp ❯❯❯ ifconfig lo0
    lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
           	inet6 ::1 prefixlen 128
           	inet netmask 0xff000000
           	inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
           	inet netmask 0xff000000
           	nd6 options=1<PERFORMNUD>

    view raw

    hosted with ❤ by GitHub

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" ""&gt;
    <plist version="1.0">

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s