Sunday, January 17, 2010

Adding IPs to a Gateway

I've been using a VPN and I want only certain websites to go through the VPN, while the rest through my current connection.

On Linux, after connecting to the VPN, I can make it execute a shell script of my choice, by default named: ip-up.local -- below is my script:

#!/bin/bash
# add domain names to theHosts array -- don't edit anything else
# the script will have each site's IP pass through the gateway of the
# connection being established

theHosts=( pandora.com last.fm hulu.com youtube.com netflix.com )

ips=$(for host in ${theHosts[@]}; do host -4tA $host; done | awk '{print $4}')
for ip in $ips; do /sbin/route add -host $ip gw $4 dev $1; done

ip-up.local should be in /etc/ppp/

Make sure you check the option to tell your connection to not replace your existing default route.

2 comments:

vinnie said...

so its the sameways as connecting to dsl
So does it buffer streaming vids better that way?
Streaming sites suck nowadays

MBH said...

For some reason the latency is 50-100ms less than when connecting normally!

Some sites do require a lot of buffering, others don't spend a lot of time on that.

I did notice that specifying websites doesn't always work. Hulu for example loads its content from IPs other than hulu.com :/