This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
docu:csheet:net:relays:vpn_wireguard_vps [2023/06/30 00:14] – admin | docu:csheet:net:relays:vpn_wireguard_vps [2023/06/30 01:02] (current) – admin | ||
---|---|---|---|
Line 2: | Line 2: | ||
\\ | \\ | ||
- | In this tutorial | + | En este tutorial |
- | \\ First of all, make sure your both VPS and local PC has ip_forward enabled. You might need to run this on every system start, as (maybe?) it is not saved upon reboot. You can do so on cron, systemd, or directly on / | + | Usaremos " |
+ | |||
+ | \\ | ||
+ | Lo primero de todo, asegurate de que ambos VPS y localpc tienen habilitado el IP forwarding. Quizás necesites ejecutar esto en cada inicio del sistema | ||
<code bash> | <code bash> | ||
echo 1 > / | echo 1 > / | ||
Line 10: | Line 13: | ||
\\ | \\ | ||
- | Second, install | + | Segundo, instala |
<code bash> | <code bash> | ||
apt install wireguard wireguard-dkms | apt install wireguard wireguard-dkms | ||
- | # on some newer distros, | + | # en algunas |
apt install wireguard | apt install wireguard | ||
</ | </ | ||
\\ | \\ | ||
- | Create your Wireguard | + | Crea tus claves |
<code bash> | <code bash> | ||
cd / | cd / | ||
Line 25: | Line 28: | ||
</ | </ | ||
- | Then, configure your server (the VPS) on **/ | + | Ahora configuraremos el Wireguard en el VPS. Editaremos el archivo |
- | Please mind that < | + | |
< | < | ||
[Interface] | [Interface] | ||
- | # The address your wireguard interface will have | + | # La direccción IP que tendrá la interfaz de Wireguard |
Address = 10.5.0.1/32 | Address = 10.5.0.1/32 | ||
- | # We use 443 (UDP) to evade traffic limiting on our residential | + | # Usamos el 443 (UDP) para evadir la limitación de tráfico de los proveedores de internet |
ListenPort = 443 | ListenPort = 443 | ||
- | PrivateKey = <copy the text from " | + | PrivateKey = <copia el contenido de " |
- | # The next line is not needed | + | # La siguiente línea no hace nada (está comentada), es solo una forma de guardar la PublicKey |
- | #PublicKey = <copy the text from " | + | #PublicKey = <copia el contenido de " |
- | # Next, we add some series of " | + | # Lo siguiente, añadiremos una serie de comandos |
- | # Maybe not needed. | + | # Quizás no sea necesario. |
PostUp = ifconfig yoursrv broadcast 10.5.0.255 up | PostUp = ifconfig yoursrv broadcast 10.5.0.255 up | ||
- | # Add the route needed for VPN clients. (Maybe not needed, as i think wireguard already knows how to route to this clients either). | + | # Añade la ruta que especifica por donde llegar a los clientes |
PostUp = ip route add 10.5.0.0/ | PostUp = ip route add 10.5.0.0/ | ||
- | # Totally optional other routes can be added this way | + | # (totalmente opcional) otras rutas por ejemplo se añadirían así. En este caso enrutamos unas redes locales muy comunes por el otro punto de nuestra VPN punto a punto, que en este caso sería " |
#PostUp = ip route add 10/8 via 10.5.0.2 | #PostUp = ip route add 10/8 via 10.5.0.2 | ||
#PostUp = ip route add 192.168/ | #PostUp = ip route add 192.168/ | ||
- | # Optional, maybe useless as your server may already set MTU to 1420 by default | + | # Opcional, quizás inutil porque creo que los servidores |
- | # Keep in mind there is a reason (i don't know) Wireguard | + | |
#PostUp = ifconfig yoursrv mtu 1420 | #PostUp = ifconfig yoursrv mtu 1420 | ||
- | # peer configuration (server side) for your VPN client: localpc | + | # configuración del par VPN para nuestro cliente: localpc |
[Peer] | [Peer] | ||
- | PublicKey = <copy the text from " | + | PublicKey = <copia el contenido de " |
- | # This setting specifies which IPs are allowed to pass to the gateway | + | # Esta conf especifica qué IPs son permitidas para pasar por esta interfaz (en ambas direcciones, |
+ | # Ponemos la IP del peer y luego 0.0.0.0/0 entendiendo que pasará todo tipo de IPs por esta interfaz. | ||
AllowedIPs = 10.5.0.2/ | AllowedIPs = 10.5.0.2/ | ||
PersistentKeepalive = 5 | PersistentKeepalive = 5 | ||
</ | </ | ||
- | Now, on the localpc, | + | Ahora, en el "localpc", modifica el archivo |
< | < | ||
[Interface] | [Interface] | ||
- | # This will be the IP of your localpc | + | # Esta será la IP de la interfaz |
Address = 10.5.0.2/32 | Address = 10.5.0.2/32 | ||
- | PrivateKey = <copy the text from " | + | PrivateKey = <copia el contenido de " |
- | # The next line is not needed (it is commented), is just a way to save the PublicKey in a place you can inspect later for further configurations. | + | # Como he dicho en la anterior configuración del VPS, ponemos esta siguiente línea comentada para tener este valor disponible por si necesitamos configurar otra cosa en adelante. |
- | #PublicKey = <copy the text from " | + | #PublicKey = <copia el contenido de " |
[Peer] | [Peer] | ||
- | # Which IPs are allowed to pass on the interface | + | # Qué IPs son permitidas para pasar por la interfaz (también se usa para enrutar todo el tráfico de salida por esta interfaz). Es extraño Wireguard, no me preguntes como funciona, no lo sé xD |
AllowedIPs = 10.5.0.0/ | AllowedIPs = 10.5.0.0/ | ||
- | PublicKey = <copy the text from " | + | PublicKey = <copia el contenido de " |
- | EndPoint = <IP_of_the_VPS>:443 # remember: 443/ | + | EndPoint = <IP_publica_VPS>:443 # recuerda: 443/ |
PersistentKeepalive = 30 | PersistentKeepalive = 30 | ||
</ | </ | ||
\\ | \\ | ||
- | Then, remove the " | + | Luego, borra los archivos |
<code bash> | <code bash> | ||
cd / | cd / | ||
Line 89: | Line 91: | ||
\\ | \\ | ||
- | Finally, get both interfaces | + | Casi para terminar, levanta las dos interfaces |
<code bash> | <code bash> | ||
- | # on the VPS: | + | # en el VPS: |
- | wg-quick up yoursrv # the manual | + | wg-quick up yoursrv # la forma manual |
- | systemctl enable wg-quick@yoursrv; | + | systemctl enable wg-quick@yoursrv; |
- | # on the localpc: | + | # en el localpc: |
- | wg-quick up whatever # the manual | + | wg-quick up whatever # la forma manual |
- | systemctl enable wg-quick@whatever; | + | systemctl enable wg-quick@whatever; |
- | + | ||
- | # mind we used " | + | |
</ | </ | ||
+ | Fijate que hemos usado el nombre de interfaz " | ||
\\ | \\ | ||
- | If everything is OK, you should be able to ping your VPS from localpc | + | Si todo está bien, deberías poder hacer ping a tu VPS desde el localpc |
<code bash> | <code bash> | ||
ping 10.5.0.1 | ping 10.5.0.1 | ||
- | # Check the wireguard | + | # Comprueba el estado de wireguard |
wg | wg | ||
</ | </ | ||
\\ | \\ | ||
- | To end with this tutorial, you need this final steps too: | + | Y finalmente, para terminar, necesitamos enrutar tráfico para que funcione. Vamos a hacer un ejemplo con enrutamiento de HTTP (que es lo más común) pero esto se usaría igual para cada servicio que queramos enrutar |
- | In order to route some traffic | + | |
<code bash> | <code bash> | ||
- | # route the IN traffic on ports 80,443 TCP to your localpc VPN IP. (You could also use another internal network | + | # ejecutar en " |
- | iptables -t nat -A PREROUTING -d <public_ip_of_VPS> -p tcp -m multiport --dports 80,443 -j DNAT --to-destination 10.5.0.2 | + | iptables -t nat -A PREROUTING -d <ip_public_del_VPS> -p tcp -m multiport --dports 80,443 -j DNAT --to-destination 10.5.0.2 |
+ | |||
+ | # ejecutar en " | ||
+ | iptables -t nat -A POSTROUTING -s 10.5.0.2/32 -o < | ||
- | # Masquerade IP of the VPN localpc when going OUT of the public (internet facing) interface. | ||
- | iptables -t nat -A POSTROUTING -s 10.5.0.2/32 -o < | ||
- | # At the localpc, run this command (this is a " | + | # ejecutar en "localpc": este comando es un " |
iptables -A FORWARD -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu | iptables -A FORWARD -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu | ||
- | # Optionally, if you use a DROP policy on your FORWARD iptables | + | # ejecutar en " |
- | iptables -A FORWARD -i <interface_name_of_public_ip_of_VPS> -d 10.5.0.2 -p tcp -m multiport --dports 80,443 -j ACCEPT | + | iptables -A FORWARD -i <nombre_interfaz_VPS_ip_publica> -d 10.5.0.2/32 -p tcp -m multiport --dports 80,443 -j ACCEPT |
- | iptables -A FORWARD -i < | + | iptables -A FORWARD -i < |
</ | </ | ||
\\ | \\ | ||
- | With all of this, you should now be able to get internet traffic into your localpc | + | Con todo esto, deberías por fin recibir tráfico en tu localpc |