I have a box where an openvpn server is running. This box has two internet
connections, and openvpn answers on both addresses. What I'd like to
accomplish is to somehow have openVPN's answers to incoming connections go
out the same interface they came in. In other words, if a client connects
on eth1, all the traffic to/from that client should use eth1; the same for
eth2. Of course, many clients should be able to connect at the same time.
This article:
http://www.linuxjournal.com/article/7291 seems to suggest
that doing what I want is as easy as setting up two rules, which I did:
# ip rule
0: from all lookup local
20000: from 1.1.1.1 lookup 1
20001: from 2.2.2.2 lookup 2
32766: from all lookup main
32767: from all lookup default
# ip route shot table 1
1.1.1.2 dev eth1 scope link src 1.1.1.1
1.1.1.0/24 dev eth1 proto kernel scope link src 1.1.1.1
default via 1.1.1.2 dev eth1
# ip route show table 2
2.2.2.3 dev eth2 scope link src 2.2.2.2
2.2.2.0/24 dev eth2 proto kernel scope link src 2.2.2.2
default via 2.2.2.3 dev eth2
# ip route show table main
1.1.1.0/24 dev eth1 proto kernel scope link src 1.1.1.1
2.2.2.0/24 dev eth2 proto kernel scope link src 2.2.2.2
default via 1.1.1.2 dev eth1 metric 100
default via 2.2.2.3 dev eth2 metric 100
However, I see erratic behavior in client connections; if a client connects
to 1.1.1.1, everything seems to work fine, but if another client (shortly
after the first) connects to 2.2.2.2, it doesn't get an answer.
My suspicion is that, for the reply packets, for some reason the "main"
routing table is used to lookup the destination, and since the default
route via 1.1.1.2 comes first, that one is used regardless of the incoming
interface.
I know that UDP is stateless, but I would expect that the source address of
the reply packet matches the destination address of the received packet, as
described in the article. That would trigger one of the two routing rules
(20000 or 20001), and the right routing table (and thus outgoing interface)
would be used. Or does it all depend on the application?
I also know that I could run two instances of openvpn, each tied to one
address, and that would solve the problem.
But I was just curious to understand why the way I'm doing it isn't working,
and whether there are ways around it.
Thanks in advance.