meta data for this page
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
linux:vpn:wireguard [2021/10/27 20:17] – created niziak | linux:vpn:wireguard [2025/01/07 20:42] (current) – niziak | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Wireguard ====== | ====== Wireguard ====== | ||
- | ===== Server setup ===== | + | * [[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 ===== | ||
<code bash> | <code bash> | ||
Line 9: | Line 43: | ||
</ | </ | ||
- | <file wg0.conf> | + | ===== Server setup ===== |
+ | |||
+ | < | ||
+ | [Interface] | ||
+ | ListenPort = 12345 | ||
+ | PrivateKey = ... | ||
+ | |||
+ | [Peer] | ||
+ | PublicKey = ... | ||
+ | AllowedIPs = 192.168.1.24/ | ||
+ | |||
+ | [Peer] | ||
+ | PublicKey = ... | ||
+ | AllowedIPs = 192.168.1.25/ | ||
+ | </ | ||
+ | |||
+ | ===== Client setup ===== | ||
+ | |||
+ | <file ini / | ||
+ | |||
+ | [Interface] | ||
+ | PrivateKey = ... | ||
+ | |||
+ | [Peer] | ||
+ | PublicKey = ... | ||
+ | Endpoint = ip1.example.com: | ||
+ | AllowedIPs = 0.0.0.0/0 | ||
+ | PersistentKeepalive = 55 | ||
+ | </ | ||
+ | |||
+ | ===== Applying changes ===== | ||
+ | |||
+ | <code bash> | ||
+ | wg syncconf wg0 / | ||
+ | #wg setconf wg0 / | ||
+ | </ | ||
+ | |||
+ | Note: | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | ===== Interface autostart ===== | ||
+ | |||
+ | ==== using ifupdown ==== | ||
+ | |||
+ | <file / | ||
+ | # activate on boot | ||
+ | auto wg0 | ||
+ | # interface configuration | ||
+ | iface wg0 inet static | ||
+ | address 192.168.1.24/ | ||
+ | pre-up ip link add wg0 type wireguard | ||
+ | pre-up wg setconf wg0 / | ||
+ | |||
+ | post-up ... | ||
+ | |||
+ | post-down ... | ||
+ | post-down ip link del wg0 | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | ==== using wgquick service ==== | ||
+ | |||
+ | '' | ||
+ | <file ini / | ||
[Interface] | [Interface] | ||
Address = 192.168.x.1/ | Address = 192.168.x.1/ | ||
Line 15: | Line 114: | ||
PrivateKey = ... | PrivateKey = ... | ||
SaveConfig = true | 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; | ||
</ | </ | ||
Line 20: | Line 121: | ||
sudo systemctl enable --now wg-quick@wg0 | sudo systemctl enable --now wg-quick@wg0 | ||
</ | </ | ||
+ | |||
+ |