Giter VIP home page Giter VIP logo

philippmarcus / geoip-router Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 8 KB

An ipsec/strongswan VPN router in a Docker container that routes international traffic via the ipsec security association, and domestic traffic via the standard internet gateway of the network.

License: MIT License

Shell 77.06% Dockerfile 22.94%
ipsec-vpn geoip docker raspberry-pi router split-tunnel split-tunneling vpn-router

geoip-router's Introduction

Traffic Split Router for a Raspberry Pi 4b based on GeoIP, IPsec, and Docker

This collection of scripts builds and starts a Docker conttainer on a Raspberry Pi 4b in macvlan mode, that acts as a VPN internet router for other PCs in the home network based on the location of the destination. he Raspberry Pi coexists as a router in the same
subnet as the WAN internet router and can be used as a router by individual devices if required. This allows in the best case to consume both, domestic and international streaming/media content all without geolocation restrictions. Roughly, the solution works as follows:

  • A Docker container starts with macvlan mode on the Raspberry Pi 4b
  • The geoip kernel module of the host sysem is loaded in the namespace of the docker conainer
  • Iptables rules are setup to mark all packages to international destinations with the marker 2
  • A policy routing table is setup that per default prohibits all packages with marker 2 unless an ipsec connection is established
  • The updown script of the ipsec connection adds default routes to the policy route table for international packages
  • The traffic selector of the ipsec security association is defined to tunnel packets from the inside ip of thee tunnel (leftsourceip) that have the mark_out=2
  • Accordingly the updown script of the ipsec connection installs a SNAT rule for all routable packets that have a marker 2 towards the inside ip of the tunnel
  • All unmarked packets are forwarded by the container to the default gateway of the home network instead of the tunnel

The solution is tailored for NordVPN but can be adjusted to any other VPN vendor that is ueses IPsec / strongswan. The charm of the solution is that the existing WLAN can continue to be used unchanged. Additionally, the Docker container on the Raspberry Pi is available as an alternative router for individual devices that require the VPN traffic split functionality. Also, the host system of the Raspberry Pi is not modified except for the kernel module that has to be installed (but not loaded on the host). Drawbacks are potential DNS leaks if a domestic DNS server is used, or geolocation blocks imposed on domestic websites if an international DNS server is used (to be added in future releases).

Contents

├── docker_build_run.sh
├── docker_build.sh
├── docker_run.sh
├── geoip-router.conf
├── LICENSE
├── README.md
└── scripts
    ├── Dockerfile
    ├── entrypoint.sh
    ├── ipsec.conf
    ├── ipsec.script.sh
    └── update-geodb.sh

Requirements

The requirements of this setup are as follows:

Most likely the setup also works on other systems, but was only tested on the Raspberry Pi 4b.

Installation

  • Insert your configuration parameters in the file geoip-router.conf
  • Execute bocker_build.sh to build the Docker image, incl. download of the geoip
  • Execute docker_run.sh to start the container as a router, check the connection status with ipsec status
  • Configure your client computers to use the container's IP as Gateway/Router

Even if the setup was tested, here some advices for debugging:

  • If debugging is required, enable in /etc/sysctl.conf the option net.netfilter.nf_log_all_netns=1 and uncomment the iptables logging lines in scripts/entrypoint.sh. See log output on the host with journalctl -f | grep FORWARD
  • Debugging within the Docker container can be done with iptables -L -nv -t mangle to show the packets that matched the marker
  • Also recommended is tcpdump -i eth0

geoip-router's People

Contributors

philippmarcus avatar

Stargazers

 avatar

Watchers

 avatar

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.