wireguard
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| wireguard [2021/02/23 07:33] – created baumi | wireguard [2026/08/02 10:15] (current) – baumi | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Wireguard ====== | ====== Wireguard ====== | ||
| - | ===== Install Wireguard on Debian 9.x and Raspbian 10.x ===== | + | ===== Create Key Pairs ===== |
| + | **Host A** | ||
| + | < | ||
| + | root@hosta # wg genkey > privateA | ||
| + | root@hosta # wg pubkey < privateA > publicA | ||
| + | </ | ||
| + | **Host B** | ||
| < | < | ||
| - | # echo "deb http:// | + | root@hostb |
| - | # echo -e " | + | root@hostb |
| - | # apt-get update && apt-get install wireguard-dkms wireguard-tools | + | |
| - | # modprobe wireguard && lsmod | grep wireguard | + | |
| </ | </ | ||
| - | ===== Create | + | ===== Assign Link Network to Wireguard-Tunnel ===== |
| - | Host A | + | Link-Network: |
| + | HostA: 172.24.0.1/ | ||
| + | HostB: 172.24.0.2/ | ||
| + | |||
| + | ===== Create | ||
| + | **Assumption** | ||
| + | Host A is visible to Host B | ||
| + | |||
| + | **Host A** | ||
| < | < | ||
| - | # wg genkey > privateA | + | root@hosta |
| - | # wg pubkey | + | # HostA - HostB |
| + | [Interface] | ||
| + | Address = 172.24.0.1/ | ||
| + | PrivateKey = <contents of privateA> | ||
| + | ListenPort = 51820 | ||
| + | |||
| + | [Peer] | ||
| + | PublicKey = < | ||
| + | AllowedIPs = 172.24.0.2/ | ||
| </ | </ | ||
| - | Host B | + | **Host B** |
| < | < | ||
| - | # wg genkey | + | root@hostb # cat / |
| - | # wg pubkey | + | # HostB - HostA |
| + | [Interface] | ||
| + | Address = 172.24.0.2/ | ||
| + | PrivateKey = < | ||
| + | ListenPort = 51820 | ||
| + | #If something needs to happen after tunnel is up or before tunnel goes down | ||
| + | #PostUp = / | ||
| + | #PreDown = / | ||
| + | |||
| + | [Peer] | ||
| + | PublicKey = < | ||
| + | Endpoint = <visible ip of HostA> | ||
| + | AllowedIPs = 172.24.0.1/ | ||
| + | # Uncomment if HostB is behind NAT Router | ||
| + | # PersistentKeepAlive = 25 | ||
| + | </ | ||
| + | |||
| + | ===== Start Wireguard Tunnel ===== | ||
| + | Issue on both hosts | ||
| + | < | ||
| + | root@hosta | ||
| + | root@hostb # wg-quick up wg0 | ||
| + | </code> | ||
| + | ===== Check Status ===== | ||
| + | **Host A** | ||
| + | < | ||
| + | root@hosta | ||
| + | interface: wg0 | ||
| + | public key: PUBLIC-KEY-A | ||
| + | private key: (hidden) | ||
| + | listening port: 51820 | ||
| + | |||
| + | peer: PUBLIC-KEY-B | ||
| + | endpoint: 185.69.244.140: | ||
| + | allowed ips: 172.24.0.2/ | ||
| + | latest handshake: 1 minute, 44 seconds ago | ||
| + | transfer: 2.80 MiB received, 1.09 MiB sent | ||
| + | </code> | ||
| + | |||
| + | **Host B** | ||
| + | < | ||
| + | root@hostb # wg | ||
| + | interface: wg0 | ||
| + | public key: PUBLIC-KEY-B | ||
| + | private key: (hidden) | ||
| + | listening port: 51820 | ||
| + | |||
| + | peer: PUBLIC-KEY-A | ||
| + | endpoint: 144.76.72.57: | ||
| + | allowed ips: 172.24.0.1/ | ||
| + | latest handshake: 21 seconds ago | ||
| + | transfer: 1006.68 KiB received, 2.57 MiB sent | ||
| + | persistent keepalive: every 25 seconds | ||
| + | </ | ||
| + | |||
| + | ===== Fallback systemd service to call PreDown script ===== | ||
| + | < | ||
| + | root@hostb # cat << EOF > / | ||
| + | [Unit] | ||
| + | Description=WireGuard wg0 shutdown fallback | ||
| + | DefaultDependencies=no | ||
| + | |||
| + | Before=shutdown.target reboot.target halt.target | ||
| + | Before=wg-quick@wg0.service | ||
| + | |||
| + | Conflicts=shutdown.target reboot.target halt.target | ||
| + | |||
| + | After=local-fs.target | ||
| + | |||
| + | [Service] | ||
| + | Type=oneshot | ||
| + | RemainAfterExit=yes | ||
| + | |||
| + | ExecStart=/ | ||
| + | ExecStop=/ | ||
| + | |||
| + | TimeoutStopSec=30 | ||
| + | |||
| + | [Install] | ||
| + | WantedBy=multi-user.target | ||
| + | EOF | ||
| + | root@hostb # systemctl daemon-reload | ||
| + | root@hostb # systemctl enable wg0-shutdown-fallback.service | ||
| + | root@hostb # systemctl start wg0-shutdown-fallback.service | ||
| </ | </ | ||
| + | {{tag>kb linux}} | ||
wireguard.1614062029.txt.gz · Last modified: by baumi
