Por Que WireGuard?

O WireGuard é um protocolo VPN moderno e de alto desempenho projetado para simplicidade, velocidade e segurança forte.

Pré-requisitos

  • Um servidor Linux com IP público.
  • Acesso root ou sudo.
  • Porta UDP 51820 aberta no firewall do servidor.

Solução Passo a Passo

1. Instalar WireGuard

sudo apt update && sudo apt install -y wireguard

2. Gerar Pares de Chaves

wg genkey | tee /etc/wireguard/private.key | wg pubkey > /etc/wireguard/public.key
chmod 600 /etc/wireguard/private.key

3. Configurar o Servidor

[Interface]
Address = 10.0.0.1/24
ListenPort = 51820
PrivateKey = <CHAVE_PRIVADA_SERVIDOR>
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 = <CHAVE_PUBLICA_CLIENTE>
AllowedIPs = 10.0.0.2/32

4. Configurar o Cliente

[Interface]
Address = 10.0.0.2/24
PrivateKey = <CHAVE_PRIVADA_CLIENTE>
DNS = 1.1.1.1

[Peer]
PublicKey = <CHAVE_PUBLICA_SERVIDOR>
Endpoint = <IP_PUBLICO_SERVIDOR>:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25

Solução de Problemas

  • Sem handshake: Verifique firewall, chaves e encaminhamento de IP.
  • Vazamento DNS: Adicione DNS = 1.1.1.1 à seção [Interface] do cliente.
  • Sem internet: Verifique as regras PostUp de iptables e o nome da interface de rede.

Resumo

  • WireGuard é um protocolo VPN moderno integrado ao kernel Linux desde a versão 5.6.
  • Use PersistentKeepalive = 25 para clientes atrás de NAT.

Artigos Relacionados