Differences
This shows you the differences between two versions of the page.
howto:utiliser_la_connexion_vpn_de_la_brique_en_filaire [2017/09/25 17:47] emile add bonus |
howto:utiliser_la_connexion_vpn_de_la_brique_en_filaire [2018/12/08 22:28] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | =====Utiliser le VPN de la brique sur la connexion filaire===== | ||
- | |||
- | Note: Ce tuto a été réalisé sur un réseau de type Livebox mais il est certainement aisé de faire la même chose sur un réseau d'un autre opérateur mainstream. | ||
- | |||
- | ====Phase A - "Désactiver" la Livebox==== | ||
- | |||
- | Pour commencer il nous faut désactiver le dhcp de la livebox. Pour cela il faut aller dans 'configuration avancé', puis 'Configuration réseau', puis 'DHCP', pour avoir le bouton "désactiver". | ||
- | |||
- | {{:howto:dhcp.png}} | ||
- | |||
- | Ensuite nous allons désactiver l'ipv6; cette étape n'est certainement pas nécéssaire mais de toute façon c'est la brique qui va nous donner l'ipv6 de notre FAI asso. Pour cela il faut aller dans 'configuration avancé', puis 'Internet IPv6', pour avoir le bouton "désactiver". | ||
- | |||
- | {{:howto:ipv6.png}} | ||
- | |||
- | ====Phase B - Configurer la brique==== | ||
- | |||
- | ===IP static=== | ||
- | |||
- | Pour commencer il faut mettre un ip(v4) fixe à la brique car notre box ne donne plus d'ip. Pour cela éditez le fichier /etc/network/interfaces comme cela: | ||
- | |||
- | auto lo | ||
- | iface lo inet loopback | ||
- | | ||
- | auto eth0 | ||
- | allow-hotplug eth0 | ||
- | iface eth0 inet static | ||
- | address 192.168.1.2 | ||
- | netmask 255.255.255.0 | ||
- | gateway 192.168.1.1 | ||
- | | ||
- | iface eth0 inet6 static | ||
- | address 2001:xxx:xxx:acab::42 | ||
- | netmask 64 | ||
- | post-up ip a a fe80::42:babe/128 dev eth0 | ||
- | |||
- | auto usb0 | ||
- | allow-hotplug usb0 | ||
- | iface usb0 inet dhcp | ||
- | |||
- | Il faut bien évidement remplacer les xxx pas un réseau donné par votre FAI. | ||
- | |||
- | ===configuration dhcp=== | ||
- | |||
- | Nous allons maintenant configurer le dhcp qui fournira les IPs sur votre réseau filaire. Pour cela il faut ajouter 2 fichiers: | ||
- | |||
- | /etc/dnsmasq.d/dhcpdv4-eth0.conf | ||
- | |||
- | interface=eth0 | ||
- | listen-address=192.168.1.2 | ||
- | dhcp-range=192.168.1.10,192.168.1.200,4h | ||
- | dhcp-option=option:dns-server,80.67.188.188,80.67.169.12 | ||
- | dhcp-authoritative | ||
- | bind-interfaces | ||
- | |||
- | cat /etc/dnsmasq.d/dhcpdv6-eth0.conf | ||
- | |||
- | interface=eth0 | ||
- | listen-address=2001:913:xxx:xxx::42 | ||
- | dhcp-range=2001:913:xxx:xxx::,slaac,64,4h | ||
- | dhcp-option=option6:dns-server,[2001:913::8],[2001:910:800::12] | ||
- | |||
- | |||
- | ===Firewall=== | ||
- | |||
- | Il nous reste à configurer le firewall pour laisser sortir le trafic. Pour cela nous allons utiliser un script qui se lancera au démarrage juste après l'application vpnclient: | ||
- | |||
- | /etc/systemd/system/wiredgw.service | ||
- | |||
- | [Unit] | ||
- | Description=Gateway for wire link | ||
- | Requires=network.target | ||
- | After=ynh-vpnclient.service | ||
- | Wants=ynh-vpnclient.service | ||
- | | ||
- | [Service] | ||
- | Type=oneshot | ||
- | ExecStart=/usr/local/bin/wiredgw start | ||
- | ExecStop=/usr/local/bin/wiredgw stop | ||
- | RemainAfterExit=yes | ||
- | | ||
- | [Install] | ||
- | WantedBy=multi-user.target | ||
- | |||
- | /usr/local/bin/wiredgw | ||
- | |||
- | #!/bin/bash | ||
- | |||
- | case "${1}" in | ||
- | start) | ||
- | # ipv6 | ||
- | ip6tables -w -I FORWARD -i tun0 -o eth0 -j DROP | ||
- | ip6tables -w -I FORWARD -i tun0 -o eth0 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT | ||
- | ip6tables -w -I FORWARD -i eth0 -o tun0 -j ACCEPT | ||
- | ip6tables -w -I FORWARD -i eth0 -o wlan0 -j ACCEPT | ||
- | ip6tables -w -I FORWARD -i wlan0 -o eth0 -j ACCEPT | ||
- | ip6tables -w -I INPUT -i eth0 -j ACCEPT | ||
- | ip6tables -w -I OUTPUT -o eth0 -j ACCEPT | ||
- | |||
- | #IPv4 | ||
- | iptables -w -I FORWARD -i tun0 -o eth0 -j DROP | ||
- | iptables -w -I FORWARD -i tun0 -o eth0 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT | ||
- | iptables -w -I FORWARD -i eth0 -o tun0 -j ACCEPT | ||
- | iptables -w -I FORWARD -i eth0 -o wlan0 -j ACCEPT | ||
- | iptables -w -I FORWARD -i wlan0 -o eth0 -j ACCEPT | ||
- | iptables -w -I INPUT -i eth0 -j ACCEPT | ||
- | iptables -w -I OUTPUT -o eth0 -j ACCEPT | ||
- | ;; | ||
- | stop) | ||
- | # ipv6 | ||
- | ip6tables -w -D FORWARD -i tun0 -o eth0 -j DROP | ||
- | ip6tables -w -D FORWARD -i tun0 -o eth0 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT | ||
- | ip6tables -w -D FORWARD -i eth0 -o tun0 -j ACCEPT | ||
- | ip6tables -w -D FORWARD -i eth0 -o wlan0 -j ACCEPT | ||
- | ip6tables -w -D FORWARD -i wlan0 -o eth0 -j ACCEPT | ||
- | ip6tables -w -D INPUT -i eth0 -j ACCEPT | ||
- | ip6tables -w -D OUTPUT -o eth0 -j ACCEPT | ||
- | | ||
- | # IPv4 | ||
- | iptables -w -D FORWARD -i tun0 -o eth0 -j DROP | ||
- | iptables -w -D FORWARD -i tun0 -o eth0 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT | ||
- | iptables -w -D FORWARD -i eth0 -o tun0 -j ACCEPT | ||
- | iptables -w -D FORWARD -i eth0 -o wlan0 -j ACCEPT | ||
- | iptables -w -D FORWARD -i wlan0 -o eth0 -j ACCEPT | ||
- | iptables -w -D INPUT -i eth0 -j ACCEPT | ||
- | iptables -w -D OUTPUT -o eth0 -j ACCEPT | ||
- | ;; | ||
- | *) | ||
- | echo "Usage: $0 {start|stop}" | ||
- | exit 1 | ||
- | ;; | ||
- | esac | ||
- | |||
- | Puis on fait en sorte que tout démarre au boot: | ||
- | |||
- | systemctl daemon-reload | ||
- | systemctl enable wiredgw.service | ||
- | |||
- | C'est à peu près tout :) on peut rebooter notre brique pour voir si ça fonctionne bien! | ||
- | |||
- | |||
- | ====Phase C - Bonus: IP fixe sur le lan==== | ||
- | |||
- | Si vous voulez mettre des IP fixes dans votre lan (imprimante, mediacenter) vous pouvez ajouter des options à dnsmasq comme ceci: | ||
- | |||
- | dhcp-host=00:10:xx:xx:xx:xx,imprimante,fe80::baba | ||
- | |||
- | Et/ou en v4 | ||
- | |||
- | dhcp-host=00:10:xx:xx:xx:xx,imprimante,192.168.1.3 | ||