DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Create VIPs On Mac OSX

  • submit to reddit
        Virtual IPs are so damn useful it hurts sometimes. On Mac OS X 10.1 and above, they're extremely easy to create:

Create a VIP on the same subnet as the primary interface(netmask must be 0xFFFFFFFF):

# ifconfig en1 inet netmask alias

Create a VIP on a different subnet:

# ifconfig en1 inet netmask alias

(Note: you may have to sub en0 for en1. Use ifconfig -a to find out what interfaces are available)

Now you have another IP that you can bring stuff up on that won't collide with other stuff running on the same port. 

This is in no way limited to Rails but we can use it to illustrate. Create a VIP for using the ifconfig command above. Then add a line to your /etc/hosts file as follows:  myapp

Now bring Rails up bound to that address on port 80:

$ cd devel/myapp
$ ./script/server -b myapp -p 80

http://myapp/ should now be on Rails.