|
1 | 1 | --- |
2 | 2 | title: OpenWRT Wireguard Server Tutorial |
3 | 3 | author_profile: false |
| 4 | +toc: true |
| 5 | +toc_label: "Table of Contents" |
| 6 | +toc_icon: "cog" |
4 | 7 | --- |
5 | | -<iframe width="560" height="315" src="https://www.youtube.com/embed/TQxwqY-m30Y" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe> |
6 | 8 |
|
| 9 | +{% include video id="TQxwqY-m30Y" provider="youtube" %} |
7 | 10 |
|
8 | | -This is some text to describe what is happening on the page |
| 11 | +# OpenWRT Wireguard Server |
| 12 | +## Update Dependencies |
| 13 | +```bash |
| 14 | +opkg update |
| 15 | +``` |
| 16 | + |
| 17 | +## Install Wireguard |
| 18 | +```bash |
| 19 | +opkg install wireguard-tools luci-app-wireguard |
| 20 | +``` |
| 21 | +## Key Generation |
| 22 | +```bash |
| 23 | +umask u=rw,g=,o= |
| 24 | +wg genkey | tee wgserver.key | wg pubkey > wgserver.pub |
| 25 | +wg genpsk > wg.psk |
| 26 | +``` |
| 27 | + |
| 28 | +## Wireguard Interface Config |
| 29 | +```bash |
| 30 | +WG_IF="wg0" |
| 31 | +WG_PORT="51820" |
| 32 | +WG_ADDR="10.0.0.1/24" |
| 33 | +``` |
| 34 | + |
| 35 | +## Firewall Config |
| 36 | +```bash |
| 37 | +WG_KEY="$(cat wgserver.key)" |
| 38 | +WG_PSK="$(cat wg.psk)" |
| 39 | +WG_PUB="$(cat wgserver.pub)" |
| 40 | +uci rename firewall.@zone[0]="lan" |
| 41 | +uci rename firewall.@zone[1]="wan" |
| 42 | +uci rename firewall.@forwarding[0]="lan_wan" |
| 43 | +uci del_list firewall.lan.network="${WG_IF}" |
| 44 | +uci add_list firewall.lan.network="${WG_IF}" |
| 45 | +uci -q delete firewall.wg |
| 46 | +uci set firewall.wg="rule" |
| 47 | +uci set firewall.wg.name="Allow-WireGuard" |
| 48 | +uci set firewall.wg.src="wan" |
| 49 | +uci set firewall.wg.dest_port="${WG_PORT}" |
| 50 | +uci set firewall.wg.proto="udp" |
| 51 | +uci set firewall.wg.proto="udp" |
| 52 | +uci set firewall.wg.target="ACCEPT" |
| 53 | +uci commit firewall |
| 54 | +/etc/init.d/firewall restart |
| 55 | +``` |
| 56 | + |
| 57 | +## Network Config: |
| 58 | +```bash |
| 59 | +uci -q delete network.${WG_IF} |
| 60 | +uci set network.${WG_IF}="interface" |
| 61 | +uci set network.${WG_IF}.proto="wireguard" |
| 62 | +uci set network.${WG_IF}.private_key="${WG_KEY}" |
| 63 | +uci set network.${WG_IF}.listen_port="${WG_PORT}" |
| 64 | +uci commit network |
| 65 | +/etc/init.d/network restart |
| 66 | +``` |
| 67 | + |
| 68 | + |
| 69 | +# Adding a Peer |
| 70 | +There are 2 ways to go about this in OpenWRT |
| 71 | + |
| 72 | +Option 1: You can configure the peer on the peer itself and share the keys. |
| 73 | + |
| 74 | +Option 2: You can generate all the keys on the server, show a QR code and then the peer can scan that to get all the information that’s required. You must then remove the private key from the server so that the peer is the only one with knowledge of its private key. |
| 75 | + |
| 76 | + |
| 77 | +## Option 1 |
| 78 | +some text |
| 79 | + |
| 80 | +## Option 2 |
| 81 | + |
| 82 | +Install qrencode |
| 83 | +```bash |
| 84 | +opkg update |
| 85 | +``` |
| 86 | +```bash |
| 87 | +opkg install qrencode |
| 88 | +``` |
| 89 | + |
| 90 | +## Setup Peer |
| 91 | +Then go to Network -> Interfaces -> wg0 -> edit -> peers -> edit peers |
| 92 | + |
| 93 | + |
| 94 | +1. Set the description of the peer |
| 95 | +2. Click “Generate new key pair” to create both the private and public key. |
| 96 | +3. Click “Generate preshared key” |
| 97 | +4. Allowed IPs: 10.0.0.2/32 → this should be unique per peer. Make sure you press the + to apply the IP |
| 98 | +5. Click Generate Configuration |
| 99 | + |
| 100 | + |
| 101 | +1. All the values here should be pre-populated. |
| 102 | +2. You can scan the QR code in your wireguard app to get the config. |
| 103 | +3. After you’ve successfully received the configs you will need to delete the private key from the previous screen. |
| 104 | + |
| 105 | +## Android Config Peer 2 |
0 commit comments