Linux 1 NIC 2 IPs on different networks, want to bind one apache instance only to second IP.
Posted on 2010-09-03
I have a Linux box with only a NIC, I have been assigned 2 ip address on different networks, and of course different default GWs, currently I have activated only one of them (IP-A) in the usual way, and it works.
IP-A is let's say 10.0.0.20 with default gw: 10.0.0.1
IP-B is let's say 192.168.1.20 with default gw: 192.168.0.1
Apache is working let's name it Apache-A
I need to set a new apache server only for IP-B, that will have different config from that running for IP-A, so what I am going to do, is to bind Apache instance A, only to IP-A, and will execute another instance with another config file for IP-B and will bind it only for that IP..
What I want to achieve is that requests comming from net-A be handled with apache-A and requests comming from net-B to be handled by apache-B.
My current Linux initialization scripts gets the IP-A, from DHCP... so dhcp sets the default gw, to net's-A 10.0.0.1.
So, what can I do to initialize the NIC (after getting IP-A address via DHCP), with the network-B IP,
and make sure that apache instance-B does not send back requests comming from IP-B trough DefaultGW-A, (it has to use defaultGW-B)?
The first step is simple:
ifconfig eth:0 192.168.1.20 up
What follows?, "ip" command?, "route" command?, "iptables" ??.......
(IP based virtual hosts is not a solution)