Set source address to use tun device does not work (Debian Squeeze)

Solution 1:

What you are looking for is called "Source based routing" and the old route program can't manage that. You'll need to use iproute2 and set up an alternate routing table based on source IP address. Using the guide here you'll have something like:

# Designate "table 200" as "vpntunnel"
# - optional, but otherwise we'd have to use 200 everywhere.  Also, 200 is an arbitrary number, 0 253 254 255 are reserved.
echo 200 vpntunnel >> /etc/iproute2/rt_tables
# Packets from your tunnel address use this table
ip rule add from 10.30.92.6/32 table vpntunnel
# The default route for packets using the vpntunnel is...
ip route add default via 10.30.92.5 dev tun1 table vpntunnel
# Flush routing cache
ip route flush cache

I'm not sure if you'll need to remove the route from the regular route table before doing this, but it should be OK to leave it (in fact it might be necessary in order to get the kernel to select the right source IP to talk to 10.30.92.5 for apps that don't bind to an IP).