GithubHelp home page GithubHelp logo

netzfisch / rpi-vpn-server Goto Github PK

View Code? Open in Web Editor NEW
34.0 2.0 10.0 28 KB

VPN server for the ARM based Raspberry PI

Home Page: https://hub.docker.com/r/netzfisch/rpi-vpn-server/

License: MIT License

Shell 87.39% Dockerfile 12.61%
vpn-server ipsec docker raspberry-pi

rpi-vpn-server's Introduction

VPN Server Image for the Raspberry PI

Turn your Raspberry PI within 15 minutes into a VPN server allowing remote access and tunneling traffic through your trusted home network!

This images aims at ARM architecture, uses the well known stronSwan IPsec stack, is based on alpine Linux, which is with ~5 MB much smaller than most other distribution base, and thus leads to a slimmer VPN server image.

Build Status

Find the source code at GitHub or the ready-to-run image in the DockerHub and do not forget to star the repository ;-)

Requirements

Setup

  • Install HypriotOS - a Raspbian based debian derivate, which results to a fully working docker host, see Getting Started and download from here!
  • Find the PI, login, change password, update packages, configure static network interface and integrate network storage if needed:
$ nmap -sP 192.168.YOUR.IP/24 | grep black-pearl
$ ssh [email protected]
$ passwd
$ sudo apt-get update && sudo apt-get upgrade
$ sudo apt-get install nfs-common
$ cat > /etc/network/interfaces.d/eth0 << EOF
  allow-hotplug eth0
  iface eth0 inet static
    address 192.168.PI.IP
    netmask 255.255.255.0
    gateway 192.168.XXX.XXX
  EOF
$ echo "192.168.NAS.IP:/nfs/Public /mnt nfs auto  0 0" >> /etc/fstab
  • Configure your router for dynamic DNS updates or use rpi-dyndns.
  • Enable port forwarding at your firewall for 192.168.PI.IP and the UDP ports 500 and 4500

Usage

Get ready to roll and run the container:

$ docker run --name vpnserver \
             --env HOSTNAME=your.domain.com \
             --env VPN_USER=name \
             --env VPN_PASSWORD=secret \
             --cap-add NET_ADMIN \
             --publish 500:500/udp \
             --publish 4500:4500/udp \
             --volume /host-directory-of-secrets:/mnt \
             --restart unless-stopped \
             --detach \
             netzfisch/rpi-vpn-server

In the local host-directory /host-directory-of-secrets you will find the encrypted PKCS#12 archive userCert.p12 and the userP12-XAUTH-Password.txt file - be patient may take up to 2 minutes until everything is generated! Import userCert.p12 (unlocked by userP12-XAUTH-Password.txt) into your remote system, e.g. use

  • Android - Install strongSwan and add new profil.
  • Linux - Install network-manager.
  • macOS X - Open Keychain App and import the PKCS#12 file into the system-keychain (not login) and mark as "always trusted". Than go to [Network Settings] > [Add Interface] > [VPN (IKEv2)] and enter the credentials:
    • ServerAdress = HOSTNAME
    • RemoteID = HOSTNAME
    • LocalID = VPN_USER
    • AuthenticationSettings = Certificate of VPN_USER

Thats all - everything below is optional!

The userP12-XAUTH-Password.txt will be also used as key for XAUTH scenarios!

Dynamic DNS Updates

If you want to go wild and use the VPN access in conjunction with rpi-dyndns for dynamic DNS updates, just run it with docker-compose

$ curl https://raw.githubusercontent.com/netzfisch/rpi-dyndns/master/docker-compose.yml -o rpi-vpn-server.yml
$ env HOSTNAME=your.domain.com \
      UPDATE_TOKEN=imwg-futl-mzmw \
      VPN_USER=name \       # optional, leave away and to
      VPN_PASSWORD=secret \ # import existing secretes later!
      VPN_HOSTDIR=/host-directory-of-secrets \
      docker-compose -f rpi-vpn-server.yml up -d

Done!

Manage

For manual configuration of hostname, user, password, certificates, and keys you have the following options.

Create Root-Authority and Server-Credentials

Start the container without the environment variables and than execute the setup script with the host option to create the appropriate server secrets:

$ docker run --name vpnserver \
             --cap-add NET_ADMIN \
             --publish 500:500/udp \
             --publish 4500:4500/udp \
             --volume /host-directory-of-secrets:/mnt \
             --restart unless-stopped \
             --detach \
             netzfisch/rpi-vpn-server
$ docker exec vpnserver setup host your-subdomain.spdns.de

Attention you do this normally only once, cause a second run will invalidate credentials ... be warned!

Add User

Starting the setup script with the option user and values for name and password will create additional user secrets:

$ docker exec vpnserver setup user VpnUser VpnPassword

If you do not set the password value a random one will be assigned!

Export/Import Secrets

