指南

在 5 分钟内为 VPS 设置 WireGuard VPN

初学者5분 읽기업데이트됨 2026년 5월 30일
간단한 답변

一个可用的 WireGuard 服务器需要四件事:一对密钥、一个 wg0 接口配置、带有 NAT 的 IP 转发,以及每台设备一个 peer 块。在一台 $4 实例上,整个过程大约需要五分钟,并且可以饱和一个千兆端口。

01 WireGuard 설치 및 키 생성

The kernel module is already present on any modern Linux distribution running on KVM.

apt update && apt install -y wireguard
umask 077
wg genkey | tee /etc/wireguard/server.key | wg pubkey > /etc/wireguard/server.pub

02 서버 구성 파일 작성

Replace eth0 with your actual interface name if it differs — check with ip -br link. The Address line defines the tunnel subnet, not your public address.

# /etc/wireguard/wg0.conf
[Interface]
Address = 10.66.66.1/24, fd42:42::1/64
ListenPort = 51820
PrivateKey = <contents of /etc/wireguard/server.key>
PostUp   = nft add table ip nat; nft add chain ip nat post { type nat hook postrouting priority 100 \; }; nft add rule ip nat post oifname "eth0" masquerade
PostDown = nft delete table ip nat

03 포워딩 활성화 및 터널 시작

Forwarding must be enabled for both address families, or IPv6 clients will fail silently.

cat >/etc/sysctl.d/99-wg.conf <<'EOF'
net.ipv4.ip_forward=1
net.ipv6.conf.all.forwarding=1
EOF
sysctl --system
systemctl enable --now wg-quick@wg0
ufw allow 51820/udp

04 각 기기에 대해 피어 추가

Generate a key pair per device. AllowedIPs on the server side is the address that device will hold inside the tunnel — not a range.

wg set wg0 peer <CLIENT_PUBLIC_KEY> allowed-ips 10.66.66.2/32,fd42:42::2/128
wg-quick save wg0

05 클라이언트 구성

AllowedIPs of 0.0.0.0/0 and ::/0 routes all traffic through the tunnel. Narrow it for split tunnelling.

[Interface]
PrivateKey = <client private key>
Address = 10.66.66.2/32, fd42:42::2/128
DNS = 10.66.66.1

[Peer]
PublicKey = <server public key>
Endpoint = YOUR_SERVER_IP:51820
AllowedIPs = 0.0.0.0/0, ::/0
PersistentKeepalive = 25

자주 묻는 질문

VPS 하나로 몇 대의 기기를 처리할 수 있나요?

공유 코어 하나는 20개 이상의 동시 피어를 무리 없이 처리합니다. 제한은 인스턴스가 아니라 업링크입니다.

연결이 느린 이유는 무엇인가요?

거의 항상 MTU 때문입니다. 클라이언트 인터페이스에서 MTU = 1420을 시도하세요. WireGuard는 오버헤드를 추가하여 패킷이 경로 MTU를 초과하고 단편화를 유발할 수 있습니다.