Showing posts with label default route. Show all posts
Showing posts with label default route. Show all posts

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.