Wireguard server on dumb AP

Wireguard server on dumb AP

Hi there. I was struggling for a couple of weeks to get a Wireguard VPN server running on my TL-WR740N (192.168.1.2, running OpenWRT) which is working as a dumb AP with ISP's router (192.168.1.1). Dumb AP works just fine after I followed this guide https://openwrt.org/docs/guide-user/network/wifi/dumbap the CLI one, I have no LuCI to save space for the Wireguard package and its dependencies.

Command used to build OpenWRT image ###
    make image PROFILE=tl-wr740n-v4 PACKAGES="base-files
    busybox
    dropbear
    iptables
    iw
    jshn
    kernel
    kmod-ath
    kmod-ath9k
    kmod-ath9k-common
    kmod-cfg80211
    kmod-gpio-button-hotplug
    kmod-ipt-conntrack
    kmod-ipt-core
    kmod-ipt-nat
    kmod-leds-gpio
    kmod-ledtrig-default-on
    kmod-ledtrig-netdev
    kmod-ledtrig-timer
    -kmod-ledtrig-usbdev
    kmod-lib-crc-ccitt
    kmod-mac80211
    kmod-nls-base
    -kmod-usb-core
    -kmod-usb-ohci
    -kmod-usb2
    libblobmsg-json
    libc
    libgcc
    libip4tc
    libiwinfo
    libnl-tiny
    libubox
    libubus
    libuci
    libxtables
    mtd
    netifd
    opkg
    swconfig
    uboot-envtools
    ubus
    ubusd
    uci
    uhttpd
    wireless-tools
    wpad-mini
    ip
    kmod-udptunnel4
    kmod-wireguard
    wireguard-tools
    wireguard
    qrencode"
    (firewall and dnsmasq were also installed)
cat /etc/config/network # cat /etc/config/network
config interface 'loopback'
    option ifname 'lo'
    option proto 'static'
    option ipaddr '127.0.0.1'
    option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fdd8:3516:2bd8::/48'

config interface 'lan'
        option type 'bridge'
        option ifname 'eth0.1'
        option proto 'static'
        option ipaddr '192.168.1.2'
        option gateway '192.168.1.1'
        list dns '192.168.1.1'
        option netmask '255.255.255.0'
        option ip6assign '60'

config switch
        option name 'switch0'
        option reset '1'
        option enable_vlan '1'

config switch_vlan
        option device 'switch0'
        option vlan '1'
        option ports '1 2 3 4 0t'

config interface 'wg0'
        option proto 'wireguard'
        option private_key '(private key)'
        option listen_port '51820'
        list addresses '192.168.9.1/24'

config wireguard_wg0
        option public_key '8FhyzMkqxyxI+a3MwbWmS8b42UIyt5NnjzCFV5ueXhA='
        list allowed_ips '0.0.0.0/0'
        option persistent_keepalive '25'
        option description 'test'
Wireguard client configuration # WG
[Interface]
PrivateKey = (private key)
Address=192.168.9.2/32

[Peer]
PublicKey = ZWMprq+TvcnQwdCokySRRylGzYq3njaKSFX7s9OD1Hs=
AllowedIPs = 0.0.0.0/0
Endpoint = (my public IP):51820
cat /etc/config/firewall
# cat /etc/config/firewall

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

config zone
        option input 'ACCEPT'
        option output 'ACCEPT'
        option name 'wireguard'
        option network 'wg0'
        option forward 'ACCEPT'

config rule
        option target 'ACCEPT'
        option src 'lan'
        option name 'allow-lan-to-wireguard'
        option dest 'wireguard'

config rule
        option target 'ACCEPT'
        option src 'wireguard'
        option name 'allow-wireguard-to-lan'
        option dest 'lan'

config forwarding
        option dest 'wireguard'
        option src 'lan'

config forwarding
        option dest 'lan'
        option src 'wireguard'

I have also set a static route to WG subnet and forwarded UDP 51820 to the dumb AP (192.168.1.2).

Observed behavior

  • Successful handshake but no Internet connection form Windows PC in local network.
  • Can't ping anything except of 192.168.9.1
  • No handshake from iOS device, also in local network
  • No handshake form other devices from Internet.

Expected behavior

  • Working internet connection through VPN for all connected devices.
  • No matter if LAN devices will be visible for VPN clients or not.

I am not very experienced at networking, and I am not sure if the firewall settings are right, connection also doesn't work with firewall disabled.

Some routers don't masquerade all egress traffic, but only what matches their lan subnet. So in this case you'd need to enable masquerade on lan firewall zone.
uci set firewall.lan.masq='1'; uci commit firewall; /etc/init.d/firewall restart

Some tcpdump would be useful to understand if packets come and go as they should. However the above mentioned NAT should fix this.

Check the keys.

Verify that you actually see these packets: tcpdump -i eth0.1 -evn udp port 51820

Also you don't need the 2 firewall rules, forwardings can cover that.

1 Like

The simplest way to do this is to masquerade from the wiregaurd tunnel to the LAN. Thus the main router doesn't see any .9.0 IPs, Internet use by the road warrior appears to come from the WR740 on the LAN. Also you can access LAN resources from the road. The only thing is if someone on the LAN needs to initiate any connections to the road warrior you'll need to forward ports or not use masquerade.

Check that the client's routing table is correct. Its route to the Internet (with an exception for the one IP of the Wireguard server at home) needs to be 192.168.9.1 on the wireguard interface. This will also cover reaching the home LAN without needing an explicit route for it.

1 Like

There are some issues with your configuration:

The allowed_ips field is wrong. It should be a /32 address in the same subnet as the main WG interface. For example, 192.168.9.2/32 (which matches your 'client' configuration).

You also need to add the following to that peer config (on the OpenWrt side):
option route_allowed_ips '1'

And you can remove the following from your firewall (it is not necessary since you already have forwarding rules configured):

These 2 are not necessarily wrong and not needed to be fixed. I am using the same configuration on my tunnels.

Thank you for responses and suggestions. For the

uci set firewall.lan.masq='1'

I get

uci: Invalid argument

Not sure if this is an error or a warning, but after that I see no changes in /etc/config/firewall. Also, I've got no space to install tcpdump, so I'll have to re-build the image. I will come back with tcpdump results if I succeed.

Creating the wg0 interface with .9.0/24 IP automatically installs a route for it. route_allowed_ips is for adding additional networks that exist on the other side of the tunnel, that the server would not otherwise know about. A road warrior client only has its one IP which is already on the tunnel and covered by the automatic route. So its authorization on the server should be for that one IP.

1 Like

On the allowed IPs, I found that 0.0.0.0/0 works in a 'server' context, but only for one 'client' connection. If you attempt to setup a second peer with 0.0.0.0/0, WG won't start. At least that was my experience when I first started using WG a few years back

Regarding the route allowed IPs -- AFAIK it is absolutely possible to run WG without it, but a route must be created on the local device (i.e. the OpenWrt side) in order for it to work properly (the OP already has a route already installed on the main router). I didn't see a route on OpenWrt, so this option would make sense.

Do I have any of those bits wrong or misunderstood? If so, lmk so I can be more aware of the options and nuances with this type of config.

I can ping 192.168.9.1 form 192.168.1.0 subnet, a consequence of setting the static route to 192.168.9.0 on the main router. I failed to get tcpdump on the WR740, so now I'm trying to apply all the suggestions from this thread. Thank you.

I tried your suggestions, (esp. psherman's). The situation is mostly the same:

  • Successful handshake from PC in local network.
  • No handshake from iPhone from local network.
  • I can ping 192.168.9.2 client from 192.168.1.0
  • From 192.168.9.0, can't ping anything outside this subnet.
  • No handshake from Internet.

My configs look like that now:

/etc/config/network

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

config globals 'globals'
      option ula_prefix 'fdd8:3516:2bd8::/48'

config interface 'lan'
      option type 'bridge'
      option ifname 'eth0.1'
      option proto 'static'
      option ipaddr '192.168.1.2'
      option gateway '192.168.1.1'
      list dns '192.168.1.1'
      option netmask '255.255.255.0'
      option ip6assign '60'

config switch
      option name 'switch0'
      option reset '1'
      option enable_vlan '1'

config switch_vlan
      option device 'switch0'
      option vlan '1'
      option ports '1 2 3 4 0t'

config interface 'wg0'
      option proto 'wireguard'
      option private_key '(private key)'
      option listen_port '51820'
      list addresses '192.168.9.1/24'

config wireguard_wg0
      option public_key 'S8404zMMuaOZWWlmsSU0IHVgod0JmnaqoVxvOEhoACM='
      list allowed_ips '192.168.9.2/32'
      option route_allowed_ips '1'
      option persistent_keepalive '25'
      option description 'test'

/etc/config/firewall
config zone
      option name 'lan'
      option input 'ACCEPT'
      option output 'ACCEPT'
      option forward 'ACCEPT'
      option network 'lan'

config zone
      option input 'ACCEPT'
      option output 'ACCEPT'
      option name 'wireguard'
      option network 'wg0'
      option forward 'ACCEPT'

config forwarding
      option dest 'wireguard'
      option src 'lan'

config forwarding
      option dest 'lan'
      option src 'wireguard'

WG client
[Interface]
PrivateKey = (private key)
Address=192.168.9.2/32

[Peer]
PublicKey = ZWMprq+TvcnQwdCokySRRylGzYq3njaKSFX7s9OD1Hs=
# if I try 192.168.9.2/32 here, I can't get successful handshake in any case
AllowedIPs = 0.0.0.0/0
Endpoint = (dump AP's IP/public IP):51820

On the 'client' side, this should be 0.0.0.0/0 if you want all traffic to go through the tunnel.

Do your iPhone and your PC have exactly the same configuration? You only have a single peer defined in the OpenWrt config... this means that the two devices must have the same private key or the handshake will fail. Obviously the rest of it must also be identical.

Two things to check here:

  1. on your primary router, have you port forwarded UDP 51820 > 192.168.1.2:51820?
  2. Have you verified that you have a proper public IP address on the WAN of your primary router?
1 Like
  1. Yes, there are exact same settings, I generate QR code from the same conf file which I showed before.
  2. I have the UDP forwarded to 192.168.1.2
  3. I have a static public IP which wasn't changed for years. As far as I know, it is only my network behind this IP (I would like to check, if this is possible).

I haven't tried it with multiple clients. In that case I would add also the specific addresses in case it would not work. However I get the feeling that it is some kind of access list and not necessarily an identifier.
Regarding the route, as @mk24 pointed out, you have the /24 on the server side, so that is enough.

It's an error alright. Add it manually. option masq '1' inside config zone lan

OMG! There is handshake from Internet, but still no Internet connection, I'll keep experimenting, I think I saw somewhere on OpenWRT forum similar topics with this problem while looking for solutions. Thank you!

Everything seems to work fine, both from local and Internet, all LAN members are visible for VPN clients. The last problem was that I haven't added DNS to WG config file. So now it is like that:

WG client
[Interface]
PrivateKey = (private key)
Address=192.168.9.2/32
DNS = 192.168.1.1

[Peer]
PublicKey = ZWMprq+TvcnQwdCokySRRylGzYq3njaKSFX7s9OD1Hs=
AllowedIPs = 0.0.0.0/0
Endpoint = (dump AP's IP/public IP):51820

Thank you guys, because of you I finally configured that VPN server!

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