How to add an IP address to loopback interface on Mac
21. November 2010 – 03:36Create file /Library/LaunchDaemons/yourname.plist with the following content:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <plist version="1.0"> <dict> <key>Label</key> <string>Your Label</string> <key>ProgramArguments</key> <array> <string>/sbin/ifconfig</string> <string>lo0</string> <string>alias</string> <string>127.0.0.2</string> <string>netmask</string> <string>255.255.255.0</string> </array> <key>RunAtLoad</key> <true/> </dict> </plist> |
and reboot the machine.
3 Responses to “How to add an IP address to loopback interface on Mac”
Very strange…
First, netmask for loopback interface usually is 255.0.0.0.
Second, reboot just to add address sounds very oldfashioned.
Third, at least under linux, one could use any 127.x.y.z addresses without setting any alias at all. I often use ssh -L 127.x.y.z:2222:10.x.y.z:22 user@gw commands to access boxes behind firewall when VPNs do not work. And I don\’t have to setup any aliases. lo0 does the magic.
By Aidas Kasparas on Nov 22, 2010
With the release of Snow Leopard, there is a watcher on /etc/hosts…
just do your edits there, like under any other *nix, and the changes will get picked up immediately.
SL will also automatically update other places like /private/etc/hosts afterwards.
By Andi on Nov 28, 2010
Andi,
adding
127.0.0.2 myhost.local myhost
to /etc/hosts is not enough as it doesn’t create IP on lo adapter. I’ve tested it right now on SL 10.6.5.
Aidas,
I should have explained better: The point here is not if mask is “usual or not” neither if I have to reboot or not. Sure I do not need to reboot as it is enough to run command:
sudo ifconfig lo0 127.0.0.2 netmask 255.255.255.0
The whole point is how to make this change permanent so I do not need to run this command after each reboot. Therefore the reboot in the original post: to verify that everything went right.
By Saki on Nov 28, 2010