Hello !
D'abord un très grand merci pour ce tuto, c'est tout à fait ce genre d'informations que je cherchais. Et même si j'avais déjà parcouru celui de tech.kanka.ch, celui-ci m'a paru plus clair.
J'ai quelques petites différences, notamment :
- le fournisseur VPN : IPVanish (login/password + certificat) ;
- les interfaces : je dispose de deux ports RJ45 physiques, eth0 et eth1, j'ai donc choisi de remplacer lo:1 par eth1, et j'ai donc connecté ces deux ports à mon switch ;
- l'adresse IP : j'utilise une adresse IP différente, du genre 192.168.150.150 (exemple).
Bref, j'ai un petit souci. Ça ne fonctionne pas ( ^^ qui a dit un gros souci ?! 😛 )
Même si j'ai l'impression que le topic a été déserté, voici ma configuration, des fois qu'une bonne âme expérimentée se promène ici.
- Table de routage VPN créée ;
- /etc/network/interfaces :
auto lo
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet static
address 192.168.20.150
netmask 255.255.255.0
gateway 192.168.20.254
dns-nameservers 192.168.20.254
allow-hotplug eth1
iface eth1 inet static
address 192.168.150.150
netmask 255.255.255.255
- /etc/openvpn/ipvanish.conf
client
dev tun
proto udp
nobind
; pas de modification de la table de routage depuis le serveur
route-nopull
; scripts locaux pour les routes et le client torrent
script-security 2
up /etc/openvpn/up.sh
down /etc/openvpn/down.sh
; host
remote xxxxxx.ipvanish.com 443 # MODIFICATION par xxxxxx uniquement pour ce message
resolv-retry infinite
; authentification
persist-key
persist-tun
persist-remote-ip
ca /etc/openvpn/ca.ipvanish.com.crt # CERTIFICAT IPVanish, placé dans le même répertoire
tls-remote xxxxxx.ipvanish.com # MODIFICATION par xxxxxx uniquement pour ce message
auth-user-pass /etc/openvpn/pass # FICHIER pass avec login et password
comp-lzo
verb 3
auth SHA256
cipher AES-256-CBC
keysize 256
tls-cipher DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:AES256-SHA
; Maintien de la connexion. PING envoyé toutes les 10s, restart si pas de réponse pendant 60s.
keepalive 10 60
- /etc/openvpn/up.sh :
#! /bin/sh
# This script enables policy routing after the tunnel interface is brought up
# Policy routing is used to make sure response packets go through the tunnel interface
# This is mandatory when your ISP has setup anti-spoofing filters
# Créer une chaine iptables nommée SERVICES, renverra un warning sans conséquence si déjà créée.
# Vous pouvez éventuellement supprimer cette directive et la mettre dans un de vos scripts qui se lance au démarrage du système.
iptables -N SERVICES
# Obtenir l'adresse IP donnée par le VPN à tun0, à supposer que votre vpn crée une interface de ce nom.
NET_DEV="tun0"
NET_IP="$(command ifconfig "${NET_DEV}" \
| command grep 'inet ' \
| command sed -e 's/^.*inet [^:]*:\([^ ]*\) .*$/\1/')"
# Add a default route via tun0 into the VPN routing table
ip route add default dev tun0 table VPN
# Pass traffic from eth1 (192.168.150.150) to the VPN routing table, using policy routing ("ip rule" commands)
ip rule add from 192.168.150.150/32 table VPN
# Pass traffic from tun0 IP address to the VPN routing table
ip rule add from ${NET_IP}/32 table VPN
# On ajoute les règles iptables pour faire le NAT
# Source NAT and destination NAT rules
iptables -A PREROUTING -t nat -i tun0 -p tcp --dport 45000-65000 -j DNAT --to 192.168.150.150
iptables -A PREROUTING -t nat -i tun0 -p udp --dport xxxxxx -j DNAT --to 192.168.150.150 # MODIFICATION par xxxxxx uniquement pour ce message
iptables -A POSTROUTING -t nat -o tun0 -j MASQUERADE
# Allow session continuation traffic
iptables -A INPUT -i tun0 -m state --state RELATED,ESTABLISHED -j ACCEPT
# Allow Bittorrent traffic via tun0
iptables -A SERVICES -p tcp --dport 45000-65000 -j ACCEPT # rTorrent random range
iptables -A SERVICES -p udp --dport xxxxxx -j ACCEPT # DHT MODIFICATION par xxxxxx uniquement pour ce message
# Disallow BitTorrent traffic via eth0 - Just to be extra safe [img]/assets/images/smileys/wink.png[/img]
iptables -A FORWARD -s 192.168.150.150/32 -o eth0 -j DROP
# Démarrage de rtorrent
/etc/init.d/xxxxxx-rtorrent start # MODIFICATION par xxxxxx uniquement pour ce message
# Démarrage du script vérifiant que le VPN est toujours actif
killall checkVPN
/usr/bin/checkVPN &
- /etc/openvpn/down.sh :
#! /bin/sh
# This script disables policy routing before the tunnel interface is brought down
#Trouver l'adresse IP affectée à tun0 par le VPN
NET_DEV="tun0"
NET_IP="$(command ifconfig "${NET_DEV}" \
| command grep 'inet ' \
| command sed -e 's/^.*inet [^:]*:\([^ ]*\) .*$/\1/')"
#On arrête le script qui va vérifier l'existence du tunnel VPN
killall checkVPN
#On stoppe rtorrent
/etc/init.d/xxxxxx-rtorrent stop # MODIFICATION par xxxxxx uniquement pour ce message
#On efface les règles iptables ajoutées
iptables -D FORWARD -s 192.168.150.150/32 -o eth0 -j DROP
iptables -D SERVICES -p udp --dport xxxxxx -j ACCEPT # DHT MODIFICATION par xxxxxx uniquement pour ce message
iptables -D SERVICES -p tcp --dport 45000-65000 -j ACCEPT # rTorrent random range
iptables -D INPUT -i tun0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -D POSTROUTING -t nat -o tun0 -j MASQUERADE
iptables -D PREROUTING -t nat -i tun0 -p udp --dport xxxxxx -j DNAT --to 192.168.150.150 # MODIFICATION par xxxxxx uniquement pour ce message
iptables -D PREROUTING -t nat -i tun0 -p tcp --dport 45000-65000 -j DNAT --to 192.168.150.150
# Remove rule for the secondary loopback IP address (192.168.150.150)
ip rule del from 192.168.150.150/32 table VPN
# Remove rule for tun0 IP address
ip rule del from ${NET_IP}/32 table VPN
# Remove rule for the secondary loopback IP address (192.168.150.150)
ip rule del from 192.168.150.150/32 table VPN
# Remove the default route via tun0 from the IPRED routing table
ip route del default dev tun0 table VPN
- /usr/bin/checkVPN :
#! /bin/bash
# PING vers www.google.com toutes les 5 minutes. Si aucun paquet n'est reçu en retour (0 packets received, le 0 est à la position 23 sur la ligne venant de PING) on relance le VPN.
#
while [ 1 > 0 ]; do
sleep 300
T=`ping -I 192.168.150.150 -c 1 www.google.com |grep "packets transmitted"`
if [[ ${T:23:1} != "1" ]]
then
/etc/init.d/openvpn restart
fi
done
- Scripts rendus exécutables ;
- Fichier pass créé avec login en première ligne et password en deuxième ligne, et droits root 700 ;
- /etc/default/openvpn :
#AUTOSTART="all"
#AUTOSTART="none"
AUTOSTART="ipvanish"
- /home/xxxxxx/.rtorrent.rc : # MODIFICATION par xxxxxx uniquement pour ce message
bind = 192.168.150.150
ajouté en première ligne du fichier ;
- /etc/init.d/openvpn :
CONFIG_DIR=/etc/openvpn
OK.
- iptables -L :
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
Chain FORWARD (policy ACCEPT)
target prot opt source destination
DROP all -- 192.168.150.150 anywhere
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain SERVICES (0 references)
target prot opt source destination
ACCEPT udp -- anywhere anywhere udp dpt:xxxxxx # MODIFICATION par xxxxxx uniquement pour ce message
- ps -aux | grep rtorrent :
aucun processus rtorrent
- netstat -lptn | grep rtorrent :
aucune connexion réseau rtorrent
- ifconfig :
eth1 Link encap:Ethernet HWaddr xxxxxx
inet adr:192.168.150.150 Bcast:192.168.150.150 Masque:255.255.255.255
adr inet6: xxxxxx/64 Scope:Lien
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:4997 errors:0 dropped:0 overruns:0 frame:0
TX packets:9 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 lg file transmission:1000
RX bytes:326987 (319.3 KiB) TX bytes:744 (744.0 B)
Interruption:17 Mémoire:f7c00000-f7c20000
tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet adr:172.xxx.xxx.xxx P-t-P:172.xxx.xxx.xxx Masque:255.255.252.0
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:8 errors:0 dropped:0 overruns:0 frame:0
TX packets:8 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 lg file transmission:100
RX bytes:672 (672.0 B) TX bytes:672 (672.0 B)
- route -n :
Table de routage IP du noyau
Destination Passerelle Genmask Indic Metric Ref Use Iface
0.0.0.0 192.168.20.254 0.0.0.0 UG 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth1
172.20.32.0 0.0.0.0 255.255.252.0 U 0 0 0 tun0
192.168.20.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
- ip rule show :
0: from all lookup local
32764: from 172.xxx.xxx.xxx lookup VPN
32765: from 192.168.150.150 lookup VPN
32766: from all lookup main
32767: from all lookup default
- ping -I 192.168.150.150 -c 1
www.google.com :
PING www.google.com (64.233.166.104) from 192.168.150.150 : 56(84) bytes of data.
64 bytes from 64.233.166.104: icmp_seq=1 ttl=45 time=33.4 ms
--- www.google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 33.463/33.463/33.463/0.000 ms
Voilà ce que je peux fournir pour l'instant. Vu l'heure, j'ai aussi le cerveau un peu embué... ^^
Si quelqu'un peut me préciser ce qui bloque dans ma configuration, même sans réponse, ça m'aiguillerait déjà pas mal !
Merci d'avance !!!
[Edit] Première petite bourde dont je viens de me rendre compte, j'avais séparé les ports avec un tiret au lieu de deux points pour les rTorrent random range. C'est modifié dans ma conf. 😛
[Edit 2] Je ne comprends pas. Quand je lance rTorrent manuellement, après avoir démarré OpenVPN, ça a l'air d'être OK.
/etc/init.d/xxxxxxxx-rtorrent start
Starting rtorrent...
- ps -aux | grep rtorrent :
xxxxxxxx 677 0.0 0.0 25660 2568 ? Ss 02:52 0:00 SCREEN -dmS xxxxxxxx-rtorrent rtorrent
xxxxxxxx 678 0.2 0.3 251924 15060 pts/0 Ssl+ 02:52 0:00 rtorrent
- netstat -lptn | grep rtorrent :
tcp 0 0 127.0.0.1:xxxxx 0.0.0.0:* LISTEN 678/rtorrent
tcp 0 0 192.168.150.150:xxxxx 0.0.0.0:* LISTEN 678/rtorrent
Pourquoi OpenVPN ne me le lance pas puisque c'est dans le script ?!?!