The OP asks if there is any way to set a gateway from a different subnet. I will not delve into best practice discussions, however I've seen this practice quite a few times already and this page still shows up as first result from my searches, without this information in the clear.
the concept
You can set a host from a different subnet as the default gateway by routing to it first. Remember that while there are "safety locks" preventing you to mess around freely with the network, the packet is nothing more than a binary stream, which can have any source address and any destination address. The network devices will receive that and decide what to do with the information they have. A router can take any packet and forward it, with translations or whatnot, to wherever it decides too.
Also consider that routing happens as you send an IP packet, with an external destination on the layer 3 header, to the mac address of your router. A layer 2 device (a simple switch) won't check the IP header, just the mac to which it should forward the packet to. As long as it sends the packet to the right port it will eventually reach the router somehow. The router then will be able to forward it further.
Assuming that the network is set up accordingly, all you need is to make sure that the packet leaves your computer from the right interface. You can do it by creating a route to the gateway network, through one of the interfaces first, then routing whatever you want to that gateway.
the practice
The following ip
commands should do that for you (sorry unix guys, I'm still mostly on linux only and even forgetting stuff about ifconfig
):
ip route add 10.100.0.1/32 dev eth0 src 10.100.10.99
ip route add default via 10.100.0.1
the disclaimer
Just let me enforce that I'm strictly staying out of a best practices discussion here. I'm not a network engineer and far from comfortable in discussing that, it just seemed to be useful to others to share the way I know it can be achieved.