Raspberry PI als VPN Gateway

Raspberry PI als VPN Gateway

Ich habe in Januar ein Raspberry Pi Version B gekauft (für ca. 50€)

Den RPI wollte ich eigentlich für meinen alten Fernseher einsetzten damit ich Filme/Fotos/Musik von meinen NAS sehen kann. Leider ist das RPI sehr cool für solche Sachen aber leider nicht damit man sich irgendeinen stream anschaut (leider zu wenig RAM) aber weil ich gerne anonym im Internet surft habe ich mir gedacht bau den RPI doch um in einen VPN Gateway.

Dieses haben ich auch umgesetzt, leider habe ich nicht große Linux Kenntnisse aber es reicht um solche Sachen zu bauen ;-P. Meistens hat man ja auch einen super Support von Forum Member hier nochmal ein danke an Thomas Butz! Der Thomas hat ein cooles Skript für hide.me geschrieben das dein Rasperry komplett einrichtet damit es als eine VPN Gateway fungiert.

Folgendes Skript könnt ihr auf euren RPI ausführen.


#! /bin/bash

###########################################
#          Created by Thomas Butz         #
#   E-Mail: btom1990(at)googlemail.com    #
#  Feel free to copy & share this script  #
###########################################

raspi_client_ip="192.168.2.2" # the IP the Raspberry should use to connect to the router
raspi_client_nm="255.255.255.0" # the netmask of the routers subnet
raspi_client_nw="192.168.2.0" # the network address of the subnet
raspi_client_gw="192.168.2.1" # the IP of your router
raspi_gateway_ip="192.168.2.3" # the IP the clients will use as their gateway

# Your hide.me credentials
username="sample_user"
password="sample_password"

server="https://hide.me/setup/ovpn/type/ovpn/server/17" # Default: Netherlands

# Don't change anything beyond this point
###########################################

# Check for root priviliges
if [[ $EUID -ne 0 ]]; then
   printf "Please run as root:\nsudo %s\n" "${0}"
   exit 1
fi

# Install required packages
apt-get update && apt-get -y install openvpn iptables-persistent

# Create config
cd /etc/openvpn
wget $server -O config.zip
unzip config.zip
rm config.zip
shopt -s nullglob
for f in *.ovpn
do
    sed -i 's/^auth-user-pass$/auth-user-pass user_pass.txt/' $f
    echo 'script-security 2' >> $f
    echo 'up update-resolv-conf' >> $f
    echo 'down update-resolv-conf' >> $f
    rename 's/.ovpn/.conf/' $f
done
cat > user_pass.txt <<EOF
$username
$password
EOF

# Reconfigure interfaces
cat > /etc/network/interfaces <<EOF
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address $raspi_client_ip
gateway $raspi_client_gw
netmask $raspi_client_nm

auto eth0:0
iface eth0:0 inet static
address $raspi_gateway_ip
EOF

# Setup IPTables
iptables -A FORWARD -s $raspi_client_nw/$raspi_client_nm -i eth0:0 -o eth0 -m conntrack --ctstate NEW -j REJECT
iptables -A FORWARD -s $raspi_client_nw/$raspi_client_nm -i eth0:0 -o tun0 -m conntrack --ctstate NEW -j ACCEPT
iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE
iptables-save > /etc/iptables/rules.v4

# Enable IP forwarding
cp /etc/sysctl.conf /etc/sysctl.conf.old
sed -i 's/.*net\.ipv4\.ip_forward=.*/net\.ipv4\.ip_forward=1/' /etc/sysctl.conf

Ich habe dieses nun seit Januar im Einsatz und es funktioniert einwandfrei!

Hoffe das es bei euch auch so gut funktioniert, bei mir funz das alles!

Hier nochmal der Warnhinweis ich nehme keinerlei Verantwortung für meine Tipps & Tricks!!! alles was hier präsentiert wird habe ich aktuell Produktiv und keinerlei Probleme feststellen können. Jeder ist trotzdem dazu verpflichtet alles sorgfältig zu testen.

4 Comments

Avatar photo
Markus Posted on12:56 - 19. March 2015

Hi,

voll gut! Sowas habe ich aktuell auch vor. Wie genau wird der Pi dann bei dir im Netz eingebunden und an welcher Stelle? Er hat ja nur eine Ethernetstelle. Oder läuft das dann übers Wlan? Dank Dir

    Avatar photo
    Mauro Posted on20:58 - 7. May 2015

    Hallo Markus, ich habe ihn vor dem Router also Internet->Router->RPI->Client.

    Im DHCP Server trage ich dann den RPI als Gateway ein.

Avatar photo
Peter Posted on21:49 - 27. March 2016

Hi, link ist dead?:

–2016-03-27 16:48:51– https://hide.me/setup/ovpn/type/ovpn/server/17
Resolving hide.me (hide.me)… 178.62.210.65
Connecting to hide.me (hide.me)|178.62.210.65|:443… connected.
HTTP request sent, awaiting response… 404 Not Found
2016-03-27 16:48:52 ERROR 404: Not Found.
Archive: config.zip
End-of-central-directory signature not found. Either this file is not
a zipfile, or it constitutes one disk of a multi-part archive. In the
latter case the central directory and zipfile comment will be found on
the last disk(s) of this archive.
unzip: cannot find zipfile directory in one of config.zip or
config.zip.zip, and cannot find config.zip.ZIP, period.

Was nun? Danke!

Avatar photo
Mauro Posted on1:28 - 12. December 2019

Moin Peter, entschuldige die verspätete Rückmeldung. Habe das Projekt die Webseite etwas zurück gelegt.

Leider habe ich eine schlechte nachricht für dich, ich habe das Projekt nicht weiter verfolgt. Benutzer heute als alternative zur FritzBox die pfSense. Solltest du dir mal anschauen.

Leave a Reply to Peter Cancel reply


This site uses Akismet to reduce spam. Learn how your comment data is processed.