Skip to content

Instantly share code, notes, and snippets.

@lemmi
Created October 24, 2020 08:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lemmi/103b4348b7f6625cfd5fd0b0917b6b68 to your computer and use it in GitHub Desktop.
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
#!/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