Skip to content

Instantly share code, notes, and snippets.

@amanjuman
Last active September 14, 2021 12:55
Show Gist options
  • Save amanjuman/545d71a93723c1d1783997cbd82f9582 to your computer and use it in GitHub Desktop.
Save amanjuman/545d71a93723c1d1783997cbd82f9582 to your computer and use it in GitHub Desktop.
Demo WireGuard Complete Installation
sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get autoremove -y
sudo apt install software-properties-common && sudo apt install linux-headers-$(uname -r)
sudo apt install wireguard wireguard-dkms wireguard-tools resolvconf -y
wg genkey | sudo tee /etc/wireguard/privatekey | wg pubkey | sudo tee /etc/wireguard/publickey
ifconfig
sudo nano /etc/wireguard/wg0.conf
## WireGuard VPN Server Config File
#Server:
[Interface]
Address = 10.26.26.1/24
ListenPort = 51820
PrivateKey = kLvZTnQERpMLBnN0ArZOkpn/IbxJqoC0h+zQ5IwcrE8=
SaveConfig = true
## Firewall Rules
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
#Client Profile
#Laptop:
[Peer]
Public Key = DKTwMKY7ey8SZsJWYkvFGd4juyNxab6Jve4t4ifyIXE=
AllowedIPs = 10.26.26.2/32
#Android:
[Peer]
Public Key = bX4Jl+/0DzL1tFTmYsRAQ9gQhyj/wCwn/Yz/7OM7rAc=
AllowedIPs = 10.26.26.3/32
sudo wg-quick up wg0
sudo wg show wg0
sudo systemctl enable wg-quick@wg0
sudo nano /etc/sysctl.conf
net.ipv4.ip_forward=1
sudo sysctl -p
ufw alliow 22/tcp
sudo ufw allow 51820/udp
sudo nano /etc/wireguard/wg0.conf
## WireGuard VPN Client Config File
[Interface]
PrivateKey = EL3EbcQ/fwtmWTrjZeQ5BXLW0rZgsS3pH8A7Gh0pA3k=
Address = 10.26.26.2/24
ListenPort = 51820
DNS = 1.1.1.1
MTU = 1412
## VPN Server Public Key
[Peer]
PublicKey = sE6a/qzQV2Ux1qVnfKDIZ9ihfO8YmI3CcWom4wSWaE0=
Endpoint = SERVER-IP:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25
sudo wg set wg0 peer BzOkSfTUifmTAxlvqdi33E5Hv3EwGiG97efKNThnX3k= allowed-ips 10.26.26.4
sudo wg set wg0 peer BzOkSfTUifmTAxlvqdi33E5Hv3EwGiG97efKNThnX3k= allowed-ips 10.26.26.4 remove
Server Public Key: sE6a/qzQV2Ux1qVnfKDIZ9ihfO8YmI3CcWom4wSWaE0=
PrivateKey: kLvZTnQERpMLBnN0ArZOkpn/IbxJqoC0h+zQ5IwcrE8=
Client-1:
Public Key: DKTwMKY7ey8SZsJWYkvFGd4juyNxab6Jve4t4ifyIXE=
Private Key: EL3EbcQ/fwtmWTrjZeQ5BXLW0rZgsS3pH8A7Gh0pA3k=
Client-2:
Public Key: bX4Jl+/0DzL1tFTmYsRAQ9gQhyj/wCwn/Yz/7OM7rAc=
Private Key: uLaa86bKzWv/5J2DvNjAWcoiH1KFQK/X8/E3WwsB7HE=
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment