WG Bidirectional flow

Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking
Author Message
CodeName.Lobo
DD-WRT Novice


Joined: 31 Mar 2022
Posts: 10

PostPosted: Thu Apr 03, 2025 15:31    Post subject: WG Bidirectional flow Reply with quote
This is just the text, attached is a file with screenshots.

I saw a post that is asking for something like what I am trying to do but there is no solution in the post; I already read the WG guides and make the tunnel as described in the Server guide, it is working except for the bidirectional part. The guidance is going thru the site to site section in the Advanced guide, however the guide is for 3 peers, this case is only 2. Also, the guide assumes both peers to have a public ip, in this case only the server has one.

Going to start with the client that is “almost” working fine.

WG client is a WRT32X router connected to a 5g Internet (do not know the public IP, but assuming is behind CGNAT); configured as Gateway, no IPV6, no DDNS, no MAC Clone, all wireless disabled, all services disabled except for SSH demon, Password login, Syslog & Telnet server, SPI firewall disabled, also disabled all VPN passthrough.

Running a trace route in the client is this:
• 192.168.12.9 is the DDWRT client
• 10.20.28.4 is the WG server side tunnel
• 192.168.76.1 is the gateway in the remote network (going out to the cable modem)
• After that it goes to the Internet

I know you can figure this, I mentioned just because if I am wrong, please let me know. This side is working fine, can see the local computers, the remote computers and go out thru the remote internet. This works on both, from the WG client via telnet and from my laptop connected to the WG client.

Well, I said at the beginning it works “almost” fine, the only issue is that the Endpoint Address cannot be resolved, it only works with the explicit public IP. (The DDNS for the domain is working fine, it can be resolved from the web browser)


Now the server side; the router is behind another router that is behind the cable modem.
The reason is that my wife works from home and I cannot reboot the gateway every time that I am testing the tunnel.

Not sure if it is relevant, but the Gateway is a WRT1200 running 53028 (will update to 59887 after this tunnel works fine), here the port forwarding is configured. SPI is enabled with the default other options and VPN passthrough disabled. The WAN is connected to a cable modem with a public IP, since this IP is dynamic, also the DDNS service is enabled.

WG server is a WRT1900AC router; configured as Router, no IPV6, no DDNS, no MAC Clone, all wireless disabled, all services disabled except for SSH demon, Password login, Syslog & Telnet server, SPI firewall disabled, also disabled all VPN passthrough.

From this side, I can see the local computers, the tunnel and the WG client (from both the WG server via telnetand another laptop connected to it), beyond that, I cannot see the remote computers nor get out from the remote internet.

The trace, goes to the internet via the local gateway, not the remote.

I already tried turning on the Allow Clients WAN Access and Bypass LAN Same-Origin Policy on the WG client, but does not work. Also tried adding the following rule to the client but does not work as well. (it works on the server side though with subnet 192.168.12.0/24 of course)
iptables -t nat -A POSTROUTING -s 192.168.76.0/24 -o $(get_wanface) -j MASQUERADE

The current configuration is just following the guides and removed all my “tries”. Thank you for the guides, they are very good.

My guess is that I have a rule/route missing on the client side that stops the traffic to the client subnet (except the client itself).

Any advice to allow the access to the client subnet from the server subnet? (and resolve the domain to the end point)

Thank you to Brainslayer for this project and also egc for his dedication to WG.



Tunnel Help.pdf
 Description:

Download
 Filename:  Tunnel Help.pdf
 Filesize:  349.02 KB
 Downloaded:  3 Time(s)

Sponsor
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 13650
Location: Netherlands

PostPosted: Thu Apr 03, 2025 16:06    Post subject: Reply with quote
Both server and client appear to be setup on a Wireless Access Point (WAP) which complicate things.
Consider just using the routers as a gateway router instead of a WAP.

But for setting up on a WAP see the WireGuard Advanced Setup guide for instructions.

Do not forget to set static routes on the main routers so not on the WireGuard routers

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
CodeName.Lobo
DD-WRT Novice


Joined: 31 Mar 2022
Posts: 10

PostPosted: Thu Apr 03, 2025 19:21    Post subject: Reply with quote
First off thank you very much for you fast reply.

