Configuración de VPN con WireGuard (Servidor y Cliente en Linux y Windows)

Skip to main content
< Regresar
Estás aquí:
Imprimir

📌 Objetivo

Implementar una red privada virtual (VPN) utilizando WireGuard, permitiendo comunicación segura entre clientes y servidor en entornos mixtos Linux y Windows.

🧩 Arquitectura

[ Cliente (Windows/Linux) ] <—> [ Servidor WireGuard (Linux recomendado) ]

  • Comunicación cifrada mediante claves públicas/privadas
  • Uso de UDP (por defecto puerto 51820)
  • Red privada virtual (ej: 10.0.0.0/24)

🔐 Conceptos clave

ConceptoDescripción
Private KeyClave privada del nodo
Public KeyClave pública derivada
EndpointIP:Puerto del servidor
AllowedIPsRedes permitidas
InterfaceConfiguración local
PeerNodo remoto

🖥️ 1. Configuración del Servidor (Linux)

Recomendado: Ubuntu 20.04+

📦 Instalación

sudo apt update

sudo apt install wireguard -y

🔑 Generación de claves

mkdir -p /etc/wireguard

cd /etc/wireguard

wg genkey | tee privatekey | wg pubkey > publickey

⚙️ Configuración

nano /etc/wireguard/wg0.conf

🌐 Habilitar forwarding

echo “net.ipv4.ip_forward=1” | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

▶️ Levantar servicio

sudo wg-quick up wg0
sudo systemctl enable wg-quick@wg0

🔍 Ver estado

sudo wg show

💻 2. Configuración Cliente Linux

📦 Instalación

sudo apt update

sudo apt install wireguard -y

🔑 Generación de claves

mkdir -p /etc/wireguard

cd /etc/wireguard

wg genkey | tee privatekey | wg pubkey > publickey

⚙️ Configuración

nano /etc/wireguard/wg0.conf

EJEMPLO:
[Interface]
Address = 10.0.0.2/24
PrivateKey = "CLIENT_PRIVATE_KEY"

[Peer]
PublicKey = "SERVER_PUBLIC_KEY"
Endpoint = "SERVER_IP:51820"
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25

▶️ Levantar servicio

sudo wg-quick up wg0
sudo systemctl enable wg-quick@wg0

🪟 3. Configuración Cliente Windows

📥 Instalación

Descargar desde: 👉 https://www.wireguard.com/install/

Aplicación: WireGuard for Windows

⚙️ Crear túnel

  • Abrir WireGuard
  • Click en “Add Tunnel” → “Add empty tunnel”
  • Se generan claves automáticamente

📝 Configuración

EJEMPLO:

[Interface]
PrivateKey = <CLIENT_PRIVATE_KEY>
Address = 10.0.0.3/24
DNS = 8.8.8.8

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

 

▶️ Activar

  • Click en Activate

🔗 4. Agregar clientes al servidor

nano /etc/wireguard/wg0.conf

[Peer]
PublicKey = <CLIENT_PUBLIC_KEY>
AllowedIPs = 10.0.0.2/32

 

 

# sudo wg syncconf wg0 <(wg-quick strip wg0)

🔥 5. Firewall y puertos

Abrir puerto en servidor:

sudo ufw allow 51820/udp

🧪 6. Pruebas

Desde el cliente:

ping 10.0.0.1

Table of Contents

Deja un comentario