Ceci est une ancienne révision du document !
Ne pas passer par le VPN pour certains domaines
Certains domaines vérifient, avant de vous autoriser certains accès, que votre IP est bien une IP de votre pays. Si vous passez par un VPN qui vous donne une IP étrangère, cela vous interdit ces accès.
Ou bien, si votre VPN ralentit votre connexion, vous préférez ne pas passer par celui-ci pour télécharger des fichiers (mises à jour de paquets, par exemple).
Voici comment faire :
Ajouter la ligne 9 specialvpn au fichier /etc/iproute2/rt_tables :
echo "9 specialvpn" | sudo tee -a /etc/iproute2/rt_tables
Créez le fichier /etc/novpnfor qui contiendra la liste des domaines concernés (un par ligne). Par exemple :
localhost smtp.free.fr freeplayer.freebox.fr freebox.fr wifi.free.fr www.free.fr sourceforge.net packages.linuxmint.com debian.linuxmint.com ftp.fr.debian.org ppa.launchpad.net download.virtualbox.org www.linuxmint-fr.org fr.archive.ubuntu.com security.ubuntu.com extras.ubuntu.com archive.canonical.com
Ensuite, créez le fichier /etc/network/if-up.d/tun0 contenant :
#!/bin/sh
NOVPNFOR=/etc/novpnfor
IP_ROUTEUR=192.168.0.254
export NOVPNFOR
export IP_ROUTEUR
if [ ! -f $NOVPNFOR ]; then
exit 0
fi
if [ "$IFACE" != "tun0" ]; then
exit 0
fi
RT_TABLE9=$(echo -n $(cat /etc/iproute2/rt_tables | grep specialvpn))
if [ "$RT_TABLE9" = "" ]; then
echo "9 specialvpn" | tee -a /etc/iproute2/rt_tables > /dev/null
fi
if [ ! -f /tmp/novpnfor.tmp ]; then
# echo -n $(stat -c %Y $NOVPNFOR) > /tmp/novpnfor.tmp
touch /tmp/novpnfor.tmp
fi
TSTAMP_OLD="$(cat /tmp/novpnfor.tmp)"
TSTAMP_NEW=$(echo -n $(stat -c %Y $NOVPNFOR))
FIRST_LINE=$(echo -n $(ip route show table specialvpn | tail -1))
echo "TSTAMP_OLD=$TSTAMP_OLD"
echo "TSTAMP_NEW=$TSTAMP_NEW"
if [ "$TSTAMP_NEW" != "$TSTAMP_OLD" ] || [ "$FIRST_LINE" = "" ]; then {
for site in $(cat $NOVPNFOR | tr "\n" " "); do {
#route add -host $site gw 192.168.0.254
for anip in $(host -c IN $site | awk '{print $4}' | tr "\n" " "); do {
if [ "$anip" != "alias" ] && [ "$anip" != "out" ]; then
echo $anip
ip route add $anip via $IP_ROUTEUR table specialvpn
fi
}; done
}; done
echo -n $(stat -c %Y $NOVPNFOR) > /tmp/novpnfor.tmp
}; fi
SPECIALVPN_PRESENT=$(echo -n $(ip rule list | grep specialvpn))
if [ "$SPECIALVPN_PRESENT" = "" ]; then
ip rule add table specialvpn
fi
#service apparmor restart &
exit 0
Rendez ce fichier exécutable :
sudo chmod +x /etc/network/if-up.d/tun0
Enfin, créez le fichier /etc/network/if-post-down.d/tun0 contenant :
#!/bin/sh
NOVPNFOR=/etc/novpnfor2
export NOVPNFOR
if [ ! -f $NOVPNFOR ]; then
exit 0
fi
if [ "$IFACE" != "tun0" ]; then
exit 0
fi
RT_TABLE9=$(echo -n $(cat /etc/iproute2/rt_tables | grep specialvpn))
if [ "$RT_TABLE9" = "" ]; then
echo "9 specialvpn" | tee -a /etc/iproute2/rt_tables > /dev/null
fi
SPEC_VPN=$(echo -n $(ip rule list | grep specialvpn))
if [ "$SPEC_VPN" != "" ]; then
ip rule del table specialvpn
fi
if [ ! -f /tmp/novpnfor.tmp ]; then
touch /tmp/novpnfor.tmp
fi
TSTAMP_OLD="$(cat /tmp/novpnfor.tmp)"
TSTAMP_NEW=$(echo -n $(stat -c %Y $NOVPNFOR))
if [ "$TSTAMP_NEW" != "$TSTAMP_OLD" ]; then
ip route flush table specialvpn
fi
#for site in $(cat $NOVPNFOR | tr "\n" " "); do {
# #echo "$site"
# for anip in $(host -c IN $site | awk '{print $4}' | tr "\n" " "); do {
# #route del -host $site
# if [ "$anip" != "alias" ]; then
# #echo "$anip"
# ip route flush $ip
# fi
# }; done
#}; done
exit 0
Rendez ce fichier exécutable :
sudo chmod +x /etc/network/if-post-down.d/tun0
Vous pouvez tester ces scripts avec les commandes :
sudo route sudo IFACE=tun0 /etc/network/if-up.d/tun0 sudo route sudo IFACE=tun0 /etc/network/if-post-down.d/tun0 sudo route