WireGuard on OpenWRT

Hi all,
I want to have a home OpenWRT as a WireGuard Server where my iPhone mobile can VPN into the OpenWRT and can access:
a) the files on my local network NAS
b) the internet on my mobile through my home for safer browsing when abroad

I can't seem to get the configuration right for WireGuard on the OpenWRT Server. This is what I did:

  1. Under >Network>Interfaces I have added a new Interface with the following configuration
    ===General Settings====
    Protocol: WireGuard VPM
    Bring up on Boot: Checked
    Have a Private and public Key through pressing the Generate new Key pair
    Listen Port: 51820
    IP Address: 192.168.21.210/32 ###this is the IP I understand of the Wireguard Server VPN interface

     ===Advanced Settings====
     I did not change anything here
     
     ===Firewall Settings====
     Create/Assign firewall-zone: Lan(lan, vpn)
     
     ===DHCP Server====
     No DHCP Server Configured
     
     ===Peers====
     Description: Mobile
     Have a Private and public Key through pressing the Generate new Key pair		
     Have a Preshared Key through pressing the Generate preshare key
     Allowe IPs: 192.168.21.211/32             ###this is the IP address that the Mobile Client will have
     Route Allowed IPs: Checked
     Endpoint Host: www.mywebsite.com          ### this is a website that points to my router's VPN Server IP address
     Endpoint IP 51820
     Persistent Keep Alive: 25
    
  2.  Under Firewall/Port Forwards
     Name:VPN_Forward
     Restrict to address family: automatic
     Protocol: TCP / UDP
     Source zone: wan:[Switch port: "wan"]wan6:[Switch port: "wan"] 
     External port 51820
     Destination zone: lan: [Bridge: "br-lan"] vpn: [Tunnel Interface: "wireguard-vpn"] 
     Internal IP address: 192.168.21.210
    
  3.  Under Firewall/Traffic Rules
     Name: WireGuard-TrafficRule
     Protocol: UDP
     Source zone: lan: [Bridge: "br-lan"] vpn: [Tunnel Interface: "wireguard-vpn"] 
     Source address: -- add IP --
     Source port@ 51820
     Destination zone: lan: [Bridge: "br-lan"] vpn: [Tunnel Interface: "wireguard-vpn"] 
     Destination address: -- add IP --
     Destination port: 51820
     Action: Accept
    

Info:
Firmware Version OpenWrt 23.05.5 r24106-10cc5fcd00 / LuCI openwrt-23.05 branch git-24.264.56413-c7a3562
Model Linksys EA8300 (Dallas)

LAN IP Config:
-OpenWRT Router IP:192.168.21.1

Let's actually just take a look at the config as it stands in the actual system:

Please connect to your OpenWrt device using ssh and copy the output of the following commands and post it here using the "Preformatted text </> " button:
grafik
Remember to redact passwords, MAC addresses and any public IP addresses you may have:

ubus call system board
cat /etc/config/network
cat /etc/config/firewall
wg show

This gives us all the info we need to get started.

Here you go

root@OpenWrt:~# ubus call system board
{
        "kernel": "5.15.167",
        "hostname": "OpenWrt",
        "system": "ARMv7 Processor rev 5 (v7l)",
        "model": "Linksys EA8300 (Dallas)",
        "board_name": "linksys,ea8300",
        "rootfs_type": "squashfs",
        "release": {
                "distribution": "OpenWrt",
                "version": "23.05.5",
                "revision": "r24106-10cc5fcd00",
                "target": "ipq40xx/generic",
                "description": "OpenWrt 23.05.5 r24106-10cc5fcd00"
        }
}
root@OpenWrt:~# cat /etc/config/network

config interface 'loopback'
        option device 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix '================/48'

config device
        option name 'br-lan'
        option type 'bridge'
        list ports 'lan1'
        list ports 'lan2'
        list ports 'lan3'
        list ports 'lan4'

config device
        option name 'lan1'
        option macaddr '==============='

config device
        option name 'lan2'
        option macaddr '==================='

config device
        option name 'lan3'
        option macaddr '============='

config device
        option name 'lan4'
        option macaddr '================'

config interface 'lan'
        option device 'br-lan'
        option proto 'static'
        option ipaddr '192.168.21.1'
        option netmask '255.255.255.0'
        option ip6assign '60'

config device
        option name 'wan'
        option macaddr '==========='

config interface 'wan'
        option device 'wan'
        option proto 'dhcp'

config interface 'wan6'
        option device 'wan'
        option proto 'dhcpv6'

config interface 'vpn'
        option proto 'wireguard'
        option private_key '====='
        option listen_port '51820'
        list addresses '192.168.21.210/32'

config wireguard_vpn 'wgclient'
        option public_key '====='
        option preshared_key '====='
        list allowed_ips '192.168.21.211/32'
        option private_key '====='
        option persistent_keepalive '25'
        option description 'Mobile'
        option route_allowed_ips '1'

root@OpenWrt:~# cat /etc/config/firewall

config defaults
        option input 'REJECT'
        option output 'ACCEPT'
        option forward 'REJECT'
        option synflood_protect '1'

config zone 'lan'
        option name 'lan'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'ACCEPT'
        list network 'lan'
        list network 'vpn'