egc wrote:
Both server and client appear to be setup on a Wireless Access Point (WAP) which complicate things.
Consider just using the routers as a gateway router instead of a WAP.


Let me see if I am following you. When you said WAP is because is behind the gateway?
If that is the case, yes the server is, but not the client, the client is configured as gateway and is connected to the modem.

egc wrote:

But for setting up on a WAP see the WireGuard Advanced Setup guide for instructions.


To make this configuration work as is now, it took me almost 4 weeks, reading, reading and reading. The hard part to figure out was the MTU, since my phone works with 1440, I assumed that was correct.
So, before moving into another direction as suggested, I would like to ask one more specific question.

From the server side, I can reach the ip 192.168.12.9 and see the ddwrt webUI. However, I cannot reach further in that subnet, for example 192.168.12.2 that is the laptop.

I am not able to fully understand the following routes, so my question is, what is the route/rule that is stopping reaching 192.168.12.0/24?

0.0.0.0/1 dev oet1 scope link
default via 192.168.12.1 dev br0
10.20.28.0/24 dev oet1 scope link src 10.20.28.9
127.0.0.0/8 dev lo scope link
128.0.0.0/1 dev oet1 scope link

192.168.12.0/24 dev br0 scope link src 192.168.12.9
192.168.76.0/24 dev oet1 scope link


Last edited by CodeName.Lobo on Sun Apr 06, 2025 22:40; edited 1 time in total
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 13650
Location: Netherlands

PostPosted: Fri Apr 04, 2025 9:07    Post subject: Reply with quote
From your PDF it seems both server and client have their WAN disabled with the router in the same subnet as the main router and DHCP and DNS off, this means that both are setup as a WAP.

See the instructions in the Advanced setup guide

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
CodeName.Lobo
DD-WRT Novice


Joined: 31 Mar 2022
Posts: 10

PostPosted: Mon Apr 07, 2025 15:35    Post subject: Reply with quote
Good morning,

In order to do the suggestion, for the client, I took a WRT1200 running 53028, Factory Reset it in the webUI, then installed 59887, once running 59887, Factory reset it again in the webUI and then started from scratch.

The very first time the tunnel connected to the server, after a reboot it stop working, after a while I noticed that the Interface Public Key changed, I tough that somehow I regenerated it by mistake, so I Factory reset it again in the WebUI and started again from scratch.

Same behavior, connected the first time and stop after a reboot and the Interface Public Key changed. This time I know I did not hit Generate Key by mistake.

Via telnet I see the Interface Private key does not change but the Interface Public does after restart the tunnel with the shell script. (see attachment please) Hence, the server refuses the connection due a wrong key. As the test shows, it generates the correct key at random, but even so it does not connect after the first time.

Any idea on what is happening? Thank you again for your help.




Dynamic key.pdf
 Description:

Download
 Filename:  Dynamic key.pdf
 Filesize:  364.45 KB
 Downloaded:  4 Time(s)

egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 13650
Location: Netherlands

PostPosted: Mon Apr 07, 2025 16:59    Post subject: Reply with quote
Regarding the WireGuard interface, the public key is always calculated from the private key with:
Code:
nvram get oet1_private | wg pubkey
So if the private key does not change the public key also should not change.

The public key is just shown for convenience, the keys used by WireGuard itself can be seen with:
Code:
wg show oet1
wg showconf oet1


This is not to be confused with the peerkey e.g. oet1_peerkey0, this is the public key of the server and is just fixed in the config.

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
CodeName.Lobo
DD-WRT Novice


Joined: 31 Mar 2022
Posts: 10

PostPosted: Tue Apr 08, 2025 18:13    Post subject: Reply with quote
Please see attachment, same behavior with the commands suggested.


Keys.pdf
 Description:

Download
 Filename:  Keys.pdf
 Filesize:  259.02 KB
 Downloaded:  2 Time(s)

egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 13650
Location: Netherlands

PostPosted: Wed Apr 09, 2025 14:37    Post subject: Reply with quote
DDWRT only stores the private key in its nvram.

WireGuard itself with the "wg pubkey" command calculates the public key with its built-in curve25519.

What you shows is that this produces random outputs with the same private key which is hard to imagine as this code has not been updated and of course if this would produce random output then more reports would have surfaced.

