I have an Ubuntu 14.04 server with one NIC. The MAC address on this NIC is assigned (by the data centre's gateway) one IP (X.X.X.100) in one subnet (X.X.X.0/24), with the gateway being in the same subnet (X.X.X.1), and an additional IP range from a completely different subnet (Y.Y.Y.0/28).
I've set up the server with both X.X.X.100 and Y.Y.Y.1 on the same interface (eth0), and the server can contact and be contacted by the rest of the Internet - on both IP addresses.
I have some virtual machines that use the IP addresses from the second subnet. I assume they must use the host's second IP address Y.Y.Y.1 as their gateway address (as they won't be able to reach the data centre's gateway address due to it being in a different subnet - as far as I understand). All the IP addresses I have, X.X.X.100 and Y.Y.Y.0/28 are statically routed on the data centre's gateway, so any request destined for them will arrive at my server's NIC. It will also only accept requests from the MAC address on that NIC, not the MAC addresses of the VMs.
How do I set up the host so that all requests to or from the Y.Y.Y.0/28 subnet are routed via the data centre's gateway X.X.X.1?
As far as I know, I cannot simply expand the netmask, as this could lead to not being able to contact other servers on the net.
Here's the server's /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address X.X.X.100
netmask 255.255.255.0
gateway X.X.X.1
dns-nameservers 8.8.8.8 8.8.4.4
iface eth0 inet static
address Y.Y.Y.1
netmask 255.255.255.240
In /etc/sysctl.conf I have enabled this line:
net.ipv4.ip_forward=1
The VMs use Y.Y.Y.n (where n>1) as IP address and Y.Y.Y.1 as gateway.
With the above setup, the VMs can contact the host on both its IP addresses, but nothing else. I think the VMs have trouble finding the MAC address of the ISP's gateway X.X.X.1:
$ arp -an
? (X.X.X.1) at c8:60:00:5e:bd:e0 [ether] on eth0
? (Y.Y.Y.1) at <incomplete> on eth0
However strangely, they can sometimes...
$ arp -an
? (X.X.X.1) at c8:60:00:5e:bd:e0 [ether] on eth0
? (Y.Y.Y.1) at cc:e1:7f:07:e0:af [ether] on eth0
These two examples where taken only a few minutes apart. I have a feeling that pinging the VM, especially pinging from the VM speeds up the process of making it get the MAC address, although this may be purely incidendal.
When it "has" the MAC address og X.X.X.1, everything actually works! I can access the Internet from the VMs and access them from the internet using their Y.Y.Y.n address. But it doesn't work all the time - occasionally it "forgets" the MAC address of Y.Y.Y.1 again, and becomes inaccessible.
I'm actually surprised it lists Y.Y.Y.1 in the ARP list at all - I thought that was only for devices in the same subnet. My goal was to make them just use the host as gateway address (Y.Y.Y.1) instead and avoid the problem by letting the host to all the communication on X.X.X.0/24.
Is my configuration a sensible one?
Are anyone else using this configuration?
What possible reasons could there be for the weird "forgetfulness"?
UPDATE:
I've tried forcing the VMs to use the datacentre's gateway's MAC address directly instead of the host's for the IP address they use as gateway - Y.Y.Y.1 - but the problem persists:
$ arp -an
? (X.X.X.1) at <incomplete> on eth0
? (Y.Y.Y.1) at c8:60:00:5e:bd:e0 [ether] PERM on eth0
raw@test-server:~$ sudo arp -s Y.Y.Y.1 cc:e1:7f:07:e0:af
raw@test-server:~$ arp -an
? (X.X.X.1) at <incomplete> on eth0
? (Y.Y.Y.1) at cc:e1:7f:07:e0:af [ether] PERM on eth0
raw@test-server:~$ ping -c 4 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
From Y.Y.Y.3 icmp_seq=1 Destination Host Unreachable
From Y.Y.Y.3 icmp_seq=2 Destination Host Unreachable
From Y.Y.Y.3 icmp_seq=3 Destination Host Unreachable
From Y.Y.Y.3 icmp_seq=4 Destination Host Unreachable
--- 8.8.8.8 ping statistics ---
4 packets transmitted, 0 received, +4 errors, 100% packet loss, time 3001ms
pipe 3
Only when there's an ARP entry for X.X.X.1 does it work properly, but I can't add it manually with arp -s (error message: SIOCSARP: Network is unreachable), and I don't know what makes it randomly appear or disappear:
$ arp -an
? (X.X.X.1) at cc:e1:7f:07:e0:af [ether] on eth0
? (Y.Y.Y.1) at cc:e1:7f:07:e0:af [ether] PERM on eth0
raw@test-server:~$ ping -c 4 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=54 time=5.92 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=54 time=6.13 ms
64 bytes from 8.8.8.8: icmp_seq=3 ttl=54 time=6.13 ms
64 bytes from 8.8.8.8: icmp_seq=4 ttl=54 time=6.13 ms
--- 8.8.8.8 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3008ms
rtt min/avg/max/mdev = 5.929/6.083/6.138/0.118 ms
A couple of minutes after this, it went away again:
$ arp -an
? (X.X.X.1) at <incomplete> on eth0
? (Y.Y.Y.1) at cc:e1:7f:07:e0:af [ether] PERM on eth0