Difference between revisions of "Wireguard"
Jump to navigation
Jump to search
(Created page with "``` I recently discovered the awesome Wireguard VPN tunnel and I was sold. Wireguard is a simple, kernel-based, state-of-the-art VPN that also happens to be ridiculously fast...") |
|||
| Line 1: | Line 1: | ||
| + | # Simple Example of setting up Wireguard on two hosts (expand for many hosts) | ||
| + | |||
| + | # host1 and host2 | ||
| + | ``` | ||
| + | apt install wireguard wireguard-tools | ||
| + | cd /etc/wireguard/ | ||
| + | wg genkey | tee key.sec | wg pubkey > key.pub | ||
``` | ``` | ||
| − | |||
| − | + | host1 /etc/wireguard/wg0.conf # wg0 will be interface name via "ip a" command | |
| + | ``` | ||
| + | [Interface] | ||
| + | Address = 10.254.1.1/24 | ||
| + | ListenPort = 123 # Please change | ||
| + | PrivateKey = <base64 encoded key> # wg genkey | ||
| + | [Peer] | ||
| + | PublicKey = <base64 encoded key> # wg genpub | ||
| + | PresharedKey = <base64 encoded key> # wg genpsk | ||
| + | AllowedIPs = 10.254.1.0/24 | ||
| + | Endpoint = <reachable_ip>:333 | ||
| + | PersistentKeepalive = 25 | ||
| + | ``` | ||
| − | + | host2 /etc/wireguard/wg0.conf # wg0 will be interface name via "ip a" command | |
| − | + | ``` | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
[Interface] | [Interface] | ||
| − | Address = 10. | + | Address = 10.254.1.2/24 |
| − | + | ListenPort = 123 # Please change | |
| − | PrivateKey = < | + | PrivateKey = <base64 encoded key> # wg genkey |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
[Peer] | [Peer] | ||
| − | PublicKey = < | + | PublicKey = <base64 encoded key> # wg genpub |
| − | + | PresharedKey = <base64 encoded key> # wg genpsk | |
| − | AllowedIPs = | + | AllowedIPs = 10.254.1.0/24 |
| − | PersistentKeepalive = | + | Endpoint = <reachable_ip>:333 |
| − | + | PersistentKeepalive = 25 | |
| + | ``` | ||
| − | + | Don both host1 and host2 | |
| − | + | ``` | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
wg-quick up wg0 | wg-quick up wg0 | ||
| − | + | wg show | |
| − | |||
| − | + | ``` | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | 1 | + | Test on both host1 and host2 |
| − | + | ``` | |
| − | + | ping -c4 10.254.1.1 | |
| + | ping -c4 10.254.1.2 | ||
| + | tcpdump -npi wg0 | ||
| + | tcpdump -npi <endpoint interface> port 123 | ||
| + | ``` | ||
| + | 10.254.1.0 should be going through wg0 and you can see port 123 passing udp encapsulated packets (encrypted) | ||
| − | + | Down/remove interface | |
| − | + | ``` | |
| − | + | wg-quick down wg0 | |
| − | + | ``` | |
| − | |||
| − | |||
| − | + | # Notes | |
| − | + | ``` | |
| − | + | # echo <base64 private key> | wg pubkey | |
| − | + | # wg genkey | tee key.sec | wg pubkey > key.pub | |
| − | + | ``` | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
# Refs | # Refs | ||
| + | - https://www.stavros.io/posts/how-to-configure-wireguard/ | ||
- https://www.ckn.io/blog/2017/11/14/wireguard-vpn-typical-setup/ | - https://www.ckn.io/blog/2017/11/14/wireguard-vpn-typical-setup/ | ||
Revision as of 15:56, 3 August 2020
Simple Example of setting up Wireguard on two hosts (expand for many hosts)
host1 and host2
apt install wireguard wireguard-tools cd /etc/wireguard/ wg genkey | tee key.sec | wg pubkey > key.pub
host1 /etc/wireguard/wg0.conf # wg0 will be interface name via "ip a" command
[Interface] Address = 10.254.1.1/24 ListenPort = 123 # Please change PrivateKey = <base64 encoded key> # wg genkey [Peer] PublicKey = <base64 encoded key> # wg genpub PresharedKey = <base64 encoded key> # wg genpsk AllowedIPs = 10.254.1.0/24 Endpoint = <reachable_ip>:333 PersistentKeepalive = 25
host2 /etc/wireguard/wg0.conf # wg0 will be interface name via "ip a" command
[Interface] Address = 10.254.1.2/24 ListenPort = 123 # Please change PrivateKey = <base64 encoded key> # wg genkey [Peer] PublicKey = <base64 encoded key> # wg genpub PresharedKey = <base64 encoded key> # wg genpsk AllowedIPs = 10.254.1.0/24 Endpoint = <reachable_ip>:333 PersistentKeepalive = 25
Don both host1 and host2
wg-quick up wg0 wg show
Test on both host1 and host2
ping -c4 10.254.1.1 ping -c4 10.254.1.2 tcpdump -npi wg0 tcpdump -npi <endpoint interface> port 123
10.254.1.0 should be going through wg0 and you can see port 123 passing udp encapsulated packets (encrypted)
Down/remove interface
wg-quick down wg0
Notes
# echo <base64 private key> | wg pubkey # wg genkey | tee key.sec | wg pubkey > key.pub