Monday, April 30, 2012

[Bug] adding gateway route but with different subnet from network

I encountered a weird behavior from my recent projects that were related to some setup of gateway servers, for both Linux-based (Debian) and BSD-based (FreeBSD) systems... wherein there is an issue when adding static gateway routes that does not match or fall within the defined subnet network configured on a network interface.

To give a better detail or explanation of this predicament of mine, below is a sample network configuration scenario...
  • Network IP address subnet is 10.10.1.0/24, so that's basically 10.10.1.X correct?
  • Gateway IP address is... let's say 10.50.1.27...
Clearly on the scenario given, the IP address of the gateway is outside of the network subnet defined for a network interface. Here in the Philippines, this is a common case for leased-line internet connections coming from telco providers. 

From previous engagements, I don't have a problem hard-coding this on either the interfaces config file or in the rc.conf... but in the recent turn of events and experience, it seems that the latest linux kernels and BSD builds have incorporated a sort-of mechanism that prohibits this kind of configuration to be enabled and up upon start-up of the operating system. I've experienced this issue with a Debian Squeeze server and a FreeBSD version 8 I think (am not really a BSD proficient guy, just the basic UNIX made me survive).

The setup still works with this kind of interface configuration, but upon boot-up, you have to manual place the static routes (using "route" command) for it to recognize and see the gateway IP you want it to use.

My initial solutions involved adding static routes on the interfaces config or on the rc.conf files.

For Linux-based:

post-up route add -net 10.50.1.27 netmask 255.255.255.255 dev eth0
post-up route add default gw 10.50.1.27
post-down route add 10.50.1.27 netmask 255.255.255.255 dev eth0
post-down route add default gw 10.50.1.27

For BSD:

defaultrouter="10.50.1.27"
static_routes="net1"
route_net1="-net 10.50.1.27/32"

Sadly though, my attempts in fixing the BSD-based system ended up in failure. As for the Linux machine, well I have yet to fully test it out since the project suddenly reached the end without further testing.

Hope this rather weird post of mine helped to shed some light to their problem and looking for an answer.