Skip to content

Instantly share code, notes, and snippets.

@jayluxferro
Last active August 21, 2023 23:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jayluxferro/010fe22c6c1710829d9a4517ba6e3290 to your computer and use it in GitHub Desktop.
Save jayluxferro/010fe22c6c1710829d9a4517ba6e3290 to your computer and use it in GitHub Desktop.
WireGuard Installer
#!/bin/bash
if [ $(whoami) != 'root' ]; then
echo 'Please run as root'
exit 1
fi
# install wireguard
apt install resolvconf wireguard wireguard-tools -y
# generate public and private key
cFile='wg0.conf'
cd /etc/wireguard/
umask 0777
wg genkey | tee privatekey | wg pubkey > publickey
touch $cFile
privKey=$(cat /etc/wireguard/privatekey)
echo '
[Interface]
Address = 10.0.0.1/24
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE; iptables -A FORWARD -o %i -j ACCEPT
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE; iptables -D FORWARD -o %i -j ACCEPT
DNS = 9.9.9.9
ListenPort = 51444
PrivateKey = '$privKey'
' > $cFile
# set permissions
chmod 755 *
# enable wireguard on boot
systemctl enable wg-quick@wg0
wg-quick up wg0
echo 1 > /proc/sys/net/ipv4/ip_forward
echo '[+] Done. Enable IPv4 forwarding'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment