2

I'm using a Mac OS X, and I'm trying to begin using VirtualHost functionality with Apache2. I've created and loaded up a hosts file that looks like this:

127.0.0.1      localhost
192.168.0.71    name1
192.168.0.71    name2

Right now, I can only use 192.168.0.71 because that's my computer's IP on my LAN. How can I make a broad range of IPs all point to my same computer?

(I don't know much, if anything, about LANs. I didn't even set up my LAN, I'm just using my wireless router as one... I haven't done any special networking.)

2
  • Generally having to take an entire class C network to use a certain functionality seems like too much - what's your end goal here? There's probably a better way..
    – Brandon
    May 9, 2009 at 17:21
  • 1
    Generally the only reason to use multiple IP-adresses on a web server is if it's suppose to serve multiple HTTPS websites... otherwise just use 'host headers' (that answer +1:ed) May 9, 2009 at 18:45

4 Answers 4

14

You could set your network card to have 253 static IP addresses - but that's really not a good way to do this.

If you just want to host multiple sites on one IP address, use name-based virtual host instead of IP virtual hosts (the apache equivalent of Host Headers in Windows/IIS).

More info... http://httpd.apache.org/docs/2.0/vhosts/name-based.html

1
  • 2
    Oh. Well, I feel stupid. Name based is totally the way to go, I just never realized there was such a way! Thank you. May 9, 2009 at 20:44
1

What you need are virtual NICs. I don't know exactly how to do it in MacOS X, but it seems something like this will do:

ifconfig eth0 alias 192.168.1.1
ifconfig eth0 alias 192.168.1.2
ifconfig eth0 alias 192.168.1.3

etc... or maybe:

ifconfig eth0:1 alias 192.168.1.1
ifconfig eth0:2 alias 192.168.1.2

Another options is that if you're running a DNS server, just add CNAMEs (aliases) for your main A record. This is far more convenient and easier, IMHO. Let me know if you need any assistance with this.

1
  • Correct syntax for linux aliases is: ifconfig eth0:0 1.2.3.4 netmask 255.255.255.0 ... ifconfig eth9:222 2.3.4.5 netmask 255.255.255.0 Or, using the newer "ip" mode: ip addr add 1.2.3.4/24 dev eth0
    – LapTop006
    May 26, 2009 at 10:57
1

Maybe you are looking at this the wrong way. Setup your apache to use the host names instead of the IPs to distingish which files to serve. Then, you can simply use the name to redirect to your computer, or locally as the following:

127.0.0.1    localhost
127.0.0.1    name1
127.0.0.1    name2
-1

I have setup my development machine like this

(hosts file)

127.0.0.1 localhost
127.0.0.2 project1.localhost
127.0.0.3 project2.localhost
...

And then proceed to use name based virtual host config in the webserver of your choise.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .