1
1
mirror of https://github.com/angristan/wireguard-install.git synced 2024-11-21 20:25:14 +00:00

Initial commit

This commit is contained in:
angristan 2019-05-05 12:42:53 +02:00
commit f1b289b6b2
4 changed files with 80 additions and 0 deletions

4
.travis.yml Normal file
View File

@ -0,0 +1,4 @@
language: shell
script:
- shellcheck wireguard-install.sh

20
LICENSE Normal file
View File

@ -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.

3
README.md Normal file
View File

@ -0,0 +1,3 @@
# Wireguard installer
WIP.

53
wireguard-install.sh Normal file
View File

@ -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"