geoma
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
Minitutorial de IP fija en VPS a un postcloud self-hosted ==== Por Felix Freeman (Lo esencial) y geoma (El texto) ## Introducción del problema a solucionar Para quienes quieren hostear sus propios servicios y están por ejemplo detrás de un ISP (proveedor de servicio de internet, como VTR, Movistar, GTD, etc.) con CGNAT (como mundopacifico, starlink, etc.) Un CGNAT (Carrier grade Network Access Translator) es como un router pero que está antes de tu casa, en el data center de tu ISP, en otras palabras, le permite a la compañía abaratar costos porque compartes la misma conexión de Internet (y la misma dirección IP, que es el número que identifica a un dispositivo que se conecta a Internet) para varios clientes; es como que tú vendieras de tu internet a tus vecinos y les pasaras un cable por la ventana, van a poder navegar pero no hacer cualquier cosa) A raíz de que compartes con otros clientes de la compañía, no tienes una dirección IP propia, ni puedes hacer "port forwarding", que básicamente es abrir un puerto (como una puerta) en alguno de los computadores de tu casa para que tus amigos o quien quieras se pueda conectar desde afuera, por ejemplo para compartir archivos, o usar servicios web éticos, como alternativa a los servicios de las grandes plataformas que hoy en día intentan (y bastante logran) monopolizar el Internet. Existen muchas posibilidades de solucionar este problema, aquí tienes algunas: https://github.com/anderspitman/awesome-tunneling Sin embargo, aquí intentamos ofrecer una simple y efectiva, sin usar soluciones privativas; solo software libre y ético. ## Requisitos Debes contar con: * Un servidor local en tu casa (puedes reciclar un computador viejo y, para mayor facilidad, instalarle algo como yunohost.org) * Un VPS (te recomendamos algo como zgh.cl o vultr.com, ofrecen buenos precios y ambos tienen servidores en Chile) Entonces esto se trata básicamente de hacer un túnel entre el VPS, que cuenta con una IP fija y permite abrir puertos, y el servidor de tu casa, que cuenta con una conexión muy walala porque el ISP te da una IP compartida y no te permite abrir puertos. ## Requerimientos previos Debes tener los siguientes paquetes instalados, lo más probable (y recomendable) es que tu servidor use Debian, en cuyo caso instalas estos paquetes con `sudo apt install iptables`, por ej., para `iptables`. ### En el VPS `iptables` `wireguard` ### En el servidor local `wireguard` ## Instrucciones Primero debes ejecutar estos pasos en el terminal. Te recomendamos abrir dos ventanas de terminal, una para el servidor local y otra para el vps. A ambas te conectas via SSH, con un comando similar a, por ej.,`ssh root@192.168.1.88` para el servidor local (ojo que tienes que hacerlo desde la misma red, o casa donde tienes el servidor, ya que éste no ofrece acceso desde el exterior, de hecho ése es justamente el problema que estamos intentando solucionar) ### Generar llaves en el VPS ```sh umask 0077 mkdir -p /etc/wireguard cd /etc/wireguard wg genkey > vps.key # generar private key wg pubkey < vps.key > vps.pub # generar public key ``` Ojo, lo que está después del signo `#` es un comentario, no debes incluirlo en el comando. Una vez hecho esto, puedes ejecutar el siguiente comando para que te entregue los valores de todas las keys (llaves) generadas y los copies y pegues a un archivo de texto (así como un torpedo, como le llamamos en Chile) para tener a mano mientras realizas las configuraciones que te indica este tutorial. ```grep "" *``` ### Generar llaves en el servidor local (postcloud) ```sh umask 0077 mkdir -p /etc/wireguard cd /etc/wireguard wg genkey > postcloud.key # generate private key wg pubkey < postcloud.key > postcloud.pub # generate public key wg genpsk > postcloud-vps.psk # generate pre-shared key ``` nuevamente, ejecuta ```grep "" *``` y copia los valores en el archivo de texto que estás usando de torpedo. Edita, en el VPS, el archivo `/etc/wireguard/vps.conf` Debes reemplazar todos los valores entre signos mayor y menor `<>` por los valores que correspondan a situación. reemplazando los valores de llaves `<KEY>` con los valores de llaves públicas (terminadas en `.pub`), privadas (terminadas en `.key`) y pre-shared (terminadasn `.psk`) que tienes anotadas en tu archivo de texto de torpedo. Además de las llaves, deberás ingresar el `<Dispositivo de RED del VPS>`, que es la tarjeta de red o con la cual se conecta el VPS a Internet. Comúnmente será `eth0`, pero también podría ser otro. Con el comando `ip addr` puedes averiguarlo. ```conf [Interface] Address = 10.0.1.1/32 ListenPort = 51820 PrivateKey = <VALOR vps.key del VPS> PostUp = sysctl -w net.ipv4.ip_forward=1 PostUp = sysctl -w net.ipv6.conf.all.forwarding=1 PostUp = iptables -t nat -A PREROUTING -i <Dispositivo de RED del VPS> -p udp --dport 51820 -j ACCEPT PostUp = iptables -t nat -A PREROUTING -i <Dispositivo de RED del VPS> -p tcp --dport 22 -j ACCEPT PostUp = iptables -t nat -A PREROUTING -i <Dispositivo de RED del VPS> -j DNAT --to-destination 10.0.1.2 PostUp = iptables -t nat -A POSTROUTING -o %i -j MASQUERADE PostDown = iptables -t nat -D PREROUTING -i <Dispositivo de RED del VPS> -p udp --dport 51820 -j ACCEPT PostDown = iptables -t nat -D PREROUTING -i <Dispositivo de RED del VPS> -p tcp --dport 22 -j ACCEPT PostDown = iptables -t nat -D PREROUTING -i <Dispositivo de RED del VPS> -j DNAT --to-destination 10.0.1.2 PostDown = iptables -t nat -D POSTROUTING -o %i -j MASQUERADE PostDown = sysctl -w net.ipv4.ip_forward=0 PostDown = sysctl -w net.ipv6.conf.all.forwarding=0 [Peer] PublicKey = <VALOR postcloud.pub del SERVIDOR LOCAL> PresharedKey = <VALOR postcloud-vps.psk del SERVIDOR LOCAL> AllowedIPs = 10.0.1.2/32 ``` Editar, en el servidor local, el archivo `/etc/wireguard/vps.conf` reemplazando los valores según corresponda. Además de las llaves, deberás ingresar la IP fija del VPS donde está indicado. ```conf [Interface] Address = 10.0.1.2/32 PrivateKey = <VALOR vps.key del VPS> [Peer] PublicKey = <VALOR vps.pub del VPS> PresharedKey = <VALOR postcloud-vps.psk del SERVIDOR LOCAL> AllowedIPs = 10.0.1.1/32 Endpoint = <IP del VPS>:51820 PersistentKeepalive = 25 ``` Habilitar los servicios para que corran automáticamente al prender los equipos: ### En el VPS ```sh systemctl enable --now wg-quick@vps ``` ### En el servidor local ```sh systemctl enable --now wg-quick@vps ``` ## Configuración DNS Con eso ya debería estar funcionado. Recuerda también configurar los DNS en tu proveedor de nombre de dominio (ej. namecheap o nic.cl), tanto para el dominio principal como para subdominios (si es que los tienes) ```conf A RECORD * <IP del VPS> A RECORD @ <IP del VPS> A RECORD www <IP del VPS> ```

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully