vpn_tables.sh

This script is run automatically when a Raspberry Pi, providing VPN service, is rebooting to ensure that the VPN tunnel is well established.

#!/bin/sh -e
# This script is loaded through /etc/network/interfaces
# by inserting a command in wlan0 section: "pre-up /bin/bash /etc/openvpn/vpn_tables.sh"
# It allows to apply the proper routing tables when the device runs Openvpn server
# The address 10.8.0.0/24 must match the IP address defined in /etc/openvpn/server.conf
sleep 10

# IPTABLES FOR VPN
iptables -A  FORWARD -i tun0 -o wlan0 -j ACCEPT
iptables -A FORWARD -i wlan0 -o tun0 -j ACCEPT
iptables -A FORWARD -s 10.8.0.0/24 -j ACCEPT
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o wlan0 -j MASQUERADE

exit 0