Using DNS in iproute2

debian-squeezedomain-name-systemiproute2

In my setup I can redirect the default gateway based on the source address. Let's say a user is connected through tun0 (10.2.0.0/16) is redirect to another vpn. That works fine!

ip rule add from 10.2.0.10 lookup vpn1

In a second rule I redirect the default gateway to another gateway if the user access a certain ip adress:

ip rule add from 10.2.0.10 to 94.142.154.71 lookup vpn2

If I access the page on 94.142.154.71 (myip.is) the user is correctly routed and I can see the ip of the second vpn. On any other pages the ip address of vpn1 is shown.

But how do I tell iproute2 that all request at e. g. google.com should be redirected through vpn2?

Best Answer

There is a good chance that an A-Record resolves to multiple ip addresses:

% dig +short google.com
209.85.148.101
209.85.148.102
209.85.148.113
209.85.148.138
209.85.148.139
209.85.148.100

So you have to loop through them and add a rule for each of them like this

dig +short google.com | while read IP; do
  ip rule add from 10.2.0.10 to "$IP" lookup vpn2
done

Also you should think about a refresh cronjob.

Related Topic