====== How do you get loopback addresses other than 127.0.0.1 to work on OS X ======
1. Add localhost alias script:
$ sudo touch /usr/local/bin/localhost_alias
$ sudo chmod +x /usr/local/bin/localhost_alias
2. localhost_alias content:
#!/usr/bin/env bash
from=${1}
to=${2}
if [[ -z "$from" |]]; then
echo "Usage: "`basename "$0"`" 2-255 2-255 [from and to range numbers (127.0.0.[from-to])]"
exit 0
fi
for ((i=${from};i<=${to};i++))
do
sudo ifconfig lo0 alias 127.0.0.$i up
done
3. add autorun daemon description:
$ sudo touch /Library/LaunchDaemons/org.localhost.alias.plist
4. org.localhost.alias.plist content:
Label
org.localhost.alias
RunAtLoad
ProgramArguments
/usr/local/bin/localhost_alias
2
8
And we have ''127.0.0.2'' - ''127.0.0.8'' aliases at boot
*Tested on MacOS Mojave.\\
** You must allow to run ''sudo script-name'' without password in sudoers file.
sudo touch /private/etc/sudoers.d/localalias
sudo vi /private/etc/sudoers.d/localalias
## Added localhost alias\\
ALL ALL=NOPASSWD: /usr/local/bin/localhost_alias
sudo chmod 440 /private/etc/sudoers.d/localalias