10

How do I get this ifconfig loopback alias change to persist after a restart?

$ sudo ifconfig lo0 alias 172.16.222.111
$ ifconfig
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
    options=1203<RXCSUM,TXCSUM,TXSTATUS,SW_TIMESTAMP>
    inet 127.0.0.1 netmask 0xff000000 
    inet6 ::1 prefixlen 128 
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
    inet 172.16.222.111 netmask 0xffff0000          ### <-- WANTED!!!
    nd6 options=201<PERFORMNUD,DAD>

The only similar instructions I've found are for nonexistent OSX files on other *nix systems for files like /etc/network/interfaces or /etc/sysconfig/networking-scripts/ifcfg-eth0.

17

Generally speaking, you can create the persistent alias in Network in System Preferences.

enter image description here enter image description here

However, the lo0 loopback device doesn't show up here. For this special case, we need to utilize launchd to kick off a short script with the ifconfig command you used above.

Here is a sample .plist file, saved as com.user.lo0-loopback.plist (can be saved anywhere as it will be copied to the appropriate directory later).

<?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>com.user.lo0-loopback</string> 
  <key>ProgramArguments</key> 
  <array> 
    <string>/sbin/ifconfig</string> 
    <string>lo0</string> 
    <string>alias</string> 
    <string>172.16.222.111</string> 
  </array> 
  <key>RunAtLoad</key> <true/> 
  <key>Nice</key> 
  <integer>10</integer> 
  <key>KeepAlive</key> 
  <false/> 
  <key>AbandonProcessGroup</key> 
  <true/> 
  <key>StandardErrorPath</key> 
  <string>/var/log/loopback-alias.log</string> 
  <key>StandardOutPath</key> 
  <string>/var/log/loopback-alias.log</string> 
</dict> 
</plist>

Next, move it to the /Library/LaunchDaemons/ directory so it's kicked off at boot (will be run as root) and set the correct permissions

$ cp com.user.lo0-loopback.plist /Library/LaunchDaemons/ 

$ chmod 0644 /Library/LaunchDaemons/com.user.lo0-loopback.plist 
$ chown root:wheel /Library/LaunchDaemons/com.user.lo0-loopback.plist

Then load it with launchctl

$ launchctl load /Library/LaunchDaemons/com.user.lo0-loopback.plist

Reboot and your lo0 loopback should have an alias IP assigned to it that will be persistent across reboots.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .