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

09.25.2005
| 4576 views |
  • 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 192.168.1.130 netmask 255.255.255.255 alias

Create a VIP on a different subnet:

# ifconfig en1 inet 192.168.64.25 netmask 255.255.255.0 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 192.168.1.150 using the ifconfig command above. Then add a line to your /etc/hosts file as follows:

192.168.1.150  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.