To export do $ docker exec vpnserver secrets export and you will find all certificates, keys, p12-archive and userP12-XAUTH-Password.txt in the local host directory /host-directory-of-secrets.

To import put your set of secrets into the mounted volume /host-directory-of-secrets and execute:

$ docker exec vpnserver secrets import HostUrl VpnUser SecretPassword

Attention make sure not to change naming of CA-, Cert- and Key-files, otherwise the import might not work!

Debugging

If you have trouble, check on the running container:

  • First look at the logs $ docker logs -f vpnserver,
  • get the ipsec status $ docker exec vpnserver ipsec statusall or
  • go into for further investigation $ docker exec -it vpnserver ash, than check following commands to debug for a working configuration:
$ ipsec statusall / swanctl -L / swanctl -l
$ route -n
  Kernel IP routing table
  Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
  0.0.0.0         172.17.0.1      0.0.0.0         UG    0      0        0 eth0
  172.17.0.0      0.0.0.0         255.255.0.0     U     0      0        0 eth0
$ iptables -t nat -L
  Chain PREROUTING (policy ACCEPT)
  target     prot opt source               destination
  Chain INPUT (policy ACCEPT)
  target     prot opt source               destination
  Chain OUTPUT (policy ACCEPT)
  target     prot opt source               destination
  Chain POSTROUTING (policy ACCEPT)
  target     prot opt source               destination
  MASQUERADE  all  --  anywhere             anywhere # <= IMPORTANT!
$ vi /etc/ipsec.conf
$ ipesc restart

If your routing is messed up (compare with above, you just NEED those TWO), flush routes $ routef and start over, see also strongSwan introduction, ipsec.onf parameters, configuration examples and forwarding + split tunneling for details!

If all not helps, export the whole container $ docker export vpnserver > vpn-server.tar and examine the file system.

Contributing

If you find a problem, please create a GitHub Issue.

Have a fix, want to add or request a feature? Pull Requests are welcome!

TODOs

  • all good!

License

The MIT License (MIT), see LICENSE file.

rpi-vpn-server's People

Contributors

netzfisch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

rpi-vpn-server's Issues

Unstable run/start/stop behaviour

tldr; step 1 and mostly step 4 have incorrect behaviour.

Step 1:
docker run --name vpnserver
--env HOSTNAME=your.domain.com
--env VPN_USER=name
--env VPN_PASSWORD=secret
--cap-add NET_ADMIN
--publish 500:500/udp
--publish 4500:4500/udp
--volume /vpn-secrets:/mnt
netzfisch/rpi-vpn-server

omitted --restart unless-stopped and --detach for debug purposes.

Expected: up and running vpn container.
Actual result: container shutsdown with "starter is already running (/var/run/starter.charon.pid exists) -- no fork done" error.

Step 2:
docker start vpnserver

Expected: up and running vpn container.
Actual result: up and running vpn container. (Tested by connecting with Android client)

Step 3:
docker stop vpnserver

Expected: stopped vpn container.
Actual result: stopped vpn container.

Step 4:
docker start vpnserver

Expected: up and running vpn container.
Actual result: container shutsdown with "starter is already running (/var/run/starter.charon.pid exists) -- no fork done" error.

Even after rebooting the PI, every "docker start vpnserver" will give "starter is already running (/var/run/starter.charon.pid exists) -- no fork done" error. Therefore it is impossible to really use this docker image.

mv -force

docker exec vpnserver setup user vpnuser password

mv: unrecognized option: force
BusyBox v1.23.2 (2015-04-25 06:52:59 GMT) multi-call binary.

Usage: mv [-fin] SOURCE DEST
or: mv [-fin] SOURCE... DIRECTORY

Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY

    -f  Don't prompt before overwriting
    -i  Interactive, prompt before overwrite
    -n  Don't overwrite an existing file

Stopping strongSwan IPsec...

i use
Linux black-pearl 4.4.15-hypriotos+ #2 PREEMPT Mon Jul 25 09:18:11 UTC 2016 armv6l GNU/Linux

Raspberry Pi (c)2011.12

From @linbrown on April 26, 2016 19:52

This may not be an issue. I have an older version of Raspberry PI (PCB says: "Raspberry Pi (c)2011.12"). I tried to install the VPN and does not quite work (client cannot connect in. I tried from Windows and from iPhone). Do you know if the VPN can work on the version of Raspberry PI I have? The Docker container runs and VPN server responses.

I just have not got into details about how StrongSwan VPN works. I believe that I did not get authentication settings right. Any help is appreciated. Thanks!

Copied from original issue: netzfisch/rpi-tvheadend#1

Zero instructions in readme about how to connect to VPN Server after creation?

Can you kindly tell me how to connect to the OpenVPN server after creating the keys and certificate files? I thought it would be related enough that it would be included in the readme but don't see anything written unless i'm missing something.

OpenVPN require .ovpn or .conf files. Is there any way to easiely create these after creating server credentials?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.