ใช้ VPS เป็นตัวกลางด้วย FRP หรือ WireGuard
แนวคิด
เมื่อคุณมีเครื่องหลัง NAT หรือไม่มี Public IP คุณสามารถใช้ VPS ที่มี Public IP เป็นตัวกลางเพื่อให้เข้าถึงจากภายนอกได้ ด้วยเครื่องมืออย่าง FRP หรือ WireGuard
✨ วิธีที่ 1: ใช้ FRP (Fast Reverse Proxy)
ติดตั้ง FRP
wget https://github.com/fatedier/frp/releases/download/v0.58.0/frp_0.58.0_linux_amd64.tar.gz
tar -xvzf frp_0.58.0_linux_amd64.tar.gz
cd frp_0.58.0_linux_amd64
1. ตั้งค่า VPS (frps)
# ไฟล์: frps.ini
[common]
bind_port = 7000
dashboard_port = 7500
dashboard_user = admin
dashboard_pwd = password
# เริ่มใช้งาน
./frps -c frps.ini
2. ตั้งค่าฝั่งเครื่องบ้าน/หลัง NAT (frpc)
# ไฟล์: frpc.ini
[common]
server_addr = YOUR.VPS.IP
server_port = 7000
[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 6000
# เริ่มใช้งาน
./frpc -c frpc.ini
ทดสอบเชื่อมต่อ
ssh -p 6000 [email protected]
วิธีที่ 2: ใช้ WireGuard VPN
1. ติดตั้ง WireGuard
apt install wireguard -y
2. สร้าง Keypair
wg genkey | tee privatekey | wg pubkey > publickey
3. ตั้งค่า VPS (10.10.0.1)
# /etc/wireguard/wg0.conf
[Interface]
Address = 10.10.0.1/24
PrivateKey = PRIVATEKEY_VPS
ListenPort = 51820
[Peer]
PublicKey = PUBLICKEY_CLIENT
AllowedIPs = 10.10.0.2/32
4. ตั้งค่า Client
# /etc/wireguard/wg0.conf
[Interface]
Address = 10.10.0.2/24
PrivateKey = PRIVATEKEY_CLIENT
[Peer]
PublicKey = PUBLICKEY_VPS
Endpoint = YOUR.VPS.IP:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25
5. เริ่มใช้งาน
wg-quick up wg0
สรุปเปรียบเทียบ
ความต้องการ | FRP | WireGuard |
---|---|---|
Forward Port เฉพาะ | ✅ เหมาะมาก | ❌ ไม่เหมาะ |
VPN เต็มรูปแบบ | ❌ | ✅ เหมาะมาก |
ใช้งานง่าย | ✅ | ✅ |
ใช้ทรัพยากรน้อย | ✅ | ✅ |