How can devices within a local network access a remote WireGuard peer deployed on a router?

/etc/config/network
config interface 'wg0'
        option proto 'wireguard'
        option private_key '*'
        option listen_port '51871'
        list addresses '10.0.0.1/24'
        list addresses 'fdc9:281f:04d7:9ee9::1/64'

config wireguard_wg0
        option description 'Peer_A'
        option public_key '*'
        list allowed_ips '10.0.0.2/32'
        list allowed_ips '10.10.10.0/24'
        list allowed_ips 'fdc9:281f:04d7:9ee9::2/128'

config wireguard_wg0
        option description 'Peer_B'
        option public_key '*'
        option endpoint_host '*.*.*.*'
        option endpoint_port '51871'
        list allowed_ips '10.0.0.3/32'
        list allowed_ips 'fdc9:281f:04d7:9ee9::3/128'
        option route_allowed_ips '1'

config wireguard_wg0
        option description 'Peer_C'
        option public_key '*'
        list allowed_ips '10.0.0.4/32'
        list allowed_ips 'fdc9:281f:04d7:9ee9::4/128'
        option endpoint_host '*.*.*.*'
        option endpoint_port '51871'
        option route_allowed_ips '1'

config wireguard_wg0
        option description 'Peer_D'
        option public_key '*'
        list allowed_ips '10.0.0.5/32'
        list allowed_ips 'fdc9:281f:04d7:9ee9::5/128'
        option route_allowed_ips '1'
/etc/config/firewall
config zone 'lan'
        option name 'lan'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'ACCEPT'
        list network 'lan'
        list network 'wg0'
config rule 'wg'
        option name 'Allow-WireGuard'
        option src 'wan'
        option dest_port '51871'
        option proto 'udp'
        option target 'ACCEPT'

config nat
        option name 'WG0'
        list proto 'udp'
        option src 'lan'
        option target 'MASQUERADE'
        option device 'br-lan'
        option dest_ip '10.0.0.0/24'
ip route
default via *.*.*.* dev pppoe-wan proto static 
10.0.0.0/24 dev wg0 proto kernel scope link src 10.0.0.1 
10.0.0.3 dev wg0 proto static scope link 
10.0.0.4 dev wg0 proto static scope link 
10.0.0.5 dev wg0 proto static scope link 
10.10.10.0/24 dev br-lan proto kernel scope link src 10.10.10.1 
*.*.*.* via *.*.*.* dev pppoe-wan proto static 
*.*.*.* via *.*.*.* dev pppoe-wan proto static 
*.*.*.* dev pppoe-wan proto kernel scope link src *.*.*.*

Essentially, while I can successfully ping 10.0.0.3 from the router, my computer located within br-lan is unable to do so.
I attempted to add 10.10.10.0/24 to the allowed_ips for peer c, but it seems to cause network outages due to route_allowed_ips. Disabling route_allowed_ips doesn't appear to help me achieve the desired outcome.
Would manual configuration of a static routing table be necessary?

What is the LAN subnet of the other side?
Add that subnet to the Allowed IPs and then enable Route Allowed IPs.

Note WG is a routed solution so can only work if the subnet of Client side, Server side and WG are different

Replace this with the subnet of the other side and enable route allowed IPs

Delete this

Reboot afterwards or do service network restart

What is this for?

My PC's IP is 10.10.10.10,The subnet of all peers is 24.

I want to connect the endpoint_host of multiple peers.

It's basically a LAN device that I can access in a non-LAN environment.
It seems that address translation must be done, and I ran some tests and it worked well.

To recap this WG setup is basically setup as a server so that other clients from outside can connect to it?

I had the impression that you also want to connect from the server side to a client which is a router?

Basically both, the former is finished because the NAT is working well, and the latter doesn't seem to be working properly.

So what is the subnet of the servers lan and what is the subnet of the clients lan you want to connect to?

br-lan ip : 10.10.10.0/24
wg peer ip : 10.0.0.0/24

It seems that my expression is a bit incorrect, it is Site to Point rather than Site to Site.

Basically, my other peers are servers, not routers, so I don't need extra NAT. Only the Peer in my own home is the router, so I made NAT to facilitate other peers to access the LAN device in my own home, but I also hope that I can access other peers in my home LAN.

If the WG peers are just simple clients like like a phone or laptop you only need the WG peer address e.g. 10.0.0.4/32

If the WG client is a router and you want to connect to the clients of that router from the server side then you can disable NAT on that WG client and add the subnet of that client as allowed IPs.
Note that all subnets need to be unique!.
In these case you can also set the endpoint and endpoint port to the other site but necessary it is not as the other side will start the tunnel and keeps it open with PersistenKeepalive. So for simplicity do not set an endpoint.
The above is often referred as a site-to-site setup.

In all case you need to enable route allowed IPs

About your WG peers they will all have access to all your local LAN clients as the WG interface is in the LAN zone, but the WG peers have their own WG address which is outside the local LAN (and it should be) and most of your LAN clients will have their own firewall which will block traffic not originating from its own local subnet so will block traffic from the WG peers.
To deal with this you can either tweak the firewall of the LAN clients or choose the easy way out and that is enabling MASQUERADING on the LAN zone.

1 Like

option masq '1'is very useful!

Out of curiosity, I conducted routing tracking.

mtr -nr 10.0.0.3
Start: 2024-01-29T15:44:48+0800
HOST: AIO                         Loss%   Snt   Last   Avg  Best  Wrst StDev
  1.|-- 10.10.10.1                 0.0%    10    0.0   0.1   0.0   0.1   0.0
  2.|-- 10.0.0.3                   0.0%    10    1.4   1.9   1.2   2.7   0.5

It seems that even wg0 and br-lan are in the lan zone and require dynamic address masking and routing in addition to routing.

I disabled the route_allowed_ips option for all peers and opted to manually create a static route. I discovered that when I intended to allow the peer to access 10.10.10.0/24, route_allowed_ips was disrupting my network.

config nat
        option name 'WG0'
        list proto 'udp'
        option src 'lan'
        option target 'MASQUERADE'
        option device 'br-lan'
        option dest_ip '10.0.0.0/24'

Of course, I also deleted this NAT.

So far, all my goals have been achieved.

Of course it disrupts your network as that is the subnet of your own lan.

There is no need to set any static routes as the routes are set by enabling Route Allowed IPs.

But you have to set the right subnets as I tried to explain to you a few times but apparently I miserably failed :frowning:

So last attempt, in the Allowed IPs of the peer section you place the address of the WG interface, like you are doing, and if the other side is a router or VPS etc., with a fixed IP address and subnet you place this subnet in the Allowed IPs.

As said all subnets need to be unique

I noticed the presence of the 10.0.0.0/24 dev wg0 proto kernel scope link src 10.0.0.1 routing table. It seems that this routing table is automatically created by OpenWrt after setting up the wg interface, and it appears to be effective. It seems that I no longer require additional routing tables. :grinning:
Next I want to try to make my soft router work in Docker.

1 Like

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