Add additional addresses to loopback on macOS
·1 min
Adding secondary address to lo0
sudo ifconfig lo0 alias 127.0.0.2
To ensure the secondary address persist after reboots Create a launch daemon with the following contents:
<?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>dev.hrndz.ifconfig</string>
<key>RunAtLoad</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/sbin/ifconfig</string>
<string>lo0</string>
<string>alias</string>
<string>127.0.0.2</string>
</array>
</dict>
</plist>
Finally, start the launch daemon
sudo launchctl bootstrap system /Library/LaunchDaemons/dev.hrndz.ifconfig.plist