Created
October 24, 2020 08:04
-
-
Save lemmi/103b4348b7f6625cfd5fd0b0917b6b68 to your computer and use it in GitHub Desktop.
small script to generate a pair of wireguard configurations that can be directly pasted to shell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
genscript() { | |
local PRIV=${1:?"No private key given"} | |
local PUB=${2:?"No public key given"} | |
local OTHER=${3:?"No peer public key given"} | |
local EP=${4:+"endpoint '$4':65534"} | |
local LL=$(echo $PUB | base64 -d | hexdump -n8 -e '"fe80:" 4/2 ":%04x" "/64\n"') | |
echo "ip link add dev wgadhoc type wireguard" | |
echo "ip link set wgadhoc up" | |
echo "ip address add $LL dev wgadhoc" | |
echo "echo $PRIV > /tmp/wgadhoc.$PUB" | |
echo "wg set wgadhoc private-key /tmp/wgadhoc.$PUB" | |
echo "rm /tmp/wgadhoc.$PUB" | |
echo "wg set wgadhoc listen-port 65534" | |
echo "wg set wgadhoc peer $OTHER allowed-ips 0.0.0.0/0,::/0 $EP" | |
echo | |
} | |
A_PRIV=$(wg genkey) | |
A_PUB=$(echo $A_PRIV | wg pubkey) | |
B_PRIV=$(wg genkey) | |
B_PUB=$(echo $B_PRIV | wg pubkey) | |
genscript $A_PRIV $A_PUB $B_PUB $1 | |
genscript $B_PRIV $B_PUB $A_PUB $2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment