WireGuard روی VPS: راهاندازی VPN خصوصی
WireGuard یکی از مدرنترین و سریعترین پروتکلهای VPN موجود است که با کدبیس تنها ۴۰۰۰ خط، بسیار سادهتر از OpenVPN بررسی و ممیزی میشود. روی VPS آفشور Anubiz Host در ایسلند یا رومانی، WireGuard یک تانل رمزگذاریشده با تاخیر بسیار پایین ایجاد میکند. این راهنما نصب سرور WireGuard، تنظیم کلاینت و اتصال از ایران را پوشش میدهد.
Need this done for your project?
We implement, you ship. Async, documented, done in days.
نصب WireGuard روی سرور VPS
WireGuard در کرنل لینوکس از نسخه ۵.۶ به بعد تعبیه شده است. برای Ubuntu 22.04:
apt update
apt install -y wireguard
wg genkey | tee /etc/wireguard/server_private.key | wg pubkey > /etc/wireguard/server_public.key
chmod 600 /etc/wireguard/server_private.keyایجاد فایل پیکربندی سرور:
nano /etc/wireguard/wg0.conf[Interface]
Address = 10.0.0.1/24
ListenPort = 51820
PrivateKey = SERVER_PRIVATE_KEY_HERE
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فعالسازی IP forwarding:
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
sysctl -p
systemctl enable wg-quick@wg0
systemctl start wg-quick@wg0اضافه کردن کلاینت WireGuard
برای هر دستگاه کلاینت جفت کلید جداگانه بسازید:
wg genkey | tee client1_private.key | wg pubkey > client1_public.keyاضافه کردن peer به پیکربندی سرور:
nano /etc/wireguard/wg0.conf[Peer]
PublicKey = CLIENT1_PUBLIC_KEY_HERE
AllowedIPs = 10.0.0.2/32فایل پیکربندی برای دستگاه کلاینت:
[Interface]
PrivateKey = CLIENT1_PRIVATE_KEY_HERE
Address = 10.0.0.2/24
DNS = 1.1.1.1, 8.8.8.8
[Peer]
PublicKey = SERVER_PUBLIC_KEY_HERE
Endpoint = VPS_IP:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25اعمال تغییرات بدون قطع اتصال:
wg syncconf wg0 <(wg-quick strip wg0)کلاینت WireGuard برای Android و iOS
سادهترین روش، تبدیل پیکربندی به QR Code است:
apt install -y qrencode
qrencode -t ansiutf8 < /path/to/client1.confبرنامه WireGuard را از Google Play یا App Store نصب کنید، QR Code را اسکن کنید و اتصال را فعال کنید.
بررسی اتصال سرور:
wg show
ping 10.0.0.2WireGuard از پورت UDP 51820 استفاده میکند. در برخی شبکههای ایران UDP ممکن است مسدود باشد؛ در این صورت Shadowsocks یا V2Ray روی TCP بهتر عمل میکنند. پلنهای VPS آفشور Anubiz Host از $4.99 در ماه شروع میشوند.
امنیت و نگهداری WireGuard
محدود کردن دسترسی به پورت WireGuard با UFW:
ufw allow 22/tcp
ufw allow 51820/udp
ufw enableلاگگیری اتصالات:
wg show wg0 latest-handshakesبرای تمدید امنیت، هر ۳ ماه کلیدها را تعویض کنید:
wg genkey | tee /etc/wireguard/server_private_new.key | wg pubkey > /etc/wireguard/server_public_new.keyWireGuard از رمزنگاری Curve25519 برای تبادل کلید، ChaCha20 برای رمزگذاری داده و Poly1305 برای احراز هویت استفاده میکند - جدیدترین الگوریتمهای رمزنگاری موجود.
Related Services
Why Anubiz Host
Ready to get started?
Skip the research. Tell us what you need, and we'll scope it, implement it, and hand it back — fully documented and production-ready.