Skip to content

Instantly share code, notes, and snippets.

@teknoraver
Created November 6, 2019 20:41
Show Gist options
  • Save teknoraver/03557acd658d8c4e7677d10871401d33 to your computer and use it in GitHub Desktop.
Save teknoraver/03557acd658d8c4e7677d10871401d33 to your computer and use it in GitHub Desktop.
#!/bin/sh
lip=192.168.0.1
rip=192.168.0.2
lip2=192.168.1.1
rip2=192.168.1.2
wg genkey >wg1.priv
wg pubkey <wg1.priv >wg1.pub
wg genkey >wg2.priv
wg pubkey <wg2.priv >wg2.pub
ip netns add peer
ip link add name vethwg type veth peer name vethwg netns peer
ip addr add ${lip}/24 dev vethwg
ip -n peer addr add ${rip}/24 dev vethwg
ip link set vethwg up
ip -n peer link set vethwg up
ip link add dev wg0 type wireguard
ip -n peer link add dev wg0 type wireguard
wg set wg0 private-key wg1.priv
ip netns exec peer wg set wg0 private-key wg2.priv
ip addr add ${lip2}/24 dev wg0
ip -n peer addr add ${rip2}/24 dev wg0
ip link set wg0 up
ip -n peer link set wg0 up
localport=$(wg |awk -F': ' '/listening port:/{print$2}')
remoteport=$(ip netns exec peer wg |awk -F': ' '/listening port:/{print$2}')
wg set wg0 peer $(cat wg2.pub) allowed-ips ${rip2}/32 endpoint ${rip}:$remoteport
ip netns exec peer wg set wg0 peer $(cat wg1.pub) allowed-ips ${lip2}/32 endpoint ${lip}:$localport
ip netns exec peer iperf3 -sD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment