Permanently create an ifconfig loopback alias — macOS

david limkys
Jan 14, 2018 · 1 min read

A couple of days ago I’ve booted up my mac and was just about to start working when I noticed non of my docker containers was working properly.
I scratched my head for a few minutes before I realised that, yet again, I forgot to set up an alias to lo0 device…

I’ve decided it’s about time to stop being lazy and make this permanent, but how? adding an alias to lo0 requires root permissions

sudo ifconfig lo0 alias someIp

Being new to mac I was not sure what would be the best way to do this, editing the hosts file? creating a SUID file ?

After searching a bit I found the answer in appleDocs, it seems we can just create launch demon.

In a nutshell a launch demon is a process managed by the launchd service, we can create one to run once, continuously or periodically.

So, how do we utilise this to create an ifconfig alias?
Just create a new launch demon file and configure it like so:

sudo vi /Library/LaunchDaemons/org.my.ifconfig.plist<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.my.ifconfig</string>
<key>RunAtLoad</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/sbin/ifconfig</string>
<string>lo0</string>
<string>alias</string>
<string>YourIpHere</string>
</array>
</dict>
</plist>

Make sure to insert the desired ip in the last string argument.

And that’s it! on your next restart you should be set to go.

For more information about launch demons and how to configure them go to appleDocs.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store