ทำไมต้อง WireGuard ไม่ใช่ OpenVPN
ผมใช้ OpenVPN มาตั้งแต่ปี 2008 มันทำงานได้ดี แต่มี 2 ปัญหาหลัก: ช้า (overhead สูง) และ config ยุ่งยาก (ไฟล์ config ยาว 50-100 บรรทัด)
พอลอง WireGuard ครั้งแรก ผมตกใจ — เร็วขึ้น 3-4 เท่า latency ลด 30% config แค่ 15 บรรทัด ตอนนี้ผมย้ายลูกค้าจาก OpenVPN มา WireGuard หมดแล้ว
| เปรียบเทียบ | WireGuard | OpenVPN |
|---|---|---|
| Speed | ~900 Mbps | ~250 Mbps |
| Latency | ต่ำมาก | สูงกว่า 2-3x |
| Code base | ~4,000 บรรทัด | ~100,000 บรรทัด |
| Config | 15 บรรทัด | 50-100 บรรทัด |
| Setup time | 10 นาที | 30-60 นาที |
สิ่งที่ต้องเตรียม
- VPS 1 เครื่อง (Ubuntu 22.04/24.04) — DigitalOcean $5/เดือน ก็พอ
- Public IP ของ VPS
- เครื่อง client (Windows/Mac/Linux/มือถือ)
Step 1: ติดตั้ง WireGuard บน Server
sudo apt update && sudo apt install -y wireguard
# สร้าง keys
wg genkey | tee /etc/wireguard/server_private.key | wg pubkey > /etc/wireguard/server_public.key
chmod 600 /etc/wireguard/server_private.key
# ดู key
cat /etc/wireguard/server_private.key
cat /etc/wireguard/server_public.key
Step 2: Config Server
sudo nano /etc/wireguard/wg0.conf
[Interface]
Address = 10.0.0.1/24
ListenPort = 51820
PrivateKey = <SERVER_PRIVATE_KEY>
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
[Peer]
PublicKey = <CLIENT_PUBLIC_KEY>
AllowedIPs = 10.0.0.2/32
Step 3: Enable IP Forwarding
echo "net.ipv4.ip_forward = 1" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
Step 4: สร้าง Client Config
# สร้าง client keys
wg genkey | tee client_private.key | wg pubkey > client_public.key
สร้างไฟล์ client.conf:
[Interface]
PrivateKey = <CLIENT_PRIVATE_KEY>
Address = 10.0.0.2/24
DNS = 1.1.1.1
[Peer]
PublicKey = <SERVER_PUBLIC_KEY>
Endpoint = <SERVER_IP>:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25
Step 5: เปิด WireGuard
# บน Server
sudo systemctl enable wg-quick@wg0
sudo systemctl start wg-quick@wg0
sudo wg show # ดูสถานะ
# เปิด firewall
sudo ufw allow 51820/udp
บน Client: import client.conf เข้า WireGuard app (มีทุก OS) แล้วกด Connect
Troubleshooting
1. เชื่อมต่อไม่ได้ — เช็ค firewall ว่าเปิด port 51820/udp แล้ว ลอง sudo ufw status
2. เชื่อมได้แต่เน็ตไม่ผ่าน — IP forwarding ยังไม่ enable หรือ PostUp iptables rule ผิด เช็ค interface name (eth0 หรือ ens3)
3. DNS ไม่ resolve — เพิ่ม DNS = 1.1.1.1 ใน client config
4. Handshake ไม่เกิด — public key ของ server/client สลับกัน ตรวจให้ดี server config ใส่ client public key, client config ใส่ server public key
FAQ
Q: WireGuard ปลอดภัยจริงไหม?
ใช้ ChaCha20, Poly1305, Curve25519 ซึ่งเป็น modern cryptography ที่ได้รับการ audit แล้ว code base เล็กมาก (4,000 บรรทัด) ตรวจสอบง่ายกว่า OpenVPN
Q: ใช้ WireGuard ดูหนัง Netflix ต่างประเทศได้ไหม?
ได้ครับ ถ้า VPS อยู่ประเทศนั้น เช่น VPS ที่ US ก็ดู Netflix US ได้ แต่ Netflix อาจ block IP ของ VPS provider บางเจ้า
Q: มือถือใช้ได้ไหม?
ได้ทั้ง iOS และ Android มี app WireGuard อย่างเป็นทางการ scan QR code จาก config ก็เชื่อมต่อได้เลย
สำหรับผู้ที่สนใจเรื่องการลงทุน Forex ดูเพิ่มเติมได้ที่ iCafeForex.com — บทความ Forex จากผู้เชี่ยวชาญ 15 ปี