We help IT Professionals succeed at work.

how to configure multiple IPs on centos box for different sites

gddl630 asked
we will be hosting multiple sites on this box and I need to use different IPs in ssl.conf etc so how can I configure the IPs on the interface?

in an old rhel box I've seen in /etc/rc.d/rc.local stuff like: ifconfig eth0:10 netmask, but I was told this is pretty "predestrian" way of doing it

what is the recommended way this should be done? best practice even

I've come across suggestions to copy ifcfg-eth0 for all aliases incrementing the value after :
cp ifcfg-eth0 ifcfg-eth0:0
cp ifcfg-eth0 ifcfg-eth0:1 etc

is this how it is supposed to be done?
Watch Question

Well,you can do it either ways,but I prefer to do it by copying AND modifying the configuration files in /etc/sysconfig/network-scripts/.
Do not forget that after you copy the "template" file ifcfg-eth0:
cp ifcfg-eth0 ifcfg-eth0:0
you have to change two lines,and these are:

DEVICE=eth0  ----> DEVICE=eth0:0IPADDR=first_IP-address ---->IDPADDR=other_interface_address

And do not forget to service network restart to make system re-read configuration files.

Julian ParkerSenior Systems Administrator

reccommended way would be to use the config files in /etc/sysconfig/network-scripts as you mentioned in you post and in the post above.
Julian ParkerSenior Systems Administrator

I've just reread your post, if you mean by hosting multiple sites in a web site sort of way, you would use virtual hosts configured in the httpd.conf file, this would then need to point to your document root depending on hostname.

Is that what you meant?
Jools,multiple SSL (HTTPS!) sites not possible on one IP,because every SSL-enabled site needs a different IP address...so name-based virtual directories do not apply for this question.
if you want to write your own IP script to do it, another pretty simple way is to use the ip addr command (/sbin/ip)

ip addr add xx.xx.xx.xx/mask dev <dev name>

for example
ip addr add dev eth0

would add the IP address to the eth0 network interface.  You would then have to use "ip addr" to see the list of ip addresses, ifconfig would not show the  address.  But if you managed the startup and shutdown in the rc scripts somewhere, you could pretty easily have one script to manage that just lists out the virtual IPs you want to add to the box.

From there, you can define IP based virtual hosts in the apache conf file to listen for the various sites on the IPs you defined.