Of course it could be wrong only on your router but that is also hard to imagine.

The only logical conclusion is that the private key is changing so please double check with a compare/diff that the private key is exactly the same as shown with "wg show oet1" if it changes just one character you will have a different public key.

If the private key does not change but you see different public keys calculated from this I do not have an explanation especially as you are the only one having problems.

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
CodeName.Lobo
DD-WRT Novice


Joined: 31 Mar 2022
Posts: 10

PostPosted: Wed Apr 09, 2025 20:40    Post subject: Reply with quote

Good afternoon.

Thank you Master for your time an help in this matter.

My final word is that MY WRT1200 does not work (only this one not all!), I did a lot of tests, reflashing, restoring and reconfiguring by hand and with files, all resulting in the same behavior. Then I went back to the WRT32x, flashed with same version, same configuration files and it worked at the very first time.

Once the tunnel was up, I followed the WAP configuration. I found that the problem were not the routes but the iptables. With so many reading back and forth, I was confusing the POSTROUTE rule in the server configuration and the WAP configuration. (I thought it was the same thing)

Well that made the bidirectional flow to work except for the internet. It only goes out FROM the server side. I cannot put an Allowed Ip 0.0.0.0/1 on the server side because it triggers an error. My guess is that I need to start removing the Allowed Ip 0.0.0.0/1 from the client since it will create a loop trying to go out from the client side.

The Advanced Setup guide mentions that after Build 56490 a PREROUTING rule must be deleted, however I do not see that rule in the raw table:

Chain PREROUTING (policy ACCEPT 138K packets, 135M bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 11331 packets, 8585K bytes)
pkts bytes target prot opt in out source destination

At this point the server goes to the Internet thru the cable modem and the client thru the 5g. Also both subnets can see and comunicate with each other.
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 13650
Location: Netherlands

PostPosted: Thu Apr 10, 2025 7:36    Post subject: Reply with quote
Please post for both routers:
Screenshot of Settings page and screenshot of wireguard page (whole pages)
Output of:
wg
ip route show


Did you set static routes on the main routers, if so also this ouptut from both Main routers"
ip route show

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
CodeName.Lobo
DD-WRT Novice


Joined: 31 Mar 2022
Posts: 10

PostPosted: Sat Apr 12, 2025 16:51    Post subject: Reply with quote
Please find it attached.


WAP server.pdf
 Description:

Download
 Filename:  WAP server.pdf
 Filesize:  1.13 MB
 Downloaded:  3 Time(s)

egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 13650
Location: Netherlands

PostPosted: Sun Apr 13, 2025 7:14    Post subject: Reply with quote
The server side looks OK, but to be able to connect from client connected on the server side you have to set a static route on the main router e.g."
Code:
ip route add 192.168.1.0/24 via 192.168.76.4


If you also want to be able to connect to the client side client on the 5G main routers subnet then you have to add that subnet to the allowed IPs so add 192.168.12.0/24
and als have to set an extra static route on the main router e.g.:
Code:
ip route add 192.168.12.0/24 via 192.168.76.4


If you cannot set static routes on the main router that then you cannot setup as a WAP,

The Client side is setup as a normal router instead of a WAP which is fine if you want this, but DHCP is off, so are there no clients connected to the router or do you use static IP addresses?
Furthermore Gateway and Local DNS should be kept at its default 0.0.0.0 (so change local DNS) and add as Static DNS 1: 9.9.9.9 and as static DNS 2: 1.0.0.1
Reboot afterwards, then you will have a normal gateway router and not a WAP.

Change the Allowed IPs slightly to allow other WG clients on your WG server to be able to connect so change 10.20.28.4/32 in 10.20.28.0/24

Other wise it looks fine and you should be able to connect from clients attached to your WRT32X to the server side.

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
CodeName.Lobo
DD-WRT Novice


Joined: 31 Mar 2022
Posts: 10

PostPosted: Wed May 28, 2025 17:12    Post subject: [Solved] Reply with quote
The replies on this post pointed to the right configuration for the bidirectional flow, however the Internet access on the CLIENT side from the SERVER only could be achieved adding the specific ip address for the site in the Allowed IPs on the server side.
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum