From f1b289b6b2e1f338e7a558b5ecdfa7e5aeced13c Mon Sep 17 00:00:00 2001 From: angristan Date: Sun, 5 May 2019 12:42:53 +0200 Subject: [PATCH] Initial commit --- .travis.yml | 4 ++++ LICENSE | 20 +++++++++++++++++ README.md | 3 +++ wireguard-install.sh | 53 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 .travis.yml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 wireguard-install.sh diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..a262964 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: shell + +script: + - shellcheck wireguard-install.sh diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..35cbf06 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +MIT License + +Copyright (c) 2019 angristan (Stanislas Lange) + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..d4b3ca3 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Wireguard installer + +WIP. diff --git a/wireguard-install.sh b/wireguard-install.sh new file mode 100644 index 0000000..c6569b2 --- /dev/null +++ b/wireguard-install.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +SERVER_WG_NIC="wg0" +SERVER_PUB_NIC="ens3" +SERVER_WG_IPV4="10.66.66.1" +SERVER_WG_IPV6="fd42:42:42::1" +#SERVER_PUB_IPV4="" +SERVER_PORT=1194 + +CLIENT_IPV4="10.66.66.2" +CLIENT_IPV6="fd42:42:42::2" + +add-apt-repository -y ppa:wireguard/wireguard +apt-get install -y wireguard + +SERVER_PRIV_KEY=$(wg genkey) +SERVER_PUB_KEY=$(echo "$SERVER_PRIV_KEY" | wg pubkey) + +CLIENT_PRIV_KEY=$(wg genkey) +CLIENT_PUB_KEY=$(echo "$CLIENT_PRIV_KEY" | wg pubkey) + +# Add server interface +echo "[Interface] +Address = $SERVER_WG_IPV4/24,$SERVER_WG_IPV6/64 +ListenPort = $SERVER_PORT +PrivateKey = $SERVER_PRIV_KEY +PostUp = iptables -t nat -A POSTROUTING -o $SERVER_PUB_NIC -j MASQUERADE; ip6tables -t nat -A POSTROUTING -o $SERVER_PUB_NIC -j MASQUERADE +PostDown = iptables -t nat -D POSTROUTING -o $SERVER_PUB_NIC -j MASQUERADE; ip6tables -t nat -D POSTROUTING -o $SERVER_PUB_NIC -j MASQUERADE" > /etc/wireguard/$SERVER_WG_NIC.conf + +# Add the client as a peer to the server +echo "[Peer] +PublicKey = $CLIENT_PUB_KEY +AllowedIPs = $CLIENT_IPV4/32,$CLIENT_IPV6/128" >> /etc/wireguard/$SERVER_WG_NIC.conf + +# Create client file with interface +echo "[Interface] +PrivateKey = $CLIENT_PRIV_KEY +Address = $CLIENT_IPV4/24,$CLIENT_IPV6/64" > ~/$SERVER_WG_NIC-client.conf + +# Add the server as a peer to the client +echo "[Peer] +PublicKey = $SERVER_PUB_KEY +Endpoint = $SERVER_PUB_IPV4:1194 +AllowedIPs = 0.0.0.0/0,::/0" >> ~/$SERVER_WG_NIC-client.conf + +# Enable routing on the server +echo "net.ipv4.ip_forward = 1 +net.ipv6.conf.all.forwarding = 1" > /etc/sysctl.d/wg.conf + +sysctl --system + +systemctl start "wg-quick@$SERVER_WG_NIC" +systemctl enable "wg-quick@$SERVER_WG_NIC"