config zone 'wan'
        option name 'wan'
        option input 'REJECT'
        option output 'ACCEPT'
        option forward 'REJECT'
        option masq '1'
        option mtu_fix '1'
        list network 'wan'
        list network 'wan6'

config forwarding
        option src 'lan'
        option dest 'wan'

config rule
        option name 'Allow-DHCP-Renew'
        option src 'wan'
        option proto 'udp'
        option dest_port '68'
        option target 'ACCEPT'
        option family 'ipv4'

config rule
        option name 'Allow-Ping'
        option src 'wan'
        option proto 'icmp'
        option icmp_type 'echo-request'
        option family 'ipv4'
        option target 'ACCEPT'

config rule
        option name 'Allow-IGMP'
        option src 'wan'
        option proto 'igmp'
        option family 'ipv4'
        option target 'ACCEPT'

config rule
        option name 'Allow-DHCPv6'
        option src 'wan'
        option proto 'udp'
        option dest_port '546'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-MLD'
        option src 'wan'
        option proto 'icmp'
        option src_ip 'fe80::/10'
        list icmp_type '130/0'
        list icmp_type '131/0'
        list icmp_type '132/0'
        list icmp_type '143/0'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-ICMPv6-Input'
        option src 'wan'
        option proto 'icmp'
        list icmp_type 'echo-request'
        list icmp_type 'echo-reply'
        list icmp_type 'destination-unreachable'
        list icmp_type 'packet-too-big'
        list icmp_type 'time-exceeded'
        list icmp_type 'bad-header'
        list icmp_type 'unknown-header-type'
        list icmp_type 'router-solicitation'
        list icmp_type 'neighbour-solicitation'
        list icmp_type 'router-advertisement'
        list icmp_type 'neighbour-advertisement'
        option limit '1000/sec'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-ICMPv6-Forward'
        option src 'wan'
        option dest '*'
        option proto 'icmp'
        list icmp_type 'echo-request'
        list icmp_type 'echo-reply'
        list icmp_type 'destination-unreachable'
        list icmp_type 'packet-too-big'
        list icmp_type 'time-exceeded'
        list icmp_type 'bad-header'
        list icmp_type 'unknown-header-type'
        option limit '1000/sec'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-IPSec-ESP'
        option src 'wan'
        option dest 'lan'
        option proto 'esp'
        option target 'ACCEPT'

config rule
        option name 'Allow-ISAKMP'
        option src 'wan'
        option dest 'lan'
        option dest_port '500'
        option proto 'udp'
        option target 'ACCEPT'

config redirect
        option dest 'lan'
        option target 'DNAT'
        option name 'WireGuard_VPN'
        option src 'wan'
        option src_dport '51820'
        option dest_ip '192.168.21.210'
        option dest_port '51820'
        list proto 'tcp'
        list proto 'udp'

config rule 'wg'
        option name 'Allow-WireGuard'
        option src 'lan'
        option dest_port '51820'
        option proto 'udp'
        option target 'ACCEPT'
        option dest 'lan'
        option src_port '51820'

You can also have a look at my notes.

You need the server setup guide.

Make sure you download it as github only shows the first 5 pages

First make sure that incoming connections are possible with your ISP. The "upstream" IP on the main status page must match that reported by a "whats my IP" test site on a lan computer. You probably want to subscribe to a DDNS service so that your phone can reach your home IP by name as the ISP will usually change your IP whenever your modem has to reconnect.

Your Allow-Wireguard firewall rule is wrong. It should be src wan and no dest. Wireguard from the LAN is also already allowed since the lan default is to allow all ports.

The vpn tunnel IP should be specified as a /24, this installs a route to all possible road warriors in that /24 so that it is not necessary to use route_allowed_ips with every /32.

Your WG interface address overlaps the lan interface's subnet (192.168.21.0/24). You must us a different subnet. For example, let's use 192.168.22.0/24.

So, fixing the above, let's make it look like this:

config interface 'vpn'
        option proto 'wireguard'
        option private_key '====='
        option listen_port '51820'
        list addresses '192.168.22.1/24'

Now, change the allowed_ips of the peer to use the same subnet:

config wireguard_vpn 'wgclient'
        option public_key '====='
        option preshared_key '====='
        list allowed_ips '192.168.22.2/32'
        option private_key '====='
        option persistent_keepalive '25'
        option description 'Mobile'
        option route_allowed_ips '1'

Now, delete this:

And edit the wg rule like this:

config rule 'wg'
        option name 'Allow-WireGuard'
        option src 'wan'
        option dest_port '51820'
        option proto 'udp'
        option target 'ACCEPT'

Don't forget to update the configuration on the remote peer ("Mobile") to match the new allowed IP on it's main interface address.

Once that's done, restart your OpenWrt router and test again. If it doesn't work, post the latest versions of those two config files and also the remote peer's configuration.

3 Likes

Both Psherman and egc solutions above worked. Only one thing extra was needed in my case.... YOU HAVE TO RESTART the Interface Service (or the whole router) before your peer client works, otherwise even with the correct configuration and "Apply and save" it was simply not working.

Thank you all for your help!!!!!

3 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.