Skip to content

Instantly share code, notes, and snippets.

@tuna2134
Last active October 3, 2023 16:27
Show Gist options
  • Save tuna2134/023961a7b18961dc885eeded07b83ca1 to your computer and use it in GitHub Desktop.
Save tuna2134/023961a7b18961dc885eeded07b83ca1 to your computer and use it in GitHub Desktop.
Using wireguard with ipv6
INTERFACE=eth0
clear
echo "[+] checking packages" && sudo apt-get update > /dev/null && sudo apt-get install wireguard qrencode jq -y > /dev/null &&
echo "[+] creating keypars" && rm -rf /etc/wireguard/keypars && mkdir /etc/wireguard/keypars &&
wg genkey | sudo tee -a /etc/wireguard/keypars/server.key > /dev/null
sudo cat /etc/wireguard/keypars/server.key | wg pubkey | tee -a /etc/wireguard/keypars/server.pub > /dev/null
wg genkey | tee -a /etc/wireguard/keypars/client.key > /dev/null
sudo cat /etc/wireguard/keypars/client.key | wg pubkey | tee -a /etc/wireguard/keypars/client.pub > /dev/null
echo "[+] creating config files"
sudo cat <<EOF > /etc/wireguard/wg0.conf
[Interface]
PrivateKey=$(cat /etc/wireguard/keypars/server.key)
Address=172.16.42.1, fd86:0000:1111::1
ListenPort=51820
PostUp=iptables -A FORWARD -i wg0 -j ACCEPT && iptables -t nat -A POSTROUTING -o $INTERFACE -j MASQUERADE && ip6tables -A FORWARD -i wg0 -j ACCEPT && ip6tables -A FORWARD -o wg0 -j ACCEPT && ip6tables -t nat -A POSTROUTING -o $INTERFACE -j MASQUERADE
PostDown=iptables -D FORWARD -i wg0 -j ACCEPT && iptables -t nat -D POSTROUTING -o $INTERFACE -j MASQUERADE && ip6tables -D FORWARD -i wg0 -j ACCEPT && ip6tables -D FORWARD -o wg0 -j ACCEPT && ip6tables -t nat -D POSTROUTING -o $INTERFACE -j MASQUERADE
[Peer]
PublicKey=$(cat /etc/wireguard/keypars/client.pub)
AllowedIPs=172.16.42.2, fd86:0000:1111::2
PersistentKeepAlive=30
EOF
sudo cat <<EOF > /etc/wireguard/client.conf.sample
[Interface]
PrivateKey=$(cat /etc/wireguard/keypars/client.key)
Address=172.16.42.2, fd86:0000:1111::2
MTU=1420
DNS=1.1.1.1
[Peer]
PublicKey=$(cat /etc/wireguard/keypars/server.pub)
AllowedIPs=0.0.0.0/0, ::/0
Endpoint=$(curl -sL 'https://api.ipify.org?format=json' | jq .ip | sed 's/"//g'):51820
PersistentKeepAlive=360
EOF
echo "[+] setting up host"
sudo cat /etc/sysctl.conf | sudo sed -i '/net.ipv4.ip_forward=1/c net.ipv4.ip_forward=1' /etc/sysctl.conf
sudo cat /etc/sysctl.conf | sudo sed -i '/net.ipv6.conf.all.forwarding=1/c net.ipv6.conf.all.forwarding=1' /etc/sysctl.conf
sudo sysctl -p > /dev/null
sudo systemctl enable --now wg-quick@wg0
sudo systemctl restart wg-quick@wg0
echo "[+] SCREENING KEYPARE"
echo "------------------< ClientKey >------------------"
cat /etc/wireguard/keypars/client.key
echo -e "\n------------------< ClientPub >------------------"
cat /etc/wireguard/keypars/client.pub
echo -e "\n------------------< ServerPub >------------------"
cat /etc/wireguard/keypars/client.pub
echo -e "\n------------------< ServerPub >------------------"
cat /etc/wireguard/keypars/server.pub
echo ""
echo "[+] SCREENING CLIENT CONFIG"
cat /etc/wireguard/client.conf.sample
echo ""
echo "[+] SCREENING CLIENT QR"
qrencode -t ansiutf8 < /etc/wireguard/client.conf.sample
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment