[SOLVED] WireGuard + PBR- default route timing?

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


Joined: 27 May 2021
Posts: 14

PostPosted: Sat May 29, 2021 6:53    Post subject: [SOLVED] WireGuard + PBR- default route timing? Reply with quote
Update:

ANSWER: Tunnel IPAddress/Netmask must be in CIDR notation.

=================================================

Firmware: DD-WRT v3.0-r46772 std (05/26/21)
Router Model: Netgear R6700 v3

Similar to https://forum.dd-wrt.com/phpBB2/viewtopic.php?p=1237985#1237985, I'm trying to setup my router so that all traffic goes to IVPN except one ip.

Following egc's Client Setup guide here: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324624

But traffic isn't routing through the VPN tunnel. Handshake looks fine, but no traffic routing.

Dug deeper and followed the links to egc's Server Setup guide with additional troubleshooting: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=322206

I followed this guide and it worked:


Quote:

Default route kicking in too soon
Builds after 43031 have extra wait time before the default route kicks in, so those should not be affected.
On some builds/routers/setup the default route can kick in too soon after a reboot, one symptom can be that
the time is not correct this also can happen if you have manually specified a slow time server (DDWRT works
best if you leave the time server field empty). This is under investigation.
If you suspect this is the case then it is easy to check and mitigate.
Disable the Route Allowed IP's via tunnel and add the following in Administration/Commands, Save as Startup
(reboot after each change).:
Code:

sleep 60
ip route add 0.0.0.0/1 dev oet1
ip route add 128.0.0.0/1 dev oet1



I disabled Route Allowed IPs and created the recommended Startup script. Now the tunnel is working for all traffic!

But, when I setup PBR it seems to have no effect, all clients are routed through the tunnel. I'm not well versed on linux networking commands, but I'm guessing `ip route add`] is conflicting with PBR?

Any advice on how to get my WireGuard tunnel setup with PBR? Either by fixing the route cause of the default route timing problem or adjusting the script to accomidate PBR?

Example: Setting Policy Based Routing to 192.168.11.64/26. Computer 192.168.11.83 is routed through the tunnel but so is 192.168.11.5!


Last edited by superTaco2 on Sun May 30, 2021 10:16; edited 2 times in total
Sponsor
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12915
Location: Netherlands

PostPosted: Sat May 29, 2021 7:32    Post subject: Reply with quote
You do not have to add anything manually (default route kicking in too soon should not be happening anymore and if it is happening you will see a warning in syslog)

The IP addresses you fill in in the PBR field are using the VPN.

You use CIDR notation as described in the guide, the address range you are using: 192.168.11.64/26
means all IP addresses from 192.168.11.64 until and including 192.168.11.127 (so 64 IP addresses) will use the VPN other IP addresses will use the WAN

If you want it otherwise see: https://www.ipaddressguide.com/cidr

You can enter multiple addresses/ranges which will use the VPN as a comma separated list

EDIT: You better enable Route allowed IP's via tunnel

_________________
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


Last edited by egc on Sat May 29, 2021 16:16; edited 1 time in total
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12915
Location: Netherlands

PostPosted: Sat May 29, 2021 8:18    Post subject: Reply with quote
A viable setup could be something like this:

Enter in the PBR field 192.168.11.64/26, 192.168.11.128/26 so all addresses from .64 - .191 are using the VPN

For your DHCP range you use start address .64 for a maximum of 64 addresses those DHCP users will use the VPN

You can set static leases from .128 - .191 those will use the VPN.
Static leases below .64 will use the WAN

_________________
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
superTaco2
DD-WRT Novice


Joined: 27 May 2021
Posts: 14

PostPosted: Sat May 29, 2021 19:01    Post subject: Reply with quote
I spent a bunch more time on this, but the only way I'm able to get the WireGuard tunnel working is with the a startup script that adds the ip routes. And this solution doesn't work with PBR.

Any troubleshooting suggestions?

I tried a bunch of configurations (listed below).

I then thought on the timing problem and checked my syslogs and was surprised they start at 1/1/1970 (date is 0?). There are some issues resolving 2.pool.nto.org but it eventually gets there. What's odd to me is the WireGuard tunnel + routing is setup BEFORE the current date is resolved. Would that have something to do with it??

Logs Excerpt (timezone: Zulu) (IP addresses modified to protect the innocent. 3.3.188.150 is ISP ip)
Quote:

Jan 1 00:00:20 r6700 user.info root: Enable WireGuard interface oet1 on port 51820
Jan 1 00:00:20 r6700 user.info root: Establishing WireGuard tunnel with peer endpoint us-wa1.wg.ivpn.net:2050
Jan 1 00:00:21 r6700 daemon.info httpd[1080]: httpd : httpd server started at port 80
Jan 1 00:00:21 r6700 user.info : httpd : http daemon successfully started
Jan 1 00:00:22 r6700 daemon.info dnsmasq-dhcp[1040]: DHCPDISCOVER(br0) b4:aa:aa:aa:aa:aa
Jan 1 00:00:22 r6700 daemon.info dnsmasq-dhcp[1040]: DHCPOFFER(br0) 192.168.11.5 b4:aa:aa:aa:aa:aa
Jan 1 00:00:22 r6700 daemon.info dnsmasq-dhcp[1040]: DHCPREQUEST(br0) 192.168.11.5 b4:aa:aa:aa:aa:aa
Jan 1 00:00:22 r6700 daemon.info dnsmasq-dhcp[1040]: DHCPACK(br0) 192.168.11.5 b4:aa:aa:aa:aa:aa PleaseHelpMeEgc
Jan 1 00:00:25 r6700 user.info root: WireGuard setting route for oet1 to endpoint us-wa1.wg.ivpn.net:2050 via 0.0.0.0 dev vlan2
Jan 1 00:00:25 r6700 user.info root: WireGuard 172.28.**.***/255.255.255.255 added to oet1
....
Jan 1 00:00:30 r6700 daemon.err ntpclient[1657]: Failed resolving address to hostname 2.pool.ntp.org: Name does not resolve
Jan 1 00:00:30 r6700 daemon.err ntpclient[1657]: Failed resolving server 2.pool.ntp.org: Network is down
Jan 1 00:00:30 r6700 daemon.notice ntpclient[1657]: Network up, resolved address to hostname 212.18.3.19
Jan 1 00:00:30 r6700 daemon.debug ntpclient[1657]: Connecting to 212.18.3.19 [212.18.3.19] ...
May 29 18:36:49 r6700 daemon.info ntpclient[1657]: Time set from 212.18.3.19 [212.18.3.19].
May 29 18:36:50 r6700 user.info root: Enable WireGuard interface oet1 on port 51820
May 29 18:36:50 r6700 user.info root: Establishing WireGuard tunnel with peer endpoint us-wa1.wg.ivpn.net:2050
May 29 18:36:50 r6700 user.info root: WireGuard setting route for oet1 to endpoint us-wa1.wg.ivpn.net:2050 via 3.3.188.1 dev vlan2
May 29 18:36:50 r6700 user.info root: WireGuard 172.28.**.***/255.255.255.255 added to oet1


Wire Guard Tunnel Configuration Experiments
Quote:

DOESN'T WORK - no traffic through tunnel (duckduckgo "what is my ip" reports isp ip, not vpn tunnel ip)
Startup Script: <empty>
PBR: 192.168.11.64/26
Allowed IPs:0.0.0.0/1,128.0.0.0/1
Route Allowed IPs via Tunnel: Enable
Wire Guard Status:

endpoint: 23.19.87.237:2050
latest handshake: 51 years, 161 days, 17 hours, 32 minutes, 58 seconds ago
transfer: 2.96 KiB received, 548 B sent

(on f5 in browser)
endpoint: 23.19.87.237:2050
latest handshake: 1 minute, 49 seconds ago
transfer: 8.48 KiB received, 960 B sent

Troubleshoot:
d/c wifi, reconnect
wait 3 minutes

**********************************************

DOESN'T WORK - no traffic through tunnel (ddg "what is my ip" reports isp ip, not vpn tunnel ip)
Startup Script: <empty>
PBR: 192.168.11.64/26
Allowed IPs:0.0.0.0/1,128.0.0.0/1
Route Allowed IPs via Tunnel: Disable
Wire Guard Status:

endpoint: 23.19.87.237:2050
latest handshake: 51 years, 161 days, 17 hours, 42 minutes, 10 seconds ago
transfer: 92 B received, 212 B sent

(on f5 in browser)
endpoint: 23.19.87.237:2050
latest handshake: 15 seconds ago
transfer: 184 B received, 520 B sent

Troubleshoot:
d/c wifi, reconnect
wait 3 minutes

**********************************************

DOESN'T WORK - no traffic through tunnel (ddg "what is my ip" reports isp ip, not vpn tunnel ip)
Startup Script: <empty>
PBR: <empty>
Allowed IPs:0.0.0.0/1,128.0.0.0/1
Route Allowed IPs via Tunnel: Enable
Wire Guard Status:

endpoint: 23.19.87.237:2050
latest handshake: 1 minute, 31 seconds ago
transfer: 92 B received, 2.15 KiB sent

Troubleshoot:
d/c wifi, reconnect
wait 3 minutes

**********************************************

DOESN'T WORK - no traffic through tunnel (ddg "what is my ip" reports isp ip, not vpn tunnel ip)
Startup Script: <empty>
PBR: <empty>
Allowed IPs:0.0.0.0/1,128.0.0.0/1
Route Allowed IPs via Tunnel: Disable
Wire Guard Status:

endpoint: 23.19.87.237:2050
latest handshake: 1 minute, 31 seconds ago
transfer: 92 B received, 2.15 KiB sent

via ssh `ip route`: (IP addresses modified to protect the innocent. 3.3.188.150 is ISP ip)

default via 3.3.188.1 dev vlan2
23.19.87.237 via 3.3.188.1 dev vlan2
3.3.188.0/22 dev vlan2 scope link src 3.3.188.150
127.0.0.0/8 dev lo scope link
192.168.11.0/24 dev br0 scope link src 192.168.11.1

Troubleshoot:
d/c wifi, reconnect
wait 2 minutes

via ssh run:
ip route add 0.0.0.0/1 dev oet1
ip route add 128.0.0.0/1 dev oet1

All clients now routed through vpn tunnel.


*********************************************
WORKS - all traffic through tunnel (ddg "what is my ip" reports vpn tunnel ip)
Startup Script:
sleep 60
ip route add 0.0.0.0/1 dev oet1
ip route add 128.0.0.0/1 dev oet1
PBR: <empty>
Allowed IPs:0.0.0.0/1,128.0.0.0/1
Route Allowed IPs via Tunnel: Disable


*********************************************

DOESN'T WORK - client 192.168.11.5 traffic still routed through tunnel
Startup Script:
sleep 60
ip route add 0.0.0.0/1 dev oet1
ip route add 128.0.0.0/1 dev oet1
PBR: 192.168.11.64/26
Allowed IPs:0.0.0.0/1,128.0.0.0/1
Route Allowed IPs via Tunnel: Disable

egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12915
Location: Netherlands

PostPosted: Sat May 29, 2021 19:28    Post subject: Reply with quote
You always have to Enable Route allowed IP's via tunnel.

To test do not put anything in the PBR Field.

The route kicks in after NTP time is up but there is timeout of 90 seconds, the syslog will tell you if everything is working, it appears to work but the best way to see everything is from the CLI (telnet/Putty):
Code:
grep -E -i 'oet|wireguard' /var/log/messages


So
Remove all scripting you have done
Enable Route allowed IP's via tunnel (otherwise nothing is routed via the tunnel)
Clear the PBR field
Save and Apply

Wait two minutes and send output of the above command

You can check your routing also from CLI with:
traceroute 8.8.8.8

In the troubleshooting section of the WireGuard server setup guide are also some more troubleshooting tips and commands which can be useful

_________________
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
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12915
Location: Netherlands

PostPosted: Sat May 29, 2021 19:41    Post subject: Reply with quote
One other thing your net mask is wrong it should be /24 (or 32) and not 255.255.255.255

You are on a recent build which has safeguards against this but you should see the warning in the syslog and the override Sad

_________________
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
superTaco2
DD-WRT Novice


Joined: 27 May 2021
Posts: 14

PostPosted: Sat May 29, 2021 21:02    Post subject: Reply with quote
Thanks for the help, followed your instructions: disabled scripts & pbr, enabled Rouate Allowed IPs, rebooted and waited 2 mintutes . Unfortunately traffic is still not routing through the Tunnel:

Disable Scripts & PBR / Enable Route Allowed IPs:
nvram show | grep oet :
Quote:

oet1_peerport0=2050
oet1_bloop=0
oet1_rem0=us-wa1.wg.ivpn.net
oet_tunnels=1
oet1_endpoint0=1
oet1_rem=192.168.90.1
oet1_private=aJ****************************kE=
oet1_peers=1
oet1_fwmark=
oet1_namep0=iVPN
oet1_bridged=0
oet1_multicast=0
oet1_ka0=25
oet1_killswitch=0
oet1_mtu=1412
oet1_rtdownscript=
oet1_netmask=0.0.0.0
oet1_pbr=
oet1_en=1
oet1_dns_ipaddr=0.0.0.0
oet1_psk0=
oet1_firewallin=1
oet1_isolation=0
oet1_port=51820
oet1_dns_redirect=0
oet1_showadvanced=1
oet1_ip0=0.0.0.0
oet1_ipaddrmask=172.**.**.**6/255.255.255.255
oet1_dns0=0.0.0.0
oet1_hwaddr=00:00:00:00:00:00
oet1_peerkey0=LV***********************Gs=
oet1_proto=2
oet1_nat=1
oet1_id=1
oet1_label=
oet1_aip0=0.0.0.0/1,128.0.0.0/1
oet1_usepsk0=0
oet1_ipaddr=0.0.0.0
oet1_natout=1
oet1_aip_rten0=1
oet1_dns=
oet1_public=gw**********************U08=
oet1_local=0.0.0.0
oet1_txq=1
oet1_mit=1
oet1_rtupscript=
bat_oet1_bridge=br0


After Reboot and 2 minutes:
grep -E -i 'oet|wireguard' /var/log/messages
(IP addresses modified to protect the innocent. 3.3.188.150 is ISP ip)
Quote:

Jan 1 00:00:20 r6700 user.info root: Enable WireGuard interface oet1 on port 51820
Jan 1 00:00:20 r6700 user.info root: Establishing WireGuard tunnel with peer endpoint us-wa1.wg.ivpn.net:2050
Jan 1 00:00:25 r6700 user.info root: WireGuard setting route for oet1 to endpoint us-wa1.wg.ivpn.net:2050 via 0.0.0.0 dev vlan2
Jan 1 00:00:25 r6700 user.info root: WireGuard 172.**.**.**6/255.255.255.255 added to oet1
Jan 1 00:00:28 r6700 user.info root: Enable WireGuard interface oet1 on port 51820
Jan 1 00:00:29 r6700 user.info root: Establishing WireGuard tunnel with peer endpoint us-wa1.wg.ivpn.net:2050
Jan 1 00:00:29 r6700 user.info root: WireGuard setting route for oet1 to endpoint us-wa1.wg.ivpn.net:2050 via 3.3.188.1 dev vlan2
Jan 1 00:00:29 r6700 user.info root: WireGuard 172.**.**.**6/255.255.255.255 added to oet1
May 29 20:18:10 r6700 user.info root: Enable WireGuard interface oet1 on port 51820
May 29 20:18:11 r6700 user.info root: Establishing WireGuard tunnel with peer endpoint us-wa1.wg.ivpn.net:2050
May 29 20:18:11 r6700 user.info root: WireGuard setting route for oet1 to endpoint us-wa1.wg.ivpn.net:2050 via 3.3.188.1 dev vlan2
May 29 20:18:11 r6700 user.info root: WireGuard 172.**.**.**6/255.255.255.255 added to oet1



ip route show
(IP addresses modified to protect the innocent. 3.3.188.150 is ISP ip)
Quote:

default via 3.3.188.1 dev vlan2
23.19.87.237 via 3.3.188.1 dev vlan2
3.3.188.0/22 dev vlan2 scope link src 3.3.188.150
127.0.0.0/8 dev lo scope link
192.168.11.0/24 dev br0 scope link src 192.168.11.1


traceroute 8.8.8.8
Route clearly going through isp, several hops mention ISP by name.
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12915
Location: Netherlands

PostPosted: Sun May 30, 2021 6:29    Post subject: Reply with quote
See my earlier post, your netmask is still wrong.

It should be /24 and not 255.255.255.255

If you correct that it will work

_________________
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
superTaco2
DD-WRT Novice


Joined: 27 May 2021
Posts: 14

PostPosted: Sun May 30, 2021 10:12    Post subject: Reply with quote
Quote:

It should be /24 and not 255.255.255.255


That was it!! I didn't realize the IP Address/Netmask needed to be in CIDR format!! Though it needed to be /32 rather than 24:.

nvram show | grep oet1_ipaddrmask
Code:

oet1_ipaddrmask=172.**.***.**6/32


I had initially followed the IVPN Setup Guide which was written against an older v39715 when Subnet Mask was a separate field and was in Dotted Decimal Netmask format.

I'll have to ping the IVPN team and let them know their guide is quite out of date.
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12915
Location: Netherlands

PostPosted: Sun May 30, 2021 10:59    Post subject: Reply with quote
Glad it is solved Smile

I will make some extra checks so that this will also be caught and specifically mention it in the label.

Actually using /24 is smarter as that is another safeguard against routing problems, if you add an /24 address to an interface a route is automatically added Smile

That is why I favour /24 but if routing is working /32 should also work (and of course 255.255.255.255 is /32)

_________________
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
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