meta data for this page
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| linux:vpn:wireguard [2024/12/20 18:28] – niziak | linux:vpn:wireguard [2025/09/23 08:14] (current) – niziak | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Wireguard ====== | ====== Wireguard ====== | ||
| + | |||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | |||
| + | ===== routing ===== | ||
| + | |||
| + | * sending: list of allowed IPs behaves as routing table | ||
| + | * receiving: list of allowed IPs behaves as ACL | ||
| + | |||
| + | ==== mesh ==== | ||
| + | |||
| + | Duplicated peer IPS (allowed IPs): | ||
| + | * not allowed | ||
| + | * technically wg is working but traffic is directed only to last connected peer ??? | ||
| + | |||
| + | The same peer IP (allowed IPs) on 2 or more wg interfaces: | ||
| + | * allowed | ||
| + | * kernel routing makes decision | ||
| + | |||
| + | Best and clear option: | ||
| + | * P2P wg links | ||
| + | * OSPF or other dynamic routing protocol | ||
| + | |||
| + | ==== working example ==== | ||
| + | |||
| + | ''/ | ||
| + | * Kernel: traffic to ''/ | ||
| + | * WG: if routed IP is in '' | ||
| + | * WG: if routed IP belongs to one of known peers, it will route it automatically | ||
| + | Tested on '' | ||
| + | All peers were in one ''/ | ||
| + | |||
| + | NOTE: trying to '' | ||
| + | |||
| ===== Setup ===== | ===== Setup ===== | ||
| Line 8: | Line 42: | ||
| chmod 400 publickey privatekey | chmod 400 publickey privatekey | ||
| </ | </ | ||
| + | |||
| + | ===== Server setup ===== | ||
| <file ini / | <file ini / | ||
| [Interface] | [Interface] | ||
| - | Address = 192.168.x.1/ | + | ListenPort = 12345 |
| - | ListenPort = ... | + | |
| PrivateKey = ... | PrivateKey = ... | ||
| - | SaveConfig | + | |
| + | [Peer] | ||
| + | PublicKey | ||
| + | AllowedIPs = 192.168.1.24/ | ||
| + | |||
| + | [Peer] | ||
| + | PublicKey = ... | ||
| + | AllowedIPs = 192.168.1.25/ | ||
| </ | </ | ||
| Line 22: | Line 64: | ||
| [Interface] | [Interface] | ||
| - | Address = 192.168.x.1/ | ||
| PrivateKey = ... | PrivateKey = ... | ||
| Line 32: | Line 73: | ||
| </ | </ | ||
| - | + | ===== Applying changes | |
| - | ===== Interface autostart | + | |
| - | + | ||
| - | ==== using wgquick service ==== | + | |
| - | + | ||
| - | '' | + | |
| - | <file ini / | + | |
| - | [Interface] | + | |
| - | Address = 192.168.x.1/ | + | |
| - | ListenPort = ... | + | |
| - | PrivateKey = ... | + | |
| - | SaveConfig = true | + | |
| - | PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE; | + | |
| - | PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE; | + | |
| - | </ | + | |
| <code bash> | <code bash> | ||
| - | sudo systemctl enable --now wg-quick@wg0 | + | wg syncconf |
| + | #wg setconf wg0 / | ||
| </ | </ | ||
| - | ==== using ifupdown ==== | + | Note: |
| + | * '' | ||
| + | * '' | ||
| - | <file ini wg0.conf> | + | ===== Interface |
| - | [Interface] | + | |
| - | ListenPort | + | ==== using ifupdown ==== |
| - | PrivateKey | + | |
| - | </ | + | |
| <file / | <file / | ||
| # activate on boot | # activate on boot | ||
| auto wg0 | auto wg0 | ||
| + | |||
| # interface configuration | # interface configuration | ||
| iface wg0 inet static | iface wg0 inet static | ||
| - | address 192.168.x.1/24 | + | address 192.168.1.24/24 |
| pre-up ip link add wg0 type wireguard | pre-up ip link add wg0 type wireguard | ||
| pre-up wg setconf wg0 / | pre-up wg setconf wg0 / | ||
| Line 74: | Line 103: | ||
| post-down ip link del wg0 | post-down ip link del wg0 | ||
| </ | </ | ||
| + | |||
| + | ==== using ifupdown + wgquick ==== | ||
| + | |||
| + | Usefull when client config is generated in '' | ||
| + | |||
| + | <file / | ||
| + | # activate on boot | ||
| + | auto user-tunnel | ||
| + | |||
| + | # interface configuration | ||
| + | iface user-tunnel inet static | ||
| + | address 192.168.1.24/ | ||
| + | pre-up wg-quick up $IFACE | ||
| + | post-down wg-quick down $IFACE | ||
| + | </ | ||
| + | |||
| + | |||
| + | ==== using wgquick service ==== | ||
| + | |||
| + | '' | ||
| + | <file ini / | ||
| + | [Interface] | ||
| + | Address = 192.168.x.1/ | ||
| + | ListenPort = ... | ||
| + | PrivateKey = ... | ||
| + | SaveConfig = true | ||
| + | PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE; | ||
| + | PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE; | ||
| + | </ | ||
| + | |||
| + | <code bash> | ||
| + | sudo systemctl enable --now wg-quick@wg0 | ||
| + | </ | ||