wireguard
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| wireguard [2021/02/23 07:43] – [Create Config] 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 ===== | ||
| - | |||
| - | < | ||
| - | # echo "deb http:// | ||
| - | # echo -e " | ||
| - | # apt-get update && apt-get install wireguard-dkms wireguard-tools | ||
| - | # modprobe wireguard && lsmod | grep wireguard | ||
| - | </ | ||
| ===== Create Key Pairs ===== | ===== Create Key Pairs ===== | ||
| **Host A** | **Host A** | ||
| < | < | ||
| - | # wg genkey > privateA | + | root@hosta |
| - | # wg pubkey < privateA > publicA | + | root@hosta |
| </ | </ | ||
| **Host B** | **Host B** | ||
| < | < | ||
| - | # wg genkey > privateB | + | root@hostb |
| - | # wg pubkey < privateB > publicB | + | root@hostb |
| </ | </ | ||
| - | {{tag>kb linux}} | ||
| ===== Assign Link Network to Wireguard-Tunnel ===== | ===== Assign Link Network to Wireguard-Tunnel ===== | ||
| - | Link-Network: | + | |
| - | HostA: 172.24.0.1/ | + | HostA: 172.24.0.1/ |
| - | Host2: 172.24.0.2/ | + | HostB: 172.24.0.2/ |
| ===== Create Config ===== | ===== Create Config ===== | ||
| + | **Assumption** | ||
| + | Host A is visible to Host B | ||
| + | |||
| **Host A** | **Host A** | ||
| < | < | ||
| - | # cat / | + | root@hosta |
| # HostA - HostB | # HostA - HostB | ||
| [Interface] | [Interface] | ||
| Line 46: | Line 39: | ||
| **Host B** | **Host B** | ||
| < | < | ||
| - | # cat / | + | root@hostb |
| # HostB - HostA | # HostB - HostA | ||
| [Interface] | [Interface] | ||
| Line 52: | Line 45: | ||
| PrivateKey = < | PrivateKey = < | ||
| ListenPort = 51820 | ListenPort = 51820 | ||
| + | #If something needs to happen after tunnel is up or before tunnel goes down | ||
| + | #PostUp = / | ||
| + | #PreDown = / | ||
| [Peer] | [Peer] | ||
| PublicKey = < | PublicKey = < | ||
| + | Endpoint = <visible ip of HostA> | ||
| AllowedIPs = 172.24.0.1/ | AllowedIPs = 172.24.0.1/ | ||
| # Uncomment if HostB is behind NAT Router | # Uncomment if HostB is behind NAT Router | ||
| Line 62: | Line 59: | ||
| ===== Start Wireguard Tunnel ===== | ===== Start Wireguard Tunnel ===== | ||
| Issue on both hosts | Issue on both hosts | ||
| - | # wg-quick up wg0 | + | < |
| + | root@hosta # wg-quick up wg0 | ||
| + | root@hostb | ||
| + | </ | ||
| ===== Check Status ===== | ===== Check Status ===== | ||
| **Host A** | **Host A** | ||
| < | < | ||
| - | # wg | + | root@hosta |
| interface: wg0 | interface: wg0 | ||
| public key: PUBLIC-KEY-A | public key: PUBLIC-KEY-A | ||
| Line 82: | Line 81: | ||
| **Host B** | **Host B** | ||
| < | < | ||
| - | # wg | + | root@hostb |
| interface: wg0 | interface: wg0 | ||
| public key: PUBLIC-KEY-B | public key: PUBLIC-KEY-B | ||
| Line 96: | Line 95: | ||
| </ | </ | ||
| + | ===== 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.1614062617.txt.gz · Last modified: by baumi
