Skip to content

Instantly share code, notes, and snippets.

@DanielBodnar
Forked from insom/wg-config.bash
Last active September 29, 2019 18:20
Show Gist options
  • Save DanielBodnar/3897391eb5f23b8aa3d06dd2b6922a24 to your computer and use it in GitHub Desktop.
Save DanielBodnar/3897391eb5f23b8aa3d06dd2b6922a24 to your computer and use it in GitHub Desktop.
#!/bin/bash
hosts=("office" "pve" "pve2" "pve3" "therealdaniel")
wg_addrs=("172.28.0.1" "172.28.0.51" "172.28.0.52" "172.28.0.53" "172.28.0.75")
vxlan_addrs=("172.27.0.1" "172.27.0.51" "172.27.0.51" "172.27.0.52" "172.27.0.53" "172.27.0.75")
modprobe ipv6
modprobe udp_tunnel
modprobe ip6_udp_tunnel
ip link add dev wg0 type wireguard
wg setconf wg0 /etc/wireguard/config
wg showconf wg0
brctl addbr internet
brctl stp internet on
ip link set up dev wg0
for i in ${!hosts[@]}; do
hostname=$(echo $hosts[$i] | grep -o '^[a-zA-Z0-9]*')
wg0_ip="${wg_addrs[$i]}"
vxlan_ip="${vxlan_addrs[$i]}"
if "$(uname -n) | grep -o '^[a-zA-Z0-9]*" -eq $hostname; then
ip addr add $wg0_ip dev wg0
ip addr add $vxlan_ip dev internet
else
ip link add $hostname type vxlan remote vxlan_ip id $i dstport 4789
fi
done
sysctl -w net.ipv6.conf.internet.disable_ipv6=0
sudo ip link set up dev internet
for i in ${!hosts[@]}; do
ip link set up $i
brctl addif internet $i
ethtool -K $i tx off
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment