vi

Tự Cài VPN Server trên VPS: WireGuard và OpenVPN

Tự cài VPN server trên VPS offshore AnubizHost cho phép bạn kiểm soát hoàn toàn kết nối internet của mình. Không có nhà cung cấp VPN trung gian, không có log chia sẻ với bên thứ ba. WireGuard nhanh hơn và đơn giản hơn OpenVPN, trong khi OpenVPN tương thích rộng hơn với mọi thiết bị.

Need this done for your project?

We implement, you ship. Async, documented, done in days.

Start a Brief

Cài Đặt WireGuard VPN Server

WireGuard là VPN protocol hiện đại, nhanh và bảo mật. Cài bằng script tự động:

wget https://git.io/wireguard -O wireguard-install.sh
bash wireguard-install.sh

Hoặc cài thủ công:

apt install -y wireguard

# Tạo server keys
wg genkey | tee /etc/wireguard/server_private.key | wg pubkey > /etc/wireguard/server_public.key
chmod 600 /etc/wireguard/server_private.key

# Tạo client keys
wg genkey | tee /etc/wireguard/client_private.key | wg pubkey > /etc/wireguard/client_public.key

Cấu Hình WireGuard Server

Tạo file cấu hình server:

nano /etc/wireguard/wg0.conf
[Interface]
PrivateKey = SERVER_PRIVATE_KEY_HERE
Address = 10.0.0.1/24
ListenPort = 51820
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_HERE
AllowedIPs = 10.0.0.2/32

Kích hoạt IP forwarding:

echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
sysctl -p

systemctl enable wg-quick@wg0
systemctl start wg-quick@wg0
ufw allow 51820/udp

Cài Đặt OpenVPN Server

OpenVPN tương thích với hầu hết thiết bị và hệ điều hành. Dùng script tự động:

wget https://git.io/vpn -O openvpn-install.sh
bash openvpn-install.sh

Script sẽ hỏi:

  • IP address của server
  • Protocol (UDP khuyến nghị)
  • Port (mặc định 1194)
  • DNS (Cloudflare 1.1.1.1 hoặc tùy chọn)
  • Tên client

Sau khi xong, file .ovpn được tạo để import vào OpenVPN client.

# Xem trạng thái
systemctl status openvpn@server

# Thêm client mới
bash openvpn-install.sh

So Sánh WireGuard vs OpenVPN

Chọn protocol phù hợp với nhu cầu của bạn:

WireGuard:

  • Tốc độ cao hơn, latency thấp hơn
  • Cấu hình đơn giản hơn
  • Code base nhỏ hơn, ít lỗ hổng hơn
  • Hỗ trợ tốt trên Linux, macOS, iOS, Android
  • Nhược điểm: ít options cấu hình phức tạp hơn

OpenVPN:

  • Tương thích với mọi thiết bị và hệ điều hành
  • Nhiều lựa chọn cấu hình (obfuscation, TCP mode)
  • Vượt tường lửa tốt hơn (có thể dùng TCP port 443)
  • Nhược điểm: chậm hơn, cấu hình phức tạp hơn

Khuyến nghị: WireGuard cho kết nối tốc độ cao cá nhân, OpenVPN khi cần vượt firewall chặt.

Why Anubiz Host

100% async — no calls, no meetings
Delivered in days, not weeks
Full documentation included
Production-grade from day one
Security-first approach
Post-delivery support included

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.

Anubiz Chat AI

Online