ติดตั้ง Wireguard บน Debian10
1 min read

ติดตั้ง Wireguard บน Debian10

Wireguard คือโปรแกรม vpn แบบ point to point หรือก็คือ ไม่มีตัว centralise แต่ละเครื่องจะติดต่อกันโดยตรงเหมือนเราต่อสายแลนโดยตรง

OS อื่นๆสามารถดูวิธีการติดตั้งได้ที่ https://www.wireguard.com/install/

Step 1 Install Wireguard

apt update
apt install wireguard

Step 2 Config wireguard

Endpoint = IP VPN ไม่ต้องใส่ subnet

Address = IP VPN ใส่ subnet

Endpoint = public-ip

Interface = คือเครื่องต้นทาง

Peer = เครื่องปลายทาง

ให้ใส่คอนฟิกเหมือนกันทุกเครื่อง เปลี่ยนแค่ [Interface]

ตัวอย่างเครื่องที่ 1

cd /etc/wireguard/
wg genkey | tee privatekey | wg pubkey > publickey

[Interface]
Address = 192.168.90.1/24
ListenPort = 51820
PrivateKey = ดูได้จากที่เรา genkey มา

[Peer]
Endpoint = public-ip
PublicKey = ดูได้จากที่เรา genkey มา
AllowedIPs = 192.168.90.1
PersistentKeepalive = 25

[Peer]
Endpoint = public-ip
PublicKey = ดูได้จากที่เรา genkey มา
AllowedIPs = 192.168.90.2
PersistentKeepalive = 25

ตัวอย่างเครื่องที่ 2

cd /etc/wireguard/
wg genkey | tee privatekey | wg pubkey > publickey

[Interface]
Address = 192.168.90.2/24
ListenPort = 51820
PrivateKey = ดูได้จากที่เรา genkey มา

[Peer]
Endpoint = public-ip
PublicKey = ดูได้จากที่เรา genkey มา
AllowedIPs = 192.168.90.1
PersistentKeepalive = 25

[Peer]
Endpoint = public-ip
PublicKey = ดูได้จากที่เรา genkey มา
AllowedIPs = 192.168.90.2
PersistentKeepalive = 25

ตัวอย่าง config เครื่องหนึ่งอยู่หลัง NAT ไม่มี public ip

[Interface]
Address = 192.168.90.1
ListenPort = 51820
PrivateKey = ดูได้จากที่เรา genkey มา

[Peer]
Endpoint = public-ip
PublicKey = ดูได้จากที่เรา genkey มา
AllowedIPs = 192.168.90.1
PersistentKeepalive = 25

[Peer] เครื่องหลัง nat
PublicKey = ดูได้จากที่เรา genkey มา
AllowedIPs = 192.168.90.2
PersistentKeepalive = 25

command สำหรับ up และ down VPN interface

wg-quick up wg0
wg-quick down wg0

Step 3 Autostart WireGuard

systemctl enable wg-quick@wg0.service
systemctl daemon-reload