Skip to content

Instantly share code, notes, and snippets.

@paulc
Created June 18, 2022 13:46
Show Gist options
  • Save paulc/bd90bbe61fe15de610f5777d1845d512 to your computer and use it in GitHub Desktop.
Save paulc/bd90bbe61fe15de610f5777d1845d512 to your computer and use it in GitHub Desktop.
Configure WG endpoint (Oracle Linux)
#!/bin/sh
# Configure WG endpoint (Oracle Linux)
WG_PRIVATE_KEY=
WG_ADDRESS=
WG_PEER=
WG_PSK=
WG_ALLOWED_IP=
WG_ENDPOINT=
WG_KEEPALIVE=
(
umask 077
# Update
yum update -y
yum upgrade -y
# Enable wireguard
yum install -y wireguard-tools
# Configure WG
cd /etc/wireguard
cat >wg0.conf <<EOM
[Interface]
PrivateKey = ${WG_PRIVATE_KEY}
Address = ${WG_ADDRESS}
[Peer]
PublicKey = ${WG_PEER}
PresharedKey = ${WG_PSK}
AllowedIPs = ${WG_ALLOWED_IP}
Endpoint = ${WG_ENDPOINT}
PersistentKeepalive = ${WG_KEEPALIVE}
EOM
awk '/PrivateKey/ { printf "WG_PUBLIC_KEY :: "; print $3 |"wg pubkey"; exit }' wg0.conf
# IP Forwarding
cat >/etc/sysctl.d/10-forward.conf <<EOM
net.ipv4.ip_forward=1
net.ipv6.conf.all.forwarding=1
EOM
# Firewalld
firewall-cmd --zone=public --add-masquerade --permanent
# Systemd
systemctl enable wg-quick@wg0.service
systemctl start wg-quick@wg0.service
systemctl status wg-quick@wg0.service
) >/config.out 2> /config.err
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment