I have a need to host multiple IPs on the same host on the same subnet due to SSL certificate reasons. My initial attempt at setting this up ended in routing errors. After a bit of digging I found out why.
Because the server in question was a VMware guest, I initially just added a second network interface to the VMware guest and assigned the second IP address to it. At first glance this seems to work, as I can ping both of the IPs from within my subnet. However, if I try to access both of the IPs from outside of the subnet, only one of the IPs works!
Why is it doing this? The answer lies in the routing table.
ajz@server:~$ route -vn
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use
220.127.116.11 0.0.0.0 255.255.255.128 U 0 0 0 eth0
18.104.22.168 0.0.0.0 255.255.255.128 U 0 0 0 eth1
0.0.0.0 22.214.171.124 0.0.0.0 UG 100 0 0 eth0
0.0.0.0 126.96.36.199 0.0.0.0 UG 100 0 0 eth1
You see when a packet comes in from outside of the local network to eth1, it may get routed back on eth0, or eth1. One of those is going to get lost. This means the routing table will choose one of the interfaces for routing traffic back to the internet outside your subnet, and the other interfaces get lost in the process.
So how do we set it up right? We don't
use a different ethernet interface for each adapter. We setup an eth0:1 interface! The working configuration file is below.
If you're using a debian based system, the
file looks like the following.
# The loopback network interface
iface lo inet loopback
# The primary network interface
iface eth0 inet static
# dns-* options are implemented by the resolvconf package, if installed
dns-nameservers 188.8.131.52 184.108.40.206
# Alternate secondary network interface
iface eth0:1 inet static