Giter VIP home page Giter VIP logo

wireguard-vpn-masquerade's Introduction

wireguard-vpn-masquerade

Build Status GPL 3+

Generate a WireGuard VPN tunnel configuration to allow multiple clients access to the internet via a server.
Copyright (C) 2019 Christian Garbs [email protected]
Licensed under GNU GPL v3 (or later)
Homepage: https://github.com/mmitch/wireguard-vpn-masquerade

nomenclature

This guide talks about three different actors that are part of the whole:

  • The server is the system where the VPN tunnel ends and the client's traffic emerges into the internet. It needs a static IP address or name resolvable by DNS so the clients know where to connect to.

  • A client is a device that uses the VPN tunnel to connect to the internet. It can be a laptop, a desktop pc or a mobile device.

  • The configurator is the host that wg-conf runs on. It can be run on the server or on a client or a completely different system. Private keys will be kept here and the generated configuration must be copied to the server and clients eventually. Because the wg(8) binary is needed, the server is a good candidate for the configurator.

schematic

................
:              :                .------.
: client 1 <----VPN-TUNNEL----> |      |
:              :                |      |           __ ,-. 
:              :                |      |          (  "   \ 
: client 2 <----VPN-TUNNEL----> |      | <-----> (      `  )
:              :                |      |          `--_____"
:              :                |      |           internet
: client 3 <----VPN-TUNNEL----> |      |
:              :                `------'
:              :                 server
: evil network :
:..............:

configuration

On the configurator:

  1. edit wg-conf.server and include your network configuration
  2. edit wg-conf.clients and include all your clients

In both cases, replace every PRIVATE-KEY placeholder with the result of wg genkey. Run it once for every client so that all keys are different.

  1. run wg-conf server and copy the generated configuration to your server
  2. run wg-conf client for all clients and copy the configuration to your clients
    • for mobile clients run wg-conf qr instead and scan the generated QR code from the app

If your clients change, repeat steps 2 to 4 from above: edit wg-conf.clients and re-generate the configuration for both the server and any changed client.

git integration

Be aware that both wg-conf.server and wg-conf.clients have been added to .gitignore so that you don't accidentially check in your configuration and reveal it to the world.

If you want to check in your configuration anyways, you can use git add --force.

Better yet: set up a local branch for your local configuration, remove both files from .gitignore in that branch and check in your configuration. Then merge (or rebase) any official changes from the master branch as needed.

setup

These things have to be done only once.

configurator setup

  1. install wireguard-vpn-masquerade (eg. github clone https://github.com/mmitch/wireguard-vpn-masquerade)
  2. install wg(8)
    • either install full wireguard (see server setup)
    • or just copy the wg binary from the server if possible (wg(8) is only needed for wg genkey and wg pubkey)
  3. install qr-encode (eg. apt install qrencode) if you want to generate QR codes for mobile clients

server setup

  1. install wireguard, see https://www.wireguard.com/install/
    For me, the following worked on Debian Buster:

    echo "deb http://deb.debian.org/debian/ unstable main" > /etc/apt/sources.list.d/unstable.list
    printf 'Package: *\nPin: release a=unstable\nPin-Priority: 90\n' > /etc/apt/preferences.d/limit-unstable
    apt update
    apt install wireguard
  2. activate masquerading

    • when using nftables, it is something like this:
      table ip nat {
              chain prerouting {
                      type nat hook prerouting priority 0; policy accept;
              }
              chain postrouting {
                      type nat hook postrouting priority 100; policy accept;
                      oifname ++EXTERNAL_INTERFACE++ masquerade
              }
      }
      
    • when using iptables, that would be
      iptables -t nat -A POSTROUTING -o ++EXTERNAL_INTERFACE++ -j MASQUERADE

    In both cases ++EXTERNAL_INTERFACE++ must be replaced with the name of the external interface on your server.

  3. activate forwarding

    • to try it out once, use
      echo "1" > /proc/sys/net/ipv4/ip_forward
    • for a persistent configuration, look at /etc/sysctl.conf and add
      net.ipv4.ip_forward=1
      

client setup

  1. install wireguard
    • for mobiles, install the app
    • otherwise see server setup above

wireguard-vpn-masquerade's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

wireguard-vpn-masquerade's Issues